Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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

object HiveDialect extends JdbcDialect {

override def canHandle(url: String): Boolean = url.startsWith("jdbc:hive2")

override def quoteIdentifier(colName: String): String = s"`$colName`"

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ object JdbcDialects {
registerDialect(DerbyDialect)
registerDialect(OracleDialect)
registerDialect(TeradataDialect)
registerDialect(HiveDialect)

/**
* Fetch the JdbcDialect class corresponding to a given database url.
Expand Down
18 changes: 14 additions & 4 deletions sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,19 @@ class JDBCSuite extends SparkFunSuite
|OPTIONS (url '$urlWithUserAndPass',
|dbtable '(SELECT NVL(@MYTESTVAR1, -1), NVL(@MYTESTVAR2, -1))',
|sessionInitStatement 'SET @MYTESTVAR1 21519; SET @MYTESTVAR2 1234')
""".stripMargin)
""".stripMargin)

val df3 = sql("SELECT * FROM test_sessionInitStatement")
assert(df3.collect() === Array(Row(21519, 1234)))
}
val df3 = sql("SELECT * FROM test_sessionInitStatement")
assert(df3.collect() === Array(Row(21519, 1234)))
}

test("Hive dialect registration") {
assert(JdbcDialects.get("jdbc:hive2://127.0.0.1/db") == HiveDialect)
}

test("Hive dialect quoted identifier") {
val dialect = JdbcDialects.get("jdbc:hive2://127.0.0.1/db")
val quotedIdentifier = dialect.quoteIdentifier("a_column")
assert(quotedIdentifier == "`a_column`")
}
}