Gabriel39 commented on code in PR #70176: URL: https://github.com/apache/doris/pull/70176#discussion_r4661345266
########## fe/fe-connector/fe-connector-adbc/src/main/java/org/apache/doris/connector/adbc/AdbcDriverInfo.java: ########## @@ -0,0 +1,79 @@ +// 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.doris.connector.adbc; + +import org.apache.doris.connector.spi.DorisConnectorException; + +import org.apache.arrow.adbc.core.AdbcConnection; +import org.apache.arrow.adbc.core.AdbcException; +import org.apache.arrow.adbc.core.AdbcInfoCode; +import org.apache.arrow.adbc.core.AdbcStatusCode; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.ipc.ArrowReader; + +import java.util.Locale; + +/** Verifies the native Flight driver's server-info isolation before it can mutate vendor state. */ +final class AdbcDriverInfo { + // Private local GetInfo capability, advertised by the bundled ADBC source patch; never sent to a server. + private static final int CONNECTION_SCOPED_VENDOR_INFO = 0x444f0001; + + private AdbcDriverInfo() { + } + + static void requireIsolatedVendorInfo(AdbcConnection connection) throws Exception { + Object name = null; + try { + name = readInfo(connection, AdbcInfoCode.DRIVER_NAME.getValue()); + } catch (AdbcException e) { + if (e.getStatus() != AdbcStatusCode.NOT_IMPLEMENTED && e.getStatus() != AdbcStatusCode.NOT_FOUND) { + throw e; + } + } + // Missing identity cannot prove that an operator-supplied library is a non-Flight driver. + // Require isolation before any vendor request when DRIVER_NAME is unavailable or empty. + if (name != null && !name.toString().isBlank() + && !name.toString().toLowerCase(Locale.ROOT).contains("flight sql")) { + return; + } Review Comment: Fixed in 37576cbc6587. The isolation guard now treats every case-insensitive Flight-like driver name as ambiguous, including FlightSQL, ArrowFlightSQL and names with hyphens or underscores. Missing or false capability responses stop before VENDOR_NAME; an isolated driver is still probed once and its vendor is cached. Identified non-Flight drivers keep the generic path. The 15 additional name cases fail on f1c61a20a4d; all 29 guard cases and all 246 ADBC tests now pass with zero failures/errors/skips, including native SQLite. FE Checkstyle and the connector import gate pass. Tests compiled current connector sources with the Maven build cache disabled and reused the existing Thrift dependency because the local compiler version does not match this branch. ########## fe/fe-connector/fe-connector-adbc/src/main/java/org/apache/doris/connector/adbc/AdbcDorisMetadata.java: ########## @@ -0,0 +1,100 @@ +// 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.doris.connector.adbc; + +import org.apache.doris.connector.spi.DorisConnectorException; + +import org.apache.arrow.adbc.core.AdbcConnection; +import org.apache.arrow.adbc.core.AdbcException; +import org.apache.arrow.adbc.core.AdbcStatement; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.ipc.ArrowReader; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** Metadata confined to the remote catalog that the ADBC connection uses for SQL execution. */ +final class AdbcDorisMetadata { + private static final DorisDialect DIALECT = new DorisDialect(); + + private AdbcDorisMetadata() { + } + + static boolean isDorisSource(AdbcClient client, Supplier<AdbcDialect> dialect) { + Optional<String> vendor = client.vendorName().map(String::trim).filter(name -> !name.isEmpty()); + if (vendor.isPresent() && !"Flight SQL".equalsIgnoreCase(vendor.get())) { + return DIALECT.matchesVendor(vendor.get()); + } + // Older Flight servers lack SQL info; the native driver can return its generic vendor default. + // An explicit Doris dialect opts into scoped discovery so GetObjects cannot reenter the source catalog. + return DorisDialect.NAME.equals(dialect.get().name()); + } + + static List<AdbcNamespace> readNamespaces(AdbcConnection connection) throws AdbcException, IOException { + List<String> catalogs = new ArrayList<>(1); + // Older Doris servers expose the current catalog through SQL but lack Flight GetSessionOptions. + readRows(connection, "SELECT CURRENT_CATALOG()", row -> catalogs.add(row.get(0))); + String catalog = catalogs.get(0); + if (catalog == null || catalog.isEmpty()) { + throw new DorisConnectorException("The Doris ADBC connection must select a remote catalog"); + } + List<AdbcNamespace> namespaces = new ArrayList<>(); + // The Flight driver omits catalog filters in GetObjects RPCs. On a loopback source, unrestricted + // discovery reenters the ADBC catalog whose metadata load is waiting for that RPC to complete. + readRows(connection, "SHOW DATABASES FROM " + DIALECT.quoteIdentifier(catalog), + row -> namespaces.add(new AdbcNamespace(catalog, row.get(0)))); + return namespaces; + } + + static List<String> readTableNames(AdbcConnection connection, AdbcNamespace namespace) + throws AdbcException, IOException { + List<String> tables = new ArrayList<>(); + // Scope the actual SQL request, not just GetObjects' client-side result filtering. + readRows(connection, "SHOW FULL TABLES FROM " + DIALECT.quoteIdentifier(namespace.getRemoteCatalog()) + + "." + DIALECT.quoteIdentifier(namespace.getRemoteDbSchema()), row -> { + if (AdbcObjectsReader.isBaseTable(row.get(1))) { + tables.add(row.get(0)); + } + }); + return tables; + } + + private static void readRows(AdbcConnection connection, String sql, Consumer<List<String>> consumer) + throws AdbcException, IOException { + try (AdbcStatement statement = connection.createStatement()) { + statement.setSqlQuery(sql); + try (AdbcStatement.QueryResult result = statement.executeQuery()) { + ArrowReader reader = result.getReader(); + VectorSchemaRoot root = reader.getVectorSchemaRoot(); + while (reader.loadNextBatch()) { + for (int row = 0; row < root.getRowCount(); row++) { + List<String> values = new ArrayList<>(); + for (int column = 0; column < root.getFieldVectors().size(); column++) { + values.add(root.getVector(column).getObject(row).toString()); + } + consumer.accept(values); Review Comment: Fixed in 37576cbc6587. Arrow row conversion preserves SQL NULL so CURRENT_CATALOG() reaches the existing explicit connector error: "The Doris ADBC connection must select a remote catalog". The recording fixture now emits a genuinely nullable Arrow cell. Both null and empty catalog cases assert the exact connector error, no SHOW/GetObjects discovery and statement closure. The null case fails with NullPointerException before the fix; all 16 AdbcDorisMetadataTest cases pass afterward. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
