lidavidm commented on a change in pull request #11982:
URL: https://github.com/apache/arrow/pull/11982#discussion_r784200474



##########
File path: 
java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java
##########
@@ -429,6 +453,80 @@ private static VectorSchemaRoot getRoot(final ResultSet 
data, final BufferAlloca
     return new VectorSchemaRoot(singletonList(dataVector));
   }
 
+  private static VectorSchemaRoot getTypeInfoRoot(CommandGetTypeInfo request, 
ResultSet typeInfo,
+                                                  final BufferAllocator 
allocator)
+      throws SQLException {
+    Objects.requireNonNull(allocator, "BufferAllocator cannot be null.");
+
+    VectorSchemaRoot root = 
VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator);
+
+    VarCharVector typeNameVector = (VarCharVector) root.getVector("type_name");
+    IntVector dataTypeVector = (IntVector) root.getVector("data_type");
+    IntVector columnSizeVector = (IntVector) root.getVector("column_size");
+    VarCharVector literalPrefixVector = (VarCharVector) 
root.getVector("literal_prefix");
+    VarCharVector literalSuffixVector = (VarCharVector) 
root.getVector("literal_suffix");
+    VarCharVector createParamsVector = (VarCharVector) 
root.getVector("create_params");
+    IntVector nullableVector = (IntVector) root.getVector("nullable");
+    BitVector caseSensitiveVector = (BitVector) 
root.getVector("case_sensitive");
+    IntVector searchableVector = (IntVector) root.getVector("searchable");
+    BitVector unsignedAttributeVector = (BitVector) 
root.getVector("unsigned_attribute");
+    BitVector fixedPrecScaleVector = (BitVector) 
root.getVector("fixed_prec_scale");
+    BitVector autoIncrementVector = (BitVector) 
root.getVector("auto_increment");
+    VarCharVector localTypeNameVector = (VarCharVector) 
root.getVector("local_type_name");
+    IntVector minimumScaleVector = (IntVector) root.getVector("minimum_scale");
+    IntVector maximumScaleVector = (IntVector) root.getVector("maximum_scale");
+    IntVector sqlDataTypeVector = (IntVector) root.getVector("sql_data_type");
+    IntVector sqlDatetimeSubVector = (IntVector) 
root.getVector("sql_datetime_sub");
+    IntVector numPrecRadixVector = (IntVector) 
root.getVector("num_prec_radix");
+
+    List<FieldVector> vectors =
+        ImmutableList.of(typeNameVector, dataTypeVector, columnSizeVector, 
literalPrefixVector, literalSuffixVector,
+            createParamsVector, nullableVector, caseSensitiveVector, 
searchableVector, unsignedAttributeVector,
+            fixedPrecScaleVector, autoIncrementVector, localTypeNameVector, 
minimumScaleVector, maximumScaleVector,
+            sqlDataTypeVector, sqlDatetimeSubVector, numPrecRadixVector);
+
+    Map<FieldVector, String> mapper = new HashMap<>();
+    mapper.put(typeNameVector, "TYPE_NAME");
+    mapper.put(dataTypeVector, "DATA_TYPE");
+    mapper.put(columnSizeVector, "PRECISION");
+    mapper.put(literalPrefixVector, "LITERAL_PREFIX");
+    mapper.put(literalSuffixVector, "LITERAL_SUFFIX");
+    mapper.put(createParamsVector, "CREATE_PARAMS");
+    mapper.put(nullableVector, "NULLABLE");
+    mapper.put(caseSensitiveVector, "CASE_SENSITIVE");
+    mapper.put(searchableVector, "SEARCHABLE");
+    mapper.put(unsignedAttributeVector, "UNSIGNED_ATTRIBUTE");
+    mapper.put(fixedPrecScaleVector, "FIXED_PREC_SCALE");
+    mapper.put(autoIncrementVector, "AUTO_INCREMENT");
+    mapper.put(localTypeNameVector, "LOCAL_TYPE_NAME");
+    mapper.put(minimumScaleVector, "MINIMUM_SCALE");
+    mapper.put(maximumScaleVector, "MAXIMUM_SCALE");
+    mapper.put(sqlDataTypeVector, "SQL_DATA_TYPE");
+    mapper.put(sqlDatetimeSubVector, "SQL_DATETIME_SUB");
+    mapper.put(numPrecRadixVector, "NUM_PREC_RADIX");
+
+    Predicate<ResultSet> predicate;
+    if (request.hasDataType()) {
+      predicate = (resultSet) -> {
+        try {
+          return resultSet.getInt("DATA_TYPE") == request.getDataType();
+        } catch (SQLException e) {
+          throw new RuntimeException(e);
+        }
+      };
+    } else {
+      predicate = (resultSet -> true);
+    }
+
+    saveToVectors(mapper, typeInfo, true, predicate);
+    final int rows =
+        
vectors.stream().map(FieldVector::getValueCount).findAny().orElseThrow(IllegalStateException::new);

