-
Notifications
You must be signed in to change notification settings - Fork 924
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
[KYUUBI #5509] Add Apache Impala JDBC engine dialect #6104
Changes from all commits
2c63a70
5ea3474
ecb0d7d
9852125
32ae6d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.util | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
|
||
import org.apache.kyuubi.KyuubiSQLException | ||
import org.apache.kyuubi.engine.jdbc.impala.{ImpalaSchemaHelper, ImpalaTRowSetGenerator} | ||
import org.apache.kyuubi.engine.jdbc.schema.{JdbcTRowSetGenerator, SchemaHelper} | ||
import org.apache.kyuubi.session.Session | ||
|
||
class ImpalaDialect extends JdbcDialect { | ||
|
||
override def getTablesQuery( | ||
catalog: String, | ||
schema: String, | ||
tableName: String, | ||
tableTypes: util.List[String]): String = { | ||
if (isPattern(schema)) { | ||
throw KyuubiSQLException.featureNotSupported("Pattern-like schema names not supported") | ||
} | ||
|
||
val query = new StringBuilder("show tables ") | ||
|
||
if (StringUtils.isNotEmpty(schema) && !isWildcardSetByKyuubi(schema)) { | ||
query.append(s"in $schema ") | ||
} | ||
|
||
if (StringUtils.isNotEmpty(tableName)) { | ||
query.append(s"like '${toImpalaRegex(tableName)}'") | ||
} | ||
|
||
query.toString() | ||
} | ||
|
||
override def getColumnsQuery( | ||
session: Session, | ||
catalogName: String, | ||
schemaName: String, | ||
tableName: String, | ||
columnName: String): String = { | ||
if (StringUtils.isEmpty(tableName)) { | ||
throw KyuubiSQLException("Table name should not be empty") | ||
} | ||
|
||
if (isPattern(schemaName)) { | ||
throw KyuubiSQLException.featureNotSupported("Pattern-like schema names not supported") | ||
} | ||
|
||
if (isPattern(tableName)) { | ||
throw KyuubiSQLException.featureNotSupported("Pattern-like table names not supported") | ||
} | ||
|
||
val query = new StringBuilder("show column stats ") | ||
|
||
if (StringUtils.isNotEmpty(schemaName) && !isWildcardSetByKyuubi(schemaName)) { | ||
query.append(s"$schemaName.") | ||
} | ||
|
||
query.append(tableName) | ||
query.toString() | ||
} | ||
|
||
override def getTRowSetGenerator(): JdbcTRowSetGenerator = new ImpalaTRowSetGenerator | ||
|
||
override def getSchemaHelper(): SchemaHelper = new ImpalaSchemaHelper | ||
|
||
override def name(): String = "impala" | ||
|
||
private def isPattern(value: String): Boolean = { | ||
value != null && !isWildcardSetByKyuubi(value) && value.contains("*") | ||
} | ||
|
||
private def isWildcardSetByKyuubi(pattern: String): Boolean = pattern == "%" | ||
|
||
private def toImpalaRegex(pattern: String): String = { | ||
pattern.replace("%", "*") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.impala | ||
|
||
import org.apache.kyuubi.engine.jdbc.connection.JdbcConnectionProvider | ||
|
||
class ImpalaConnectionProvider extends JdbcConnectionProvider { | ||
|
||
override val name: String = classOf[ImpalaConnectionProvider].getName | ||
|
||
override val driverClass: String = ImpalaConnectionProvider.driverClass | ||
} | ||
|
||
object ImpalaConnectionProvider { | ||
// we should use kyuubi hive driver instead of original hive one in order | ||
// to get fixed getMoreResults() | ||
val driverClass: String = "org.apache.kyuubi.jdbc.KyuubiHiveDriver" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.impala | ||
|
||
import org.apache.kyuubi.engine.jdbc.schema.SchemaHelper | ||
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.TTypeId | ||
|
||
class ImpalaSchemaHelper extends SchemaHelper { | ||
override protected def floatToTTypeId: TTypeId = { | ||
TTypeId.DOUBLE_TYPE | ||
} | ||
|
||
override protected def realToTTypeId: TTypeId = { | ||
TTypeId.DOUBLE_TYPE | ||
} | ||
} |
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.impala | ||
|
||
import org.apache.kyuubi.engine.jdbc.schema.DefaultJdbcTRowSetGenerator | ||
import org.apache.kyuubi.shaded.hive.service.rpc.thrift.{TColumn, TColumnValue} | ||
|
||
class ImpalaTRowSetGenerator extends DefaultJdbcTRowSetGenerator { | ||
override def toFloatTColumn(rows: Seq[Seq[_]], ordinal: Int): TColumn = | ||
asDoubleTColumn(rows, ordinal) | ||
|
||
override def toFloatTColumnValue(row: Seq[_], ordinal: Int): TColumnValue = | ||
asDoubleTColumnValue(row, ordinal) | ||
|
||
override def toRealTColumn(rows: Seq[Seq[_]], ordinal: Int): TColumn = | ||
asDoubleTColumn(rows, ordinal) | ||
|
||
override def toRealTColumnValue(row: Seq[_], ordinal: Int): TColumnValue = | ||
asDoubleTColumnValue(row, ordinal) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,12 @@ abstract class SchemaHelper { | |
case Types.DECIMAL => | ||
decimalToTTypeId | ||
|
||
case Types.FLOAT => | ||
floatToTTypeId | ||
|
||
case Types.BOOLEAN => | ||
booleanToTTypeId | ||
Comment on lines
+103
to
+107
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. this looks like affects(or not?) all dialects, if so, change it in a seperate PR first. 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. As far as I understand, other dialects don't use this types or use another JDBC types for the same types from db (for instance, 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. sgtm |
||
|
||
// TODO add more type support | ||
case _ => | ||
defaultToTTypeId | ||
|
@@ -109,6 +115,10 @@ abstract class SchemaHelper { | |
TTypeId.BOOLEAN_TYPE | ||
} | ||
|
||
protected def booleanToTTypeId: TTypeId = { | ||
TTypeId.BOOLEAN_TYPE | ||
} | ||
|
||
protected def tinyIntToTTypeId: TTypeId = { | ||
TTypeId.TINYINT_TYPE | ||
} | ||
|
@@ -129,6 +139,10 @@ abstract class SchemaHelper { | |
TTypeId.FLOAT_TYPE | ||
} | ||
|
||
protected def floatToTTypeId: TTypeId = { | ||
TTypeId.FLOAT_TYPE | ||
} | ||
|
||
protected def doubleToTTypeId: TTypeId = { | ||
TTypeId.DOUBLE_TYPE | ||
} | ||
|
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.
possible to add a nagetive test case for it? someday we may want to implement it.
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.
Added tests for such cases to
org.apache.kyuubi.engine.jdbc.impala.DialectSuite