tokoko commented on code in PR #605:
URL: https://github.com/apache/arrow-adbc/pull/605#discussion_r1462586795


##########
java/driver/flight-sql/src/main/java/org/apache/arrow/adbc/driver/flightsql/ObjectMetadataBuilder.java:
##########
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.adbc.driver.flightsql;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.channels.Channels;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import org.apache.arrow.adbc.core.AdbcConnection;
+import org.apache.arrow.adbc.core.AdbcException;
+import org.apache.arrow.adbc.core.StandardSchemas;
+import org.apache.arrow.flight.FlightEndpoint;
+import org.apache.arrow.flight.FlightInfo;
+import org.apache.arrow.flight.FlightStream;
+import org.apache.arrow.flight.sql.FlightSqlClient;
+import org.apache.arrow.memory.ArrowBuf;
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.arrow.vector.complex.impl.UnionListWriter;
+import org.apache.arrow.vector.complex.writer.BaseWriter;
+import org.apache.arrow.vector.complex.writer.VarCharWriter;
+import org.apache.arrow.vector.ipc.ReadChannel;
+import org.apache.arrow.vector.ipc.message.MessageSerializer;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.Schema;
+
+final class ObjectMetadataBuilder {
+
+  private final FlightSqlClient client;
+  private final VectorSchemaRoot root;
+  private final VarCharVector adbcCatalogNames;
+  private final UnionListWriter adbcCatalogDbSchemasWriter;
+  private final BaseWriter.StructWriter adbcCatalogDbSchemasStructWriter;
+  private final BaseWriter.ListWriter adbcCatalogDbSchemaTablesWriter;
+  private final VarCharWriter adbcCatalogDbSchemaNameWriter;
+  private final BaseWriter.StructWriter adbcTablesStructWriter;
+  private final VarCharWriter adbcTableNameWriter;
+  private final VarCharWriter adbcTableTypeWriter;
+  private final BaseWriter.ListWriter adbcTableColumnsWriter;
+  private final BufferAllocator allocator;
+  private final AdbcConnection.GetObjectsDepth depth;
+  private final String catalogPattern;
+  private final String dbSchemaPattern;
+  private final String tableNamePattern;
+  private final String[] tableTypes;
+  private final String columnNamePattern;
+
+  ObjectMetadataBuilder(
+      BufferAllocator allocator,
+      FlightSqlClient client,
+      final AdbcConnection.GetObjectsDepth depth,
+      final String catalogPattern,
+      final String dbSchemaPattern,
+      final String tableNamePattern,
+      final String[] tableTypes,
+      final String columnNamePattern) {
+    this.allocator = allocator;
+    this.client = client;
+    this.depth = depth;
+    this.catalogPattern = catalogPattern;
+    this.dbSchemaPattern = dbSchemaPattern;
+    this.tableNamePattern = tableNamePattern;
+    this.tableTypes = tableTypes;
+    this.columnNamePattern = columnNamePattern;
+    this.root = VectorSchemaRoot.create(StandardSchemas.GET_OBJECTS_SCHEMA, 
allocator);
+    this.adbcCatalogNames = (VarCharVector) root.getVector(0);
+    this.adbcCatalogDbSchemasWriter = ((ListVector) 
root.getVector(1)).getWriter();
+    this.adbcCatalogDbSchemasStructWriter = 
adbcCatalogDbSchemasWriter.struct();
+    this.adbcCatalogDbSchemaTablesWriter =
+        adbcCatalogDbSchemasStructWriter.list("db_schema_tables");
+    this.adbcCatalogDbSchemaNameWriter = 
adbcCatalogDbSchemasStructWriter.varChar("db_schema_name");
+    this.adbcTablesStructWriter = adbcCatalogDbSchemaTablesWriter.struct();
+    this.adbcTableNameWriter = adbcTablesStructWriter.varChar("table_name");
+    this.adbcTableTypeWriter = adbcTablesStructWriter.varChar("table_type");
+    this.adbcTableColumnsWriter = adbcTablesStructWriter.list("table_columns");
+  }
+
+  private void writeVarChar(VarCharWriter writer, String value) {
+    byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
+    try (ArrowBuf tempBuf = allocator.buffer(bytes.length)) {
+      tempBuf.setBytes(0, bytes, 0, bytes.length);
+      writer.writeVarChar(0, bytes.length, tempBuf);
+    }
+  }
+
+  private boolean patternMatched(String name, String pattern) {
+    if (pattern == null) {
+      return true;
+    }
+
+    return name.matches(pattern.replace("_", ".").replace("%", ".*"));

Review Comment:
   moved quote and precompile step to constructor



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