jiangxt2 commented on code in PR #13493: URL: https://github.com/apache/gravitino/pull/13493#discussion_r4129328841
########## 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: Thanks for the review. I moved schema checks outside the metadata `try` block, removing message-prefix matching; JDBC failures, including `SHOW COLUMNS`, now report the stage and available SQLState/vendor code. I did not retain the raw cause because [JDK 17 `DriverManager`](https://github.com/openjdk/jdk17u/blob/master/src/java.sql/share/classes/java/sql/DriverManager.java) can echo the full URL, which [may contain credentials](https://dev.mysql.com/doc/connector-j/en/connector-j-reference-jdbc-url-format.html), contrary to [#13489's redaction requirement](https://github.com/apache/gravitino/issues/13489). Unit tests verify that surfaced errors omit a sentinel password. I removed the redundant `Class.forName` because [Spark registers the configured driver](https://github.com/apache/spark/blob/v3.5.3/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCOptions.scala); `requireProperty(all, "driver")` still checks its presence, and `all` is then passed to Spar k. -- 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]
