World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#11231] fix(spark-connector): handle JDBC timestamp type (#11424)
YangJie3ce2387bcd93
diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTypeConverter.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTypeConverter.javaindex 56e2734a7f..95a9c0c408 100644--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTypeConverter.java+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTypeConverter.java@@ -33,6 +33,8 @@ public class SparkJdbcTypeConverter extends SparkTypeConverter {// type varchar.if (gravitinoType instanceof Types.VarCharType) {return DataTypes.StringType;+ } else if (gravitinoType instanceof Types.TimestampType) {+ return DataTypes.TimestampType;} else {return super.toSparkType(gravitinoType);}diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter.javanew file mode 100644index 0000000000..00fd1c7784--- /dev/null+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter.java@@ -0,0 +1,47 @@+/*+ * 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;++import org.apache.gravitino.rel.types.Types;+import org.apache.spark.sql.types.DataTypes;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.Test;++/** Unit tests for {@link SparkJdbcTypeConverter}. */+public class TestSparkJdbcTypeConverter {++ private final SparkJdbcTypeConverter sparkJdbcTypeConverter = new SparkJdbcTypeConverter();++ @Test+ void testConvertTimestampTypesToSparkTimestamp() {+ Assertions.assertEquals(+ DataTypes.TimestampType,+ sparkJdbcTypeConverter.toSparkType(Types.TimestampType.withTimeZone()));+ Assertions.assertEquals(+ DataTypes.TimestampType,+ sparkJdbcTypeConverter.toSparkType(Types.TimestampType.withoutTimeZone()));+ }++ @Test+ void testConvertVarCharTypeToSparkString() {+ Assertions.assertEquals(+ DataTypes.StringType, sparkJdbcTypeConverter.toSparkType(Types.VarCharType.of(10)));+ }+}