Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #1906] Add GetColumns for trino engine
<!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html 2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'. 3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'. --> ### _Why are the changes needed?_ <!-- Please clarify why the changes are needed. For instance, 1. If you add a feature, you can talk about the use case of it. 2. If you fix a bug, you can clarify why it is a bug. --> Add GetColumns for trino engine. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1922 from SteNicholas/KYUUBI-1906. Closes #1906 e7ff09b [SteNicholas] [KYUUBI #1906] Add GetColumns for trino engine Authored-by: SteNicholas <programgeek@163.com> Signed-off-by: Kent Yao <yao@apache.org>
- Loading branch information
1 parent
2501f9a
commit 9bcd08f
Showing
3 changed files
with
230 additions
and
34 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...ubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetColumns.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,77 @@ | ||
/* | ||
* 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.trino.operation | ||
|
||
import scala.collection.mutable.ArrayBuffer | ||
|
||
import org.apache.commons.lang3.StringUtils | ||
|
||
import org.apache.kyuubi.engine.trino.TrinoStatement | ||
import org.apache.kyuubi.operation.{IterableFetchIterator, OperationType} | ||
import org.apache.kyuubi.operation.meta.ResultSetSchemaConstant.{COLUMN_NAME, TABLE_CAT, TABLE_NAME, TABLE_SCHEM} | ||
import org.apache.kyuubi.session.Session | ||
|
||
class GetColumns( | ||
session: Session, | ||
catalogName: String, | ||
schemaName: String, | ||
tableName: String, | ||
columnName: String) | ||
extends TrinoOperation(OperationType.GET_COLUMNS, session) { | ||
|
||
private val SEARCH_STRING_ESCAPE: String = "\\" | ||
|
||
override protected def runInternal(): Unit = { | ||
val query = new StringBuilder( | ||
""" | ||
|SELECT TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE, | ||
|TYPE_NAME, COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX, | ||
|NULLABLE, REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB, | ||
|CHAR_OCTET_LENGTH, ORDINAL_POSITION, IS_NULLABLE, SCOPE_CATALOG, | ||
|SCOPE_SCHEMA, SCOPE_TABLE, SOURCE_DATA_TYPE | ||
|FROM system.jdbc.columns | ||
|""".stripMargin) | ||
|
||
val filters = ArrayBuffer[String]() | ||
if (StringUtils.isNotEmpty(catalogName)) { | ||
filters += s"$TABLE_CAT = '$catalogName'" | ||
} | ||
if (StringUtils.isNotEmpty(schemaName)) { | ||
filters += s"$TABLE_SCHEM LIKE '$schemaName' ESCAPE '$SEARCH_STRING_ESCAPE'" | ||
} | ||
if (StringUtils.isNotEmpty(tableName)) { | ||
filters += s"$TABLE_NAME LIKE '$tableName' ESCAPE '$SEARCH_STRING_ESCAPE'" | ||
} | ||
if (StringUtils.isNotEmpty(columnName)) { | ||
filters += s"$COLUMN_NAME LIKE '$columnName' ESCAPE '$SEARCH_STRING_ESCAPE'" | ||
} | ||
|
||
if (filters.nonEmpty) { | ||
query.append(" WHERE ") | ||
query.append(filters.mkString(" AND ")) | ||
} | ||
|
||
try { | ||
val trinoStatement = | ||
TrinoStatement(trinoContext, session.sessionManager.getConf, query.toString) | ||
schema = trinoStatement.getColumns | ||
val resultSet = trinoStatement.execute() | ||
iter = new IterableFetchIterator(resultSet) | ||
} catch onError() | ||
} | ||
} |
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