yuqi1129 commented on code in PR #13493:
URL: https://github.com/apache/gravitino/pull/13493#discussion_r4123375016


##########
spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/DorisPhysicalSchemaValidator35.java:
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.gravitino.spark.connector.jdbc.doris;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Table;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.spark.connector.SparkTypeConverter;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+
+/** Validates one authorized Doris table against FE and JDBC physical 
metadata. */
+final class DorisPhysicalSchemaValidator35 {
+
+  private static final Set<String> ORDINARY_TYPES =
+      ImmutableSet.of(
+          "bigint",
+          "boolean",
+          "char",
+          "date",
+          "datev2",
+          "datetime",
+          "datetimev2",
+          "decimal",
+          "double",
+          "float",
+          "int",
+          "integer",
+          "smallint",
+          "string",
+          "text",
+          "tinyint",
+          "varchar");
+
+  private DorisPhysicalSchemaValidator35() {}
+
+  static void validate(
+      Identifier identifier,
+      Table logicalTable,
+      StructType sparkPhysicalSchema,
+      String jdbcUrl,
+      String jdbcDriver,
+      String jdbcUser,
+      String jdbcPassword,
+      SparkTypeConverter typeConverter) {
+    try {
+      Class.forName(jdbcDriver);
+      try (Connection connection = DriverManager.getConnection(jdbcUrl, 
jdbcUser, jdbcPassword)) {
+        List<PhysicalColumn> jdbcColumns = loadJdbcColumns(connection, 
identifier);
+        List<PhysicalColumn> feColumns = loadFeColumns(connection, identifier);
+        validateColumns(
+            identifier, logicalTable, sparkPhysicalSchema, jdbcColumns, 
feColumns, typeConverter);
+      }
+    } catch (ClassNotFoundException | SQLException | RuntimeException e) {
+      if (e instanceof IllegalArgumentException
+          && e.getMessage() != null
+          && e.getMessage().startsWith("Doris schema mismatch")) {
+        throw (IllegalArgumentException) e;
+      }
+      throw new IllegalArgumentException(
+          "Doris physical schema validation failed for " + identifier);

Review Comment:
   Every non-mismatch failure is rethrown without its cause, so users can't 
tell what went wrong.
   
   A missing driver on the classpath (the most likely setup error, since the 
docs ask users to provide Connector/J themselves), an unreachable FE, an 
authentication failure, a vended account without `SHOW COLUMNS` access, or an 
unsupported type from `typeConverter.toSparkType` all end up as the same `Doris 
physical schema validation failed for <ident>`. Because this path fails closed, 
that is the error users will see most often.
   
   Could you:
   - keep the cause: `new IllegalArgumentException("Doris physical schema 
validation failed for " + identifier, e)`. Connector/J messages don't include 
the password;
   - use a private exception subclass for schema mismatches instead of matching 
the `"Doris schema mismatch"` message prefix;
   - add a unit test with a wrong driver class name that asserts `getCause()` 
is a `ClassNotFoundException`?



##########
spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/DorisPhysicalSchemaValidator35.java:
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.gravitino.spark.connector.jdbc.doris;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Set;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Table;
+import org.apache.gravitino.rel.types.Type;
+import org.apache.gravitino.rel.types.Types;
+import org.apache.gravitino.spark.connector.SparkTypeConverter;
+import org.apache.spark.sql.connector.catalog.Identifier;
+import org.apache.spark.sql.types.DataType;
+import org.apache.spark.sql.types.StructField;
+import org.apache.spark.sql.types.StructType;
+
+/** Validates one authorized Doris table against FE and JDBC physical 
metadata. */
+final class DorisPhysicalSchemaValidator35 {
+
+  private static final Set<String> ORDINARY_TYPES =

Review Comment:
   `ORDINARY_TYPES` lists 17 types, but `SparkJdbcDorisReadBaselineIT35` only 
creates `INT` and `VARCHAR(64)` columns.
   
   `validateColumns` requires the FE `SHOW COLUMNS` signature and the JDBC 
`getColumns` signature to be equal. When the two report a type differently, the 
table is rejected as a schema mismatch and can't be read. I haven't verified 
these against Doris, but from the code a few look risky:
   - `datetime` with scale 0: FE may print `datetime`, while JDBC 
`DECIMAL_DIGITS = 0` becomes `datetime(0)`;
   - `boolean`: over the MySQL protocol, JDBC may report `TINYINT`;
   - `string` / `text`: JDBC may report a sized `VARCHAR`, while FE prints 
`string`;
   - `float`, `double`, `char`, `date` and `decimal` aren't exercised either.
   
   Could you add a table to the IT with one column per `ORDINARY_TYPES` entry, 
both nullable and `NOT NULL`, and read the values back? Any type that doesn't 
match should be normalized in `typeSignature` or removed from `ORDINARY_TYPES` 
and the docs.



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