Skip to content

Commit

Permalink
[SPARK-47482] Add HiveDialect to sql module
Browse files Browse the repository at this point in the history
  • Loading branch information
xleoken committed Jun 11, 2024
1 parent 53d65fd commit 36c61b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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`"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 36c61b3

Please sign in to comment.