in flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowDatabaseMetadata.java [969:1040]
public ResultSet getColumns(
final String catalog,
final String schemaPattern,
final String tableNamePattern,
final String columnNamePattern)
throws SQLException {
final ArrowFlightConnection connection = getConnection();
final FlightInfo flightInfoTables =
connection
.getClientHandler()
.getTables(catalog, schemaPattern, tableNamePattern, null, true);
final BufferAllocator allocator = connection.getBufferAllocator();
final Pattern columnNamePat =
columnNamePattern != null ? Pattern.compile(sqlToRegexLike(columnNamePattern)) : null;
return ArrowFlightJdbcFlightStreamResultSet.fromFlightInfo(
connection,
flightInfoTables,
(originalRoot, transformedRoot) -> {
int columnCounter = 0;
if (transformedRoot == null) {
transformedRoot = VectorSchemaRoot.create(GET_COLUMNS_SCHEMA, allocator);
}
final int originalRootRowCount = originalRoot.getRowCount();
final VarCharVector catalogNameVector =
(VarCharVector) originalRoot.getVector("catalog_name");
final VarCharVector tableNameVector =
(VarCharVector) originalRoot.getVector("table_name");
final VarCharVector schemaNameVector =
(VarCharVector) originalRoot.getVector("db_schema_name");
final VarBinaryVector schemaVector =
(VarBinaryVector) originalRoot.getVector("table_schema");
for (int i = 0; i < originalRootRowCount; i++) {
final Text catalogName = catalogNameVector.getObject(i);
final Text tableName = tableNameVector.getObject(i);
final Text schemaName = schemaNameVector.getObject(i);
final Schema currentSchema;
try {
currentSchema =
MessageSerializer.deserializeSchema(
new ReadChannel(
Channels.newChannel(new ByteArrayInputStream(schemaVector.get(i)))));
} catch (final IOException e) {
throw new IOException(
String.format("Failed to deserialize schema for table %s", tableName), e);
}
final List<Field> tableColumns = currentSchema.getFields();
columnCounter =
setGetColumnsVectorSchemaRootFromFields(
transformedRoot,
columnCounter,
tableColumns,
catalogName,
tableName,
schemaName,
columnNamePat);
}
transformedRoot.setRowCount(columnCounter);
originalRoot.clear();
return transformedRoot;
});
}