You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "diqiu50 (via GitHub)" <gi...@apache.org> on 2026/06/05 07:18:53 UTC

[PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

diqiu50 opened a new pull request, #11451:
URL: https://github.com/apache/gravitino/pull/11451

   ## What changes were proposed in this pull request?
   
   MySQL `datetime` columns were unusable as filter predicates when accessed via Gravitino's Spark JDBC connector (e.g. `WHERE update_time >= '2025-12-04 09:07:43'` would fail with `SQLSyntaxErrorException: ... near ':07:43)'`).
   
   **Root cause:** Gravitino's JDBC type converters mapped MySQL `datetime` (`Types.TimestampType.withoutTimeZone()`) to Spark `TimestampNTZType` in Spark 3.4+, while the MySQL JDBC dialect only knows how to format `TimestampType` literals during filter pushdown. In Spark 3.3, this path threw `UnsupportedOperationException` instead.
   
   Without Gravitino, Spark's native JDBC MySQL catalog maps `datetime` → `TimestampType`, so filter pushdown works correctly.
   
   **Fix:**
   - `SparkJdbcTypeConverter`: map `TimestampType.withoutTimeZone()` → `TimestampType` (fixes Spark 3.3)
   - `SparkJdbcTypeConverter34`: override parent's `TimestampNTZType` mapping → `TimestampType` (fixes Spark 3.4)
   - `GravitinoJdbcCatalogSpark35`: use `SparkJdbcTypeConverter34` instead of `SparkTypeConverter34` (fixes Spark 3.5, also corrects a pre-existing gap where the Spark 3.5 JDBC catalog was missing `VarCharType` handling)
   
   Note: `toGravitinoType(TimestampType)` continues to return `withTimeZone()` (inherited, unchanged). Both MySQL `TIMESTAMP` and `DATETIME` columns round-trip to `withTimeZone()` in Gravitino metadata — this asymmetry is intentional for JDBC compatibility.
   
   ## How was this patch tested?
   
   - Added unit tests for all three affected converters (`TestSparkJdbcTypeConverter`, `TestSparkJdbcTypeConverter34`, `TestSparkJdbcTypeConverter35`)
   - Added `TimestampType.withoutTimeZone()` to `notSupportGravitinoTypes` in `TestSparkTypeConverter` to document the base-class behavior
   - All new tests assert the JDBC override, the delegation path, and the intentional `toGravitinoType` asymmetry


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 closed pull request #11451: [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector
URL: https://github.com/apache/gravitino/pull/11451


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11451:
URL: https://github.com/apache/gravitino/pull/11451#issuecomment-4629749519

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|66.94%|:green_circle:|
   |:-|:-|:-:|
   |Files changed|54.55%|:red_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.8%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.04%|:red_circle:|
   |catalog-fileset|80.35%|:green_circle:|
   |catalog-glue|66.67%|:green_circle:|
   |catalog-hive|79.35%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|45.31%|:green_circle:|
   |catalog-jdbc-doris|80.28%|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|44.89%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.74%|:green_circle:|
   |catalog-lakehouse-paimon|79.29%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|77.91%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.48%|:green_circle:|
   |filesystem-hadoop3|76.97%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|46.09%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.39%|:red_circle:|
   |hive-metastore-common|53.42%|:green_circle:|
   |iceberg-common|56.54%|:green_circle:|
   |iceberg-rest-server|73.5%|:green_circle:|
   |idp-basic|85.99%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.83%|:red_circle:|
   |lance-rest-server|60.27%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.87%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.73%|:green_circle:|
   |server-common|73.28%|:green_circle:|
   |spark|40.0% **`+2.71%`**|:green_circle:|
   |spark-common|41.07%|:green_circle:|
   |trino-connector|39.97%|:red_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |spark|[SparkJdbcTypeConverter34.java](https://github.com/diqiu50/gravitino/blob/4e0bda33df752bcdb566eff4e9d01a6b92cd8393/spark-connector/v3.4/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTypeConverter34.java)|85.71%|:green_circle:|
   ||[GravitinoJdbcCatalogSpark35.java](https://github.com/diqiu50/gravitino/blob/4e0bda33df752bcdb566eff4e9d01a6b92cd8393/spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalogSpark35.java)|0.0%|:red_circle:|
   
   </details>


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on PR #11451:
URL: https://github.com/apache/gravitino/pull/11451#issuecomment-4629210024

   There is a similar fix. https://github.com/apache/gravitino/pull/11424


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 merged PR #11451:
URL: https://github.com/apache/gravitino/pull/11451


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #11451:
URL: https://github.com/apache/gravitino/pull/11451#discussion_r3361080101


##########
spark-connector/v3.5/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestSparkJdbcTypeConverter35.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.TimestampType;
+import org.apache.spark.sql.types.DataTypes;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestSparkJdbcTypeConverter35 {
+
+  // GravitinoJdbcCatalogSpark35.getSparkTypeConverter() returns SparkJdbcTypeConverter34.
+  private final SparkJdbcTypeConverter34 converter = new SparkJdbcTypeConverter34();
+
+  @Test
+  void testDatetimeWithoutTimezoneConvertsToTimestampType() {
+    // Spark 3.5 introduces TimestampNTZType (via SparkTypeConverter34). Without the JDBC override,
+    // MySQL datetime (withoutTimeZone) would map to TimestampNTZType, which the MySQL JDBC dialect
+    // cannot format as valid SQL, causing syntax errors like "near ':07:43)'".

Review Comment:
   The comment says Spark 3.5 introduces `TimestampNTZType`, but this type is already present in Spark 3.4+ (as evidenced by `SparkTypeConverter34`). This is misleading documentation for why the override is needed.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#9374] fix(spark): Fix MySQL datetime filter pushdown in Spark JDBC connector [gravitino]

Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on PR #11451:
URL: https://github.com/apache/gravitino/pull/11451#issuecomment-4645251267

   > There is a similar fix. #11424
   
   It's not fix this bugs


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org