Review comment:
       Instead of creating `vectors` above I think you can just use 
`root.getFieldVectors` (though if saveToVectors can return the row count, you 
can skip this too)

##########
File path: 
java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java
##########
@@ -429,6 +453,80 @@ private static VectorSchemaRoot getRoot(final ResultSet 
data, final BufferAlloca
     return new VectorSchemaRoot(singletonList(dataVector));
   }
 
+  private static VectorSchemaRoot getTypeInfoRoot(CommandGetTypeInfo request, 
ResultSet typeInfo,
+                                                  final BufferAllocator 
allocator)
+      throws SQLException {
+    Objects.requireNonNull(allocator, "BufferAllocator cannot be null.");
+
+    VectorSchemaRoot root = 
VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator);
+
+    VarCharVector typeNameVector = (VarCharVector) root.getVector("type_name");
+    IntVector dataTypeVector = (IntVector) root.getVector("data_type");
+    IntVector columnSizeVector = (IntVector) root.getVector("column_size");
+    VarCharVector literalPrefixVector = (VarCharVector) 
root.getVector("literal_prefix");
+    VarCharVector literalSuffixVector = (VarCharVector) 
root.getVector("literal_suffix");
+    VarCharVector createParamsVector = (VarCharVector) 
root.getVector("create_params");
+    IntVector nullableVector = (IntVector) root.getVector("nullable");
+    BitVector caseSensitiveVector = (BitVector) 
root.getVector("case_sensitive");
+    IntVector searchableVector = (IntVector) root.getVector("searchable");
+    BitVector unsignedAttributeVector = (BitVector) 
root.getVector("unsigned_attribute");
+    BitVector fixedPrecScaleVector = (BitVector) 
root.getVector("fixed_prec_scale");
+    BitVector autoIncrementVector = (BitVector) 
root.getVector("auto_increment");
+    VarCharVector localTypeNameVector = (VarCharVector) 
root.getVector("local_type_name");
+    IntVector minimumScaleVector = (IntVector) root.getVector("minimum_scale");
+    IntVector maximumScaleVector = (IntVector) root.getVector("maximum_scale");
+    IntVector sqlDataTypeVector = (IntVector) root.getVector("sql_data_type");
+    IntVector sqlDatetimeSubVector = (IntVector) 
root.getVector("sql_datetime_sub");
+    IntVector numPrecRadixVector = (IntVector) 
root.getVector("num_prec_radix");
+
+    List<FieldVector> vectors =
+        ImmutableList.of(typeNameVector, dataTypeVector, columnSizeVector, 
literalPrefixVector, literalSuffixVector,
+            createParamsVector, nullableVector, caseSensitiveVector, 
searchableVector, unsignedAttributeVector,
+            fixedPrecScaleVector, autoIncrementVector, localTypeNameVector, 
minimumScaleVector, maximumScaleVector,
+            sqlDataTypeVector, sqlDatetimeSubVector, numPrecRadixVector);
+
+    Map<FieldVector, String> mapper = new HashMap<>();
+    mapper.put(typeNameVector, "TYPE_NAME");
+    mapper.put(dataTypeVector, "DATA_TYPE");
+    mapper.put(columnSizeVector, "PRECISION");
+    mapper.put(literalPrefixVector, "LITERAL_PREFIX");
+    mapper.put(literalSuffixVector, "LITERAL_SUFFIX");
+    mapper.put(createParamsVector, "CREATE_PARAMS");
+    mapper.put(nullableVector, "NULLABLE");
+    mapper.put(caseSensitiveVector, "CASE_SENSITIVE");
+    mapper.put(searchableVector, "SEARCHABLE");
+    mapper.put(unsignedAttributeVector, "UNSIGNED_ATTRIBUTE");
+    mapper.put(fixedPrecScaleVector, "FIXED_PREC_SCALE");
+    mapper.put(autoIncrementVector, "AUTO_INCREMENT");
+    mapper.put(localTypeNameVector, "LOCAL_TYPE_NAME");
+    mapper.put(minimumScaleVector, "MINIMUM_SCALE");
+    mapper.put(maximumScaleVector, "MAXIMUM_SCALE");
+    mapper.put(sqlDataTypeVector, "SQL_DATA_TYPE");
+    mapper.put(sqlDatetimeSubVector, "SQL_DATETIME_SUB");
+    mapper.put(numPrecRadixVector, "NUM_PREC_RADIX");
+
+    Predicate<ResultSet> predicate;
+    if (request.hasDataType()) {
+      predicate = (resultSet) -> {
+        try {
+          return resultSet.getInt("DATA_TYPE") == request.getDataType();
+        } catch (SQLException e) {
+          throw new RuntimeException(e);
+        }
+      };
+    } else {
+      predicate = (resultSet -> true);
+    }
+
+    saveToVectors(mapper, typeInfo, true, predicate);
+    final int rows =
+        
vectors.stream().map(FieldVector::getValueCount).findAny().orElseThrow(IllegalStateException::new);
+    vectors.forEach(vector -> vector.setValueCount(rows));

Review comment:
       IIRC, root.setRowCount does this for you.

##########
File path: 
java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java
##########
@@ -429,6 +453,80 @@ private static VectorSchemaRoot getRoot(final ResultSet 
data, final BufferAlloca
     return new VectorSchemaRoot(singletonList(dataVector));
   }
 
+  private static VectorSchemaRoot getTypeInfoRoot(CommandGetTypeInfo request, 
ResultSet typeInfo,
+                                                  final BufferAllocator 
allocator)
+      throws SQLException {
+    Objects.requireNonNull(allocator, "BufferAllocator cannot be null.");
+
+    VectorSchemaRoot root = 
VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator);
+
+    VarCharVector typeNameVector = (VarCharVector) root.getVector("type_name");
+    IntVector dataTypeVector = (IntVector) root.getVector("data_type");
+    IntVector columnSizeVector = (IntVector) root.getVector("column_size");
+    VarCharVector literalPrefixVector = (VarCharVector) 
root.getVector("literal_prefix");
+    VarCharVector literalSuffixVector = (VarCharVector) 
root.getVector("literal_suffix");
+    VarCharVector createParamsVector = (VarCharVector) 
root.getVector("create_params");
+    IntVector nullableVector = (IntVector) root.getVector("nullable");
+    BitVector caseSensitiveVector = (BitVector) 
root.getVector("case_sensitive");
+    IntVector searchableVector = (IntVector) root.getVector("searchable");
+    BitVector unsignedAttributeVector = (BitVector) 
root.getVector("unsigned_attribute");
+    BitVector fixedPrecScaleVector = (BitVector) 
root.getVector("fixed_prec_scale");
+    BitVector autoIncrementVector = (BitVector) 
root.getVector("auto_increment");
+    VarCharVector localTypeNameVector = (VarCharVector) 
root.getVector("local_type_name");
+    IntVector minimumScaleVector = (IntVector) root.getVector("minimum_scale");
+    IntVector maximumScaleVector = (IntVector) root.getVector("maximum_scale");
+    IntVector sqlDataTypeVector = (IntVector) root.getVector("sql_data_type");
+    IntVector sqlDatetimeSubVector = (IntVector) 
root.getVector("sql_datetime_sub");
+    IntVector numPrecRadixVector = (IntVector) 
root.getVector("num_prec_radix");
+
+    List<FieldVector> vectors =
+        ImmutableList.of(typeNameVector, dataTypeVector, columnSizeVector, 
literalPrefixVector, literalSuffixVector,
+            createParamsVector, nullableVector, caseSensitiveVector, 
searchableVector, unsignedAttributeVector,
+            fixedPrecScaleVector, autoIncrementVector, localTypeNameVector, 
minimumScaleVector, maximumScaleVector,
+            sqlDataTypeVector, sqlDatetimeSubVector, numPrecRadixVector);
+
+    Map<FieldVector, String> mapper = new HashMap<>();
+    mapper.put(typeNameVector, "TYPE_NAME");
+    mapper.put(dataTypeVector, "DATA_TYPE");
+    mapper.put(columnSizeVector, "PRECISION");
+    mapper.put(literalPrefixVector, "LITERAL_PREFIX");
+    mapper.put(literalSuffixVector, "LITERAL_SUFFIX");
+    mapper.put(createParamsVector, "CREATE_PARAMS");
+    mapper.put(nullableVector, "NULLABLE");
+    mapper.put(caseSensitiveVector, "CASE_SENSITIVE");
+    mapper.put(searchableVector, "SEARCHABLE");
+    mapper.put(unsignedAttributeVector, "UNSIGNED_ATTRIBUTE");
+    mapper.put(fixedPrecScaleVector, "FIXED_PREC_SCALE");
+    mapper.put(autoIncrementVector, "AUTO_INCREMENT");
+    mapper.put(localTypeNameVector, "LOCAL_TYPE_NAME");
+    mapper.put(minimumScaleVector, "MINIMUM_SCALE");
+    mapper.put(maximumScaleVector, "MAXIMUM_SCALE");
+    mapper.put(sqlDataTypeVector, "SQL_DATA_TYPE");
+    mapper.put(sqlDatetimeSubVector, "SQL_DATETIME_SUB");
+    mapper.put(numPrecRadixVector, "NUM_PREC_RADIX");
+
+    Predicate<ResultSet> predicate;
+    if (request.hasDataType()) {
+      predicate = (resultSet) -> {
+        try {
+          return resultSet.getInt("DATA_TYPE") == request.getDataType();
+        } catch (SQLException e) {
+          throw new RuntimeException(e);
+        }
+      };
+    } else {
+      predicate = (resultSet -> true);
+    }
+
+    saveToVectors(mapper, typeInfo, true, predicate);

Review comment:
       Would it make sense for this to return the row count so that you don't 
have to do it manually?

##########
File path: 
java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java
##########
@@ -429,6 +453,80 @@ private static VectorSchemaRoot getRoot(final ResultSet 
data, final BufferAlloca
     return new VectorSchemaRoot(singletonList(dataVector));
   }
 
+  private static VectorSchemaRoot getTypeInfoRoot(CommandGetTypeInfo request, 
ResultSet typeInfo,
+                                                  final BufferAllocator 
allocator)
+      throws SQLException {
+    Objects.requireNonNull(allocator, "BufferAllocator cannot be null.");
+
+    VectorSchemaRoot root = 
VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator);
+
+    VarCharVector typeNameVector = (VarCharVector) root.getVector("type_name");
+    IntVector dataTypeVector = (IntVector) root.getVector("data_type");
+    IntVector columnSizeVector = (IntVector) root.getVector("column_size");
+    VarCharVector literalPrefixVector = (VarCharVector) 
root.getVector("literal_prefix");
+    VarCharVector literalSuffixVector = (VarCharVector) 
root.getVector("literal_suffix");
+    VarCharVector createParamsVector = (VarCharVector) 
root.getVector("create_params");
+    IntVector nullableVector = (IntVector) root.getVector("nullable");
+    BitVector caseSensitiveVector = (BitVector) 
root.getVector("case_sensitive");
+    IntVector searchableVector = (IntVector) root.getVector("searchable");
+    BitVector unsignedAttributeVector = (BitVector) 
root.getVector("unsigned_attribute");
+    BitVector fixedPrecScaleVector = (BitVector) 
root.getVector("fixed_prec_scale");
+    BitVector autoIncrementVector = (BitVector) 
root.getVector("auto_increment");
+    VarCharVector localTypeNameVector = (VarCharVector) 
root.getVector("local_type_name");
+    IntVector minimumScaleVector = (IntVector) root.getVector("minimum_scale");
+    IntVector maximumScaleVector = (IntVector) root.getVector("maximum_scale");
+    IntVector sqlDataTypeVector = (IntVector) root.getVector("sql_data_type");
+    IntVector sqlDatetimeSubVector = (IntVector) 
root.getVector("sql_datetime_sub");
+    IntVector numPrecRadixVector = (IntVector) 
root.getVector("num_prec_radix");

Review comment:
       Since the types don't matter, why not inline these into the `mapper.put` 
calls below?

##########
File path: 
java/flight/flight-sql/src/test/java/org/apache/arrow/flight/sql/example/FlightSqlExample.java
##########
@@ -429,6 +453,80 @@ private static VectorSchemaRoot getRoot(final ResultSet 
data, final BufferAlloca
     return new VectorSchemaRoot(singletonList(dataVector));
   }
 
+  private static VectorSchemaRoot getTypeInfoRoot(CommandGetTypeInfo request, 
ResultSet typeInfo,
+                                                  final BufferAllocator 
allocator)
+      throws SQLException {
+    Objects.requireNonNull(allocator, "BufferAllocator cannot be null.");
+
+    VectorSchemaRoot root = 
VectorSchemaRoot.create(Schemas.GET_TYPE_INFO_SCHEMA, allocator);
+
+    VarCharVector typeNameVector = (VarCharVector) root.getVector("type_name");
+    IntVector dataTypeVector = (IntVector) root.getVector("data_type");
+    IntVector columnSizeVector = (IntVector) root.getVector("column_size");
+    VarCharVector literalPrefixVector = (VarCharVector) 
root.getVector("literal_prefix");
+    VarCharVector literalSuffixVector = (VarCharVector) 
root.getVector("literal_suffix");
+    VarCharVector createParamsVector = (VarCharVector) 
root.getVector("create_params");
+    IntVector nullableVector = (IntVector) root.getVector("nullable");
+    BitVector caseSensitiveVector = (BitVector) 
root.getVector("case_sensitive");
+    IntVector searchableVector = (IntVector) root.getVector("searchable");
+    BitVector unsignedAttributeVector = (BitVector) 
root.getVector("unsigned_attribute");
+    BitVector fixedPrecScaleVector = (BitVector) 
root.getVector("fixed_prec_scale");
+    BitVector autoIncrementVector = (BitVector) 
root.getVector("auto_increment");
+    VarCharVector localTypeNameVector = (VarCharVector) 
root.getVector("local_type_name");
+    IntVector minimumScaleVector = (IntVector) root.getVector("minimum_scale");
+    IntVector maximumScaleVector = (IntVector) root.getVector("maximum_scale");
+    IntVector sqlDataTypeVector = (IntVector) root.getVector("sql_data_type");
+    IntVector sqlDatetimeSubVector = (IntVector) 
root.getVector("sql_datetime_sub");
+    IntVector numPrecRadixVector = (IntVector) 
root.getVector("num_prec_radix");
+
+    List<FieldVector> vectors =
+        ImmutableList.of(typeNameVector, dataTypeVector, columnSizeVector, 
literalPrefixVector, literalSuffixVector,
+            createParamsVector, nullableVector, caseSensitiveVector, 
searchableVector, unsignedAttributeVector,
+            fixedPrecScaleVector, autoIncrementVector, localTypeNameVector, 
minimumScaleVector, maximumScaleVector,
+            sqlDataTypeVector, sqlDatetimeSubVector, numPrecRadixVector);
+
+    Map<FieldVector, String> mapper = new HashMap<>();
+    mapper.put(typeNameVector, "TYPE_NAME");
+    mapper.put(dataTypeVector, "DATA_TYPE");
+    mapper.put(columnSizeVector, "PRECISION");
+    mapper.put(literalPrefixVector, "LITERAL_PREFIX");
+    mapper.put(literalSuffixVector, "LITERAL_SUFFIX");
+    mapper.put(createParamsVector, "CREATE_PARAMS");
+    mapper.put(nullableVector, "NULLABLE");
+    mapper.put(caseSensitiveVector, "CASE_SENSITIVE");
+    mapper.put(searchableVector, "SEARCHABLE");
+    mapper.put(unsignedAttributeVector, "UNSIGNED_ATTRIBUTE");
+    mapper.put(fixedPrecScaleVector, "FIXED_PREC_SCALE");
+    mapper.put(autoIncrementVector, "AUTO_INCREMENT");
+    mapper.put(localTypeNameVector, "LOCAL_TYPE_NAME");
+    mapper.put(minimumScaleVector, "MINIMUM_SCALE");
+    mapper.put(maximumScaleVector, "MAXIMUM_SCALE");
+    mapper.put(sqlDataTypeVector, "SQL_DATA_TYPE");
+    mapper.put(sqlDatetimeSubVector, "SQL_DATETIME_SUB");
+    mapper.put(numPrecRadixVector, "NUM_PREC_RADIX");
+
+    Predicate<ResultSet> predicate;
+    if (request.hasDataType()) {
+      predicate = (resultSet) -> {
+        try {
+          return resultSet.getInt("DATA_TYPE") == request.getDataType();
+        } catch (SQLException e) {
+          throw new RuntimeException(e);
+        }
+      };
+    } else {
+      predicate = (resultSet -> true);
+    }
+
+    saveToVectors(mapper, typeInfo, true, predicate);

Review comment:
       Oh, it already returns the row count. Why not use that below?




-- 
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]


Reply via email to