Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
asfimport opened this issue Aug 16, 2022 · 1 comment
Closed

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

asfimport opened this issue Aug 16, 2022 · 1 comment

Comments

@asfimport
Copy link
Collaborator

asfimport commented Aug 16, 2022

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());
    }
}

 

Reporter: Igor Suhorukov / @igor-suhorukov
Assignee: Igor Suhorukov / @igor-suhorukov

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-17431. Please see the migration documentation for further details.

@asfimport
Copy link
Collaborator Author

David Li / @lidavidm:
Issue resolved by pull request 13941
#13941

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant