-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #6815] JDBC Engine supports Oracle
# Description Currently, Kyuubi supports JDBC engines with limited dialects, and I extend the dialects to support Oracle. * Introduce Oracle support in JDBC Engine * Adding dialects and tests for Oracle ## Types of changes 🔖 - [ ] Bugfix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 Add tests of `OperationWithOracleEngineSuite`, `OracleOperationSuite`, `OracleSessionSuite` and `OracleStatementSuite`. --- # Checklist 📝 - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6815 from naive-zhang/jdbc-oracle. Closes #6815 0ffad5b [native-zhang] add some brief comments on the caller side for the implementation of Oracle JDBC engine 6f469a1 [naive-zhang] Merge branch 'apache:master' into jdbc-oracle ae70710 [Cheng Pan] Update externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/OracleSQLDialect.scala 171d06b [native-zhang] use another implementation of transform decimal into int, in engine instead of KyuubiBaseResultSet 7cb74d2 [naive-zhang] Merge branch 'apache:master' into jdbc-oracle ccd7cae [naive-zhang] remove redundant override methods in OracleSQLDialect.scala a7da4a6 [naive-zhang] remove redundant impl of getTableTypesOperation in OracleSQLDialect.scala 70b49fc [naive-zhang] Use the single line string if SQL fits in one line, otherwise write it in a pretty style e583484 [naive-zhang] Update externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/OracleSQLDialect.scala b33e97a [naive-zhang] remove redundant testcontainers-scala-oracle-xe dependency in pom.xml 4c967b9 [naive-zhang] use gvenzl/oracle-free:23.5-slim with docker-compose for test case 0215e6d [naive-zhang] Merge branch 'apache:master' into jdbc-oracle d688b47 [naive-zhang] change oracle image into gvenzl/oracle-free:23.5-slim abf9837 [naive-zhang] fix code style checking error in KyuubiConf.scala d1e82ed [naive-zhang] fix code style checking error in settings.md aa2e2e9 [naive-zhang] adjust wired space in OracleSQLDialect b43cea4 [naive-zhang] add oracle configuration for kyuubi.engine.jdbc.connection.provider 397c1cf [naive-zhang] Merge branch 'apache:master' into jdbc-oracle 2f1b5ed [naive-zhang] add jdbc support for Oracle Lead-authored-by: naive-zhang <[email protected]> Co-authored-by: native-zhang <[email protected]> Co-authored-by: Cheng Pan <[email protected]> Signed-off-by: Cheng Pan <[email protected]>
- Loading branch information
1 parent
68a6f48
commit eb1b599
Showing
18 changed files
with
664 additions
and
3 deletions.
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
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
114 changes: 114 additions & 0 deletions
114
...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,114 @@ | ||
/* | ||
* 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.engine.jdbc.oracle.{OracleSchemaHelper, OracleTRowSetGenerator} | ||
import org.apache.kyuubi.engine.jdbc.schema.{JdbcTRowSetGenerator, SchemaHelper} | ||
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( | ||
"SELECT OWNER AS TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE AS TABLE_TYPE FROM ALL_CATALOG") | ||
|
||
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 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") | ||
|
||
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 getTRowSetGenerator(): JdbcTRowSetGenerator = new OracleTRowSetGenerator | ||
|
||
override def getSchemaHelper(): SchemaHelper = new OracleSchemaHelper | ||
|
||
override def name(): String = "oracle" | ||
} |
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 { | ||
override val name: String = classOf[OracleConnectionProvider].getName | ||
// use oracle jdbc class for connection | ||
override val driverClass: String = "oracle.jdbc.OracleDriver" | ||
} |
36 changes: 36 additions & 0 deletions
36
...-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,36 @@ | ||
/* | ||
* 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 for int, returns NUMERIC type in Oracle JDBC | ||
case Types.NUMERIC if scale == 0 => | ||
super.toTTypeDesc(Types.INTEGER, precision, scale) | ||
// except for int | ||
case Types.NUMERIC => | ||
super.toTTypeDesc(Types.DECIMAL, precision, scale) | ||
case _ => super.toTTypeDesc(sqlType, precision, scale) | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...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,46 @@ | ||
/* | ||
* 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.{Column, DefaultJdbcTRowSetGenerator} | ||
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.{TColumn, TColumnValue} | ||
|
||
class OracleTRowSetGenerator extends DefaultJdbcTRowSetGenerator { | ||
|
||
override def toIntegerTColumn(rows: Seq[Seq[_]], ordinal: Int): TColumn = { | ||
// define convertFunc in asIntegerTColumn for int type | ||
asIntegerTColumn(rows, ordinal, (rows, ordinal) => Integer.parseInt(rows(ordinal).toString)) | ||
} | ||
|
||
override def toIntegerTColumnValue(row: Seq[_], ordinal: Int): TColumnValue = { | ||
asIntegerTColumnValue(row, ordinal, x => Integer.parseInt(x.toString)) | ||
super.toIntegerTColumnValue(row, ordinal) | ||
} | ||
|
||
override def getColumnType(schema: Seq[Column], ordinal: Int): Int = { | ||
schema(ordinal).sqlType match { | ||
// case for int, returns NUMERIC type in Oracle JDBC | ||
case Types.NUMERIC if schema(ordinal).scale == 0 => | ||
Types.INTEGER | ||
case Types.NUMERIC => | ||
Types.DECIMAL | ||
case _ => super.getColumnType(schema, ordinal) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.