[
https://issues.apache.org/jira/browse/ARROW-17431?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
David Li resolved ARROW-17431.
------------------------------
Fix Version/s: 10.0.0
Resolution: Fixed
Issue resolved by pull request 13941
[https://github.com/apache/arrow/pull/13941]
> [Java] MapBinder to bind Arrow Map type to DB column
> -----------------------------------------------------
>
> Key: ARROW-17431
> URL: https://issues.apache.org/jira/browse/ARROW-17431
> Project: Apache Arrow
> Issue Type: Improvement
> Components: Java
> Affects Versions: 10.0.0
> Reporter: Igor Suhorukov
> Assignee: Igor Suhorukov
> Priority: Major
> Labels: pull-request-available
> Fix For: 10.0.0
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> 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|https://github.com/apache/arrow/blob/master/java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/binder/ColumnBinderArrowTypeVisitor.java#L100]]
>
> {code:java}
> @Override
>
>
> public ColumnBinder visit(ArrowType.Map type) {
>
>
> throw new UnsupportedOperationException("No column binder
> implemented for type " + type);
>
>
> } {code}
>
> My current implementation patch ColumnBinderArrowTypeVisitor in classpath to
> return MapBinder
> {code:java}
> @Override
> public ColumnBinder visit(ArrowType.Map type) {
> return new MapBinder((MapVector) vector);
> }
> {code}
> 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:
> {code:java}
> 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());
> }
> }
> {code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)