diff --git a/sql/core/src/main/resources/META-INF/services/org.apache.spark.sql.jdbc.JdbcDialect b/sql/core/src/main/resources/META-INF/services/org.apache.spark.sql.jdbc.JdbcDialect index 0b9dda2d14f24..7dae16d168716 100644 --- a/sql/core/src/main/resources/META-INF/services/org.apache.spark.sql.jdbc.JdbcDialect +++ b/sql/core/src/main/resources/META-INF/services/org.apache.spark.sql.jdbc.JdbcDialect @@ -18,6 +18,7 @@ # org.apache.spark.sql.jdbc.MySQLDialect +org.apache.spark.sql.jdbc.HiveDialect org.apache.spark.sql.jdbc.PostgresDialect org.apache.spark.sql.jdbc.DB2Dialect org.apache.spark.sql.jdbc.MsSqlServerDialect diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/HiveDialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/HiveDialect.scala new file mode 100644 index 0000000000000..dc77f09e12507 --- /dev/null +++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/HiveDialect.scala @@ -0,0 +1,29 @@ +/* + * 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.spark.sql.jdbc + +import java.util.Locale + +private case class HiveDialect() extends JdbcDialect { + override def canHandle(url: String): Boolean = + url.toLowerCase(Locale.ROOT).startsWith("jdbc:hive2") + + override def quoteIdentifier(colName: String): String = { + s"`$colName`" + } +} diff --git a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala index e4116b565818e..07433e2b4ae2e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala @@ -787,6 +787,7 @@ class JDBCSuite extends QueryTest with SharedSparkSession { test("Default jdbc dialect registration") { assert(JdbcDialects.get("jdbc:mysql://127.0.0.1/db") === MySQLDialect()) + assert(JdbcDialects.get("jdbc:hive2://127.0.0.1/db") === HiveDialect()) assert(JdbcDialects.get("jdbc:postgresql://127.0.0.1/db") === PostgresDialect()) assert(JdbcDialects.get("jdbc:db2://127.0.0.1/db") === DB2Dialect()) assert(JdbcDialects.get("jdbc:sqlserver://127.0.0.1/db") === MsSqlServerDialect())