-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDBC Engine supports Oracle #6815
Open
naive-zhang
wants to merge
6
commits into
apache:master
Choose a base branch
from
naive-zhang:jdbc-oracle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f1b5ed
add jdbc support for Oracle
naive-zhang 397c1cf
Merge branch 'apache:master' into jdbc-oracle
naive-zhang b43cea4
add oracle configuration for kyuubi.engine.jdbc.connection.provider
naive-zhang aa2e2e9
adjust wired space in OracleSQLDialect
naive-zhang d1e82ed
fix code style checking error in settings.md
naive-zhang abf9837
fix code style checking error in KyuubiConf.scala
naive-zhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
...i-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/OracleSQLDialect.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* 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.kyuubi.engine.jdbc.dialect | ||
|
||
import java.sql.{Connection, ResultSet, Statement} | ||
import java.util | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.collection.mutable.ArrayBuffer | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
|
||
import org.apache.kyuubi.KyuubiSQLException | ||
import org.apache.kyuubi.engine.jdbc.oracle.{OracleSchemaHelper, OracleTRowSetGenerator} | ||
import org.apache.kyuubi.engine.jdbc.schema.{JdbcTRowSetGenerator, SchemaHelper} | ||
import org.apache.kyuubi.operation.Operation | ||
import org.apache.kyuubi.operation.meta.ResultSetSchemaConstant._ | ||
import org.apache.kyuubi.session.Session | ||
|
||
class OracleSQLDialect extends JdbcDialect { | ||
|
||
override def createStatement(connection: Connection, fetchSize: Int): Statement = { | ||
val statement = | ||
connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) | ||
if (connection.getAutoCommit) { | ||
statement.setFetchSize(fetchSize) | ||
} | ||
statement | ||
} | ||
|
||
override def getTablesQuery( | ||
catalog: String, | ||
schema: String, | ||
tableName: String, | ||
tableTypes: util.List[String]): String = { | ||
val tTypes = | ||
if (tableTypes == null || tableTypes.isEmpty) { | ||
Set() | ||
} else { | ||
tableTypes.asScala.toSet | ||
} | ||
val query = new StringBuilder( | ||
s"""SELECT OWNER AS TABLE_SCHEMA, | ||
| TABLE_NAME, | ||
| TABLE_TYPE AS TABLE_TYPE | ||
|FROM ALL_CATALOG | ||
|""".stripMargin) | ||
|
||
val filters = ArrayBuffer[String]() | ||
if (StringUtils.isNotBlank(schema)) { | ||
filters += s"OWNER LIKE '$schema'" | ||
} | ||
|
||
if (StringUtils.isNotBlank(tableName)) { | ||
filters += s"$TABLE_NAME LIKE '$tableName'" | ||
} | ||
|
||
if (tTypes.nonEmpty) { | ||
filters += s"(${ | ||
tTypes.map { tableType => s"$TABLE_TYPE = '$tableType'" } | ||
.mkString(" OR ") | ||
})" | ||
} | ||
|
||
if (filters.nonEmpty) { | ||
query.append(" WHERE ") | ||
query.append(filters.mkString(" AND ")) | ||
} | ||
|
||
query.toString() | ||
} | ||
|
||
override def getTableTypesOperation(session: Session): Operation = { | ||
throw KyuubiSQLException.featureNotSupported() | ||
} | ||
|
||
override def getColumnsQuery( | ||
session: Session, | ||
catalogName: String, | ||
schemaName: String, | ||
tableName: String, | ||
columnName: String): String = { | ||
val query = new StringBuilder( | ||
""" | ||
|SELECT OWNER AS TABLE_SCHEMA | ||
| , TABLE_NAME | ||
| , COLUMN_NAME | ||
|FROM ALL_TAB_COLUMNS | ||
|""".stripMargin) | ||
|
||
val filters = ArrayBuffer[String]() | ||
if (StringUtils.isNotEmpty(schemaName)) { | ||
filters += s"OWNER LIKE '$schemaName'" | ||
} | ||
if (StringUtils.isNotEmpty(tableName)) { | ||
filters += s"$TABLE_NAME LIKE '$tableName'" | ||
} | ||
if (StringUtils.isNotEmpty(columnName)) { | ||
filters += s"$COLUMN_NAME LIKE '$columnName'" | ||
} | ||
|
||
if (filters.nonEmpty) { | ||
query.append(" WHERE ") | ||
query.append(filters.mkString(" AND ")) | ||
} | ||
|
||
query.toString() | ||
} | ||
|
||
override def getFunctionsOperation(session: Session): Operation = { | ||
throw KyuubiSQLException.featureNotSupported() | ||
} | ||
|
||
override def getPrimaryKeysOperation(session: Session): Operation = { | ||
throw KyuubiSQLException.featureNotSupported() | ||
} | ||
|
||
override def getCrossReferenceOperation(session: Session): Operation = { | ||
throw KyuubiSQLException.featureNotSupported() | ||
} | ||
|
||
override def getTRowSetGenerator(): JdbcTRowSetGenerator = new OracleTRowSetGenerator | ||
|
||
override def getSchemaHelper(): SchemaHelper = { | ||
// throw KyuubiSQLException.featureNotSupported() | ||
new OracleSchemaHelper | ||
} | ||
|
||
override def name(): String = { | ||
"oracle" | ||
} | ||
} | ||
// class OracleSchemaHelper extends SchemaHelper {} |
26 changes: 26 additions & 0 deletions
26
...engine/src/main/scala/org/apache/kyuubi/engine/jdbc/oracle/OracleConnectionProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.kyuubi.engine.jdbc.oracle | ||
|
||
import org.apache.kyuubi.engine.jdbc.connection.JdbcConnectionProvider | ||
|
||
class OracleConnectionProvider extends JdbcConnectionProvider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update the docs for configuration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review, and I've update the docs~ |
||
override val name: String = classOf[OracleConnectionProvider].getName | ||
|
||
override val driverClass: String = "oracle.jdbc.OracleDriver" | ||
} |
34 changes: 34 additions & 0 deletions
34
...-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/oracle/OracleSchemaHelper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.kyuubi.engine.jdbc.oracle | ||
|
||
import java.sql.Types | ||
|
||
import org.apache.kyuubi.engine.jdbc.schema.SchemaHelper | ||
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeDesc | ||
|
||
class OracleSchemaHelper extends SchemaHelper { | ||
override protected def toTTypeDesc(sqlType: Int, precision: Int, scale: Int): TTypeDesc = { | ||
sqlType match { | ||
case Types.NUMERIC if scale == 0 => | ||
super.toTTypeDesc(Types.INTEGER, precision, scale) | ||
case Types.NUMERIC => | ||
super.toTTypeDesc(Types.DECIMAL, precision, scale) | ||
case _ => super.toTTypeDesc(sqlType, precision, scale) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...c-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/oracle/OracleTRowSetGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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.kyuubi.engine.jdbc.oracle | ||
|
||
import org.apache.kyuubi.engine.jdbc.schema.DefaultJdbcTRowSetGenerator | ||
|
||
class OracleTRowSetGenerator extends DefaultJdbcTRowSetGenerator {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../src/test/scala/org/apache/kyuubi/engine/jdbc/oracle/OperationWithOracleEngineSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.kyuubi.engine.jdbc.oracle | ||
|
||
import org.apache.kyuubi.config.KyuubiConf | ||
import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider | ||
import org.apache.kyuubi.operation.HiveJDBCTestHelper | ||
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.{TGetInfoReq, TGetInfoType} | ||
|
||
class OperationWithOracleEngineSuite extends OracleOperationSuite with HiveJDBCTestHelper { | ||
|
||
override protected def jdbcUrl: String = jdbcConnectionUrl | ||
|
||
test("oracle - test for Jdbc engine getInfo") { | ||
val metaData = ConnectionProvider.create(kyuubiConf).getMetaData | ||
|
||
withSessionConf(Map(KyuubiConf.SERVER_INFO_PROVIDER.key -> "ENGINE"))()() { | ||
withSessionHandle { (client, handle) => | ||
val req = new TGetInfoReq() | ||
req.setSessionHandle(handle) | ||
req.setInfoType(TGetInfoType.CLI_DBMS_NAME) | ||
assert(client.GetInfo(req).getInfoValue.getStringValue == metaData.getDatabaseProductName) | ||
|
||
val req2 = new TGetInfoReq() | ||
req2.setSessionHandle(handle) | ||
req2.setInfoType(TGetInfoType.CLI_DBMS_VER) | ||
assert( | ||
client.GetInfo(req2).getInfoValue.getStringValue == metaData.getDatabaseProductVersion) | ||
|
||
val req3 = new TGetInfoReq() | ||
req3.setSessionHandle(handle) | ||
req3.setInfoType(TGetInfoType.CLI_MAX_COLUMN_NAME_LEN) | ||
assert(client.GetInfo(req3).getInfoValue.getLenValue == metaData.getMaxColumnNameLength) | ||
|
||
val req4 = new TGetInfoReq() | ||
req4.setSessionHandle(handle) | ||
req4.setInfoType(TGetInfoType.CLI_MAX_SCHEMA_NAME_LEN) | ||
assert(client.GetInfo(req4).getInfoValue.getLenValue == metaData.getMaxSchemaNameLength) | ||
|
||
val req5 = new TGetInfoReq() | ||
req5.setSessionHandle(handle) | ||
req5.setInfoType(TGetInfoType.CLI_MAX_TABLE_NAME_LEN) | ||
assert(client.GetInfo(req5).getInfoValue.getLenValue == metaData.getMaxTableNameLength) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weired spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I've already adjusted the wired space