-
Notifications
You must be signed in to change notification settings - Fork 0
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 apache#4320] Support GetPrimaryKeys for Trino Fe #12
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -97,6 +97,12 @@ SCOPE_TABLE: 'SCOPE_TABLE'; | |
SOURCE_DATA_TYPE: 'SOURCE_DATA_TYPE'; | ||
IS_AUTOINCREMENT: 'IS_AUTOINCREMENT'; | ||
IS_GENERATEDCOLUMN: 'IS_GENERATEDCOLUMN'; | ||
VARCHAR: 'VARCHAR'; | ||
SMALLINT: 'SMALLINT'; | ||
CAST: 'CAST'; | ||
AS: 'AS'; | ||
KEY_SEQ: 'KEY_SEQ'; | ||
PK_NAME: 'PK_NAME'; | ||
|
||
fragment SEARCH_STRING_ESCAPE: '\'' '\\' '\''; | ||
|
||
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. 这段代码看起来只是添加了一些常量,并没有直接运行的代码。因此无法确定是否存在bug风险。但是,以下是一些建议:
另外,你可以在将来的代码提交中提供更多上下文信息,以便提供更全面的反馈。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,13 @@ statement | |
SOURCE_DATA_TYPE COMMA IS_AUTOINCREMENT COMMA IS_GENERATEDCOLUMN FROM SYSTEM_JDBC_COLUMNS | ||
(WHERE tableCatalogFilter? AND? tableSchemaFilter? AND? tableNameFilter? AND? colNameFilter?)? | ||
ORDER BY TABLE_CAT COMMA TABLE_SCHEM COMMA TABLE_NAME COMMA ORDINAL_POSITION #getColumns | ||
| SELECT CAST LEFT_PAREN NULL AS VARCHAR RIGHT_PAREN TABLE_CAT COMMA | ||
CAST LEFT_PAREN NULL AS VARCHAR RIGHT_PAREN TABLE_SCHEM COMMA | ||
CAST LEFT_PAREN NULL AS VARCHAR RIGHT_PAREN TABLE_NAME COMMA | ||
CAST LEFT_PAREN NULL AS VARCHAR RIGHT_PAREN COLUMN_NAME COMMA | ||
CAST LEFT_PAREN NULL AS SMALLINT RIGHT_PAREN KEY_SEQ COMMA | ||
CAST LEFT_PAREN NULL AS VARCHAR RIGHT_PAREN PK_NAME | ||
WHERE FALSE #getPrimaryKeys | ||
| .*? #passThrough | ||
; | ||
|
||
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. 这段代码是一个正则表达式,可以用来匹配 SQL 语句的字符串。其中第一部分会从 SYSTEM_JDBC_COLUMNS 表中选择特定的列,并根据过滤器(tableCatalogFilter、tableSchemaFilter、tableNameFilter、colNameFilter)进行查询。第二部分则是从任何字符串中捕获所有字符。 根据这个补丁的内容,可以看出作者在数据库的获取和操作上进行了优化,新增了查询主键的功能。同时这个代码片段看上去没有明显的错误,但是如果整块代码给出会更容易进行完整的 review。 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import org.apache.kyuubi.operation.OperationHandle | |
import org.apache.kyuubi.service.BackendService | ||
import org.apache.kyuubi.sql.parser.trino.KyuubiTrinoFeParser | ||
import org.apache.kyuubi.sql.plan.PassThroughNode | ||
import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetColumns, GetSchemas, GetTables, GetTableTypes, GetTypeInfo} | ||
import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetColumns, GetPrimaryKeys, GetSchemas, GetTables, GetTableTypes, GetTypeInfo} | ||
|
||
class KyuubiTrinoOperationTranslator(backendService: BackendService) { | ||
lazy val parser = new KyuubiTrinoFeParser() | ||
|
@@ -68,6 +68,11 @@ class KyuubiTrinoOperationTranslator(backendService: BackendService) { | |
schemaPattern, | ||
tableNamePattern, | ||
colNamePattern) | ||
case GetPrimaryKeys() => | ||
val operationHandle = backendService.getPrimaryKeys(sessionHandle, null, null, null) | ||
// The trino implementation always returns empty. | ||
operationHandle.setHasResultSet(false) | ||
operationHandle | ||
case PassThroughNode() => | ||
backendService.executeStatement(sessionHandle, statement, configs, runAsync, queryTimeout) | ||
} | ||
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. 这段代码的变化是将原来操作Plan中将
希望我的答复可以帮到您! |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import org.apache.kyuubi.sql.KyuubiTrinoFeBaseParser._ | |
import org.apache.kyuubi.sql.KyuubiTrinoFeBaseParserBaseVisitor | ||
import org.apache.kyuubi.sql.parser.KyuubiParser.unescapeSQLString | ||
import org.apache.kyuubi.sql.plan.{KyuubiTreeNode, PassThroughNode} | ||
import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetColumns, GetSchemas, GetTables, GetTableTypes, GetTypeInfo} | ||
import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetColumns, GetPrimaryKeys, GetSchemas, GetTables, GetTableTypes, GetTypeInfo} | ||
|
||
class KyuubiTrinoFeAstBuilder extends KyuubiTrinoFeBaseParserBaseVisitor[AnyRef] { | ||
|
||
|
@@ -92,6 +92,10 @@ class KyuubiTrinoFeAstBuilder extends KyuubiTrinoFeBaseParserBaseVisitor[AnyRef] | |
GetColumns(catalog, schemaPattern, tableNamePattern, colNamePattern) | ||
} | ||
|
||
override def visitGetPrimaryKeys(ctx: GetPrimaryKeysContext): KyuubiTreeNode = { | ||
GetPrimaryKeys() | ||
} | ||
|
||
override def visitNullCatalog(ctx: NullCatalogContext): AnyRef = { | ||
null | ||
} | ||
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. 这段代码看起来是在引入一些Trino SQL查询计划的类,并重新实现了
希望我的建议能对你有所帮助! |
||
|
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.
这个代码补丁主要引入了一个新的依赖 - org.apache.commons.lang3.StringUtils,并对一些变量和方法进行了修改。
在方法 extractURLComponents 中,现在使用的是 Pattern 类编译的正则表达式,其中 confPattern 对象的定义被移动到了方法内部,并修改了 while 循环将结果存储到 Map 对象中。同时,还增加了一些新的检查,以避免错误或意外的输入数据。
在 isKyuubiOperationHint 方法中,现在使用的是一个匹配器对象,对 KYUUBI_OPERATION_HINT_PATTERN 进行了预编译,以提高性能。此外,该方法没有任何更改。
put 语句中的 Map 对象如果接收 null 值会导致 NullPointerException 错误。建议在向 Map 中添加之前创建它,每次都判断一下异常情况。
总的来说,这个补丁采取了良好的编码风格和技术实践。虽然可能仍存在一些潜在的错误或忽略的边界情况,但这是必要的优化和重构。