-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Apache Impala JDBC engine dialect
- Loading branch information
1 parent
d516a5d
commit 57d56d0
Showing
29 changed files
with
946 additions
and
21 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
91 changes: 91 additions & 0 deletions
91
...uubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/dialect/ImpalaDialect.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,91 @@ | ||
/* | ||
* 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 (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("%", "*") | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...engine/src/main/scala/org/apache/kyuubi/engine/jdbc/impala/ImpalaConnectionProvider.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,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" | ||
} |
30 changes: 30 additions & 0 deletions
30
...-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/impala/ImpalaSchemaHelper.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,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 | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...c-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/impala/ImpalaTRowSetGenerator.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.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) | ||
} |
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
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
Oops, something went wrong.