Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
10.0.0
Description
Typical real life Arrow datasets contain List type vectors of primitive type. 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.List type) { throw new UnsupportedOperationException("No column binder implemented for type " + type); }
My current implementation patch ColumnBinderArrowTypeVisitor in classpath (to leverage Builder functionality instead of manual vector mapping in code) to return ListBinder
@Override public ColumnBinder visit(ArrowType.List type) { return new ListBinder((ListVector) vector); }
and following code works for me with H2 database and in java stored PostgreSQL function in PL/Java to bind List parameter to JDBC:
package org.apache.arrow.adapter.jdbc.binder; import org.apache.arrow.vector.complex.ListVector; import org.apache.arrow.vector.complex.impl.UnionListReader; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; public class ListBinder extends BaseColumnBinder<ListVector>{ private UnionListReader reader; public ListBinder(ListVector vector) { this(vector, Types.ARRAY); } public ListBinder(ListVector vector, int jdbcType) { super(vector, jdbcType); reader = vector.getReader(); } @Override public void bind(PreparedStatement statement, int parameterIndex, int rowIndex) throws SQLException { reader.setPosition(rowIndex); ArrayList sourceArray = (ArrayList) reader.readObject(); Class aClass = sourceArray.get(0).getClass(); if(aClass.isAssignableFrom(Long.class)){ Long[] res = new Long[sourceArray.size()]; Arrays.setAll(res, sourceArray::get); statement.setObject(parameterIndex, res); } else if(aClass.isAssignableFrom(Integer.class)){ Integer[] res = new Integer[sourceArray.size()]; Arrays.setAll(res, sourceArray::get); statement.setObject(parameterIndex, res); } else if(aClass.isAssignableFrom(Short.class)){ Short[] res = new Short[sourceArray.size()]; Arrays.setAll(res, sourceArray::get); statement.setObject(parameterIndex, res); } else if(aClass.isAssignableFrom(String.class)){ String[] res = new String[sourceArray.size()]; Arrays.setAll(res, sourceArray::get); statement.setObject(parameterIndex, res); } } }
Attachments
Issue Links
- is cloned by
-
ARROW-17431 [Java] MapBinder to bind Arrow Map type to DB column
- Resolved
- links to