Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-17431

[Java] MapBinder to bind Arrow Map type to DB column

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 10.0.0
    • 10.0.0
    • Java

    Description

      Typical real life Arrow datasets contain Map type vectors of string key->string value. Looks logically implement default JDBC parameter binders for such vector type or implement some kind on binder code extensibility of core framework via MetaINF/ServiceLocator

      Current implementation just throws UnsupportedOperationException]

       

        @Override
              
              
                  public ColumnBinder visit(ArrowType.Map type) {
              
              
                    throw new UnsupportedOperationException("No column binder implemented for type " + type);
              
              
                  } 

       
      My current implementation patch ColumnBinderArrowTypeVisitor in classpath to return MapBinder

          @Override
          public ColumnBinder visit(ArrowType.Map type) {
              return  new MapBinder((MapVector) vector);
          }
      

      and following code works for me with H2 database and in java stored PostgreSQL function in PL/Java to bind Map(string,string) parameter to JDBC:

      package org.apache.arrow.adapter.jdbc.binder;
      
      import org.apache.arrow.vector.complex.MapVector;
      import org.apache.arrow.vector.complex.impl.UnionMapReader;
      import org.apache.arrow.vector.util.JsonStringHashMap;
      
      import java.sql.PreparedStatement;
      import java.sql.SQLException;
      import java.sql.Types;
      import java.util.LinkedHashMap;
      
      public class MapBinder extends BaseColumnBinder<MapVector> {
      
          private UnionMapReader reader;
      
          public MapBinder(MapVector vector) {
              this(vector, Types.VARCHAR);
          }
      
          public MapBinder(MapVector vector, int jdbcType) {
              super(vector, jdbcType);
              reader = vector.getReader();
          }
      
          @Override
          public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException {
              reader.setPosition(rowIndex);
              LinkedHashMap<String, String> tags = new JsonStringHashMap<>();
              while (reader.next()){
                  tags.put(reader.key().readText().toString(), reader.value().readText().toString());
              }
              statement.setString(parameterIndex, tags.toString());
          }
      }
      

       

      Attachments

        Issue Links

          Activity

            People

              igor.suhorukov Igor Suhorukov
              igor.suhorukov Igor Suhorukov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m