Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
10.0.0
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
- is a clone of
-
ARROW-17430 [Java] ListBinder to bind Arrow List type to DB column
- Resolved
- links to