igor-suhorukov commented on code in PR #13941:
URL: https://github.com/apache/arrow/pull/13941#discussion_r953088354
##########
java/adapter/jdbc/src/test/java/org/apache/arrow/adapter/jdbc/JdbcParameterBinderTest.java:
##########
@@ -672,4 +750,108 @@ <T, V extends FieldVector> void testListType(ArrowType
arrowType, TriConsumer<V,
assertThat(binder.next()).isFalse();
}
}
+
+ <T, V extends FieldVector> void testMapType(ArrowType arrowType,
TriConsumer<V, Integer, T> setValue,
+ BiConsumer<V, Integer> setNull,
List<T> values,
+ ArrowType elementType) throws
SQLException {
+ int jdbcType = Types.VARCHAR;
+ FieldType keyType = new FieldType(false, elementType, null, null);
+ FieldType mapType = new FieldType(false, ArrowType.Struct.INSTANCE, null,
null);
+ Schema schema = new Schema(Collections.singletonList(new Field("field",
FieldType.nullable(arrowType),
+ Collections.singletonList(new Field(MapVector.KEY_NAME, mapType,
+ Arrays.asList(new Field(MapVector.KEY_NAME, keyType, null),
+ new Field(MapVector.VALUE_NAME, keyType,
null)))))));
+ try (final MockPreparedStatement statement = new MockPreparedStatement();
+ final VectorSchemaRoot root = VectorSchemaRoot.create(schema,
allocator)) {
+ final JdbcParameterBinder binder =
+ JdbcParameterBinder.builder(statement, root).bindAll().build();
+ assertThat(binder.next()).isFalse();
+
+ @SuppressWarnings("unchecked")
+ final V vector = (V) root.getVector(0);
+ final ColumnBinder columnBinder = ColumnBinder.forVector(vector);
+ assertThat(columnBinder.getJdbcType()).isEqualTo(jdbcType);
+
+ setValue.accept(vector, 0, values.get(0));
+ setValue.accept(vector, 1, values.get(1));
+ setNull.accept(vector, 2);
+ root.setRowCount(3);
+
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(0).toString());
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(1).toString());
+ assertThat(binder.next()).isTrue();
+ assertThat(statement.getParamValue(1)).isNull();
+ assertThat(statement.getParamType(1)).isEqualTo(jdbcType);
+ assertThat(binder.next()).isFalse();
+
+ binder.reset();
+
+ setNull.accept(vector, 0);
+ setValue.accept(vector, 1, values.get(3));
+ setValue.accept(vector, 2, values.get(0));
+ setValue.accept(vector, 3, values.get(2));
+ setValue.accept(vector, 4, values.get(1));
+ root.setRowCount(5);
+
+ assertThat(binder.next()).isTrue();
+ assertThat(statement.getParamValue(1)).isNull();
+ assertThat(statement.getParamType(1)).isEqualTo(jdbcType);
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(3).toString());
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(0).toString());
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(2).toString());
+ assertThat(binder.next()).isTrue();
+
assertThat(statement.getParamValue(1)).isEqualTo(values.get(1).toString());
+ assertThat(binder.next()).isFalse();
+ }
+
+ // Non-nullable (since some types have a specialized binder)
Review Comment:
Well spotted @lidavidm ! Thx.
Test and MapBinder was updated
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]