Skip to content

Commit 012fc75

Browse files
SteNicholaspan3793
authored andcommitted
[KYUUBI #1643][FOLLOWUP] Fix Flink GetFunctions result schema
<!-- 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. --> Implement GetFunctions operation. ### _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.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1773 from SteNicholas/KYUUBI-1643. Closes #1643 498c7f9 [SteNicholas] [KYUUBI #1643] Implement GetFunctions operation Authored-by: SteNicholas <programgeek@163.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 7ca1665 commit 012fc75

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

externals/kyuubi-flink-sql-engine/src/main/scala/org/apache/kyuubi/engine/flink/operation/GetFunctions.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.kyuubi.engine.flink.operation
1919

20+
import java.sql.DatabaseMetaData
21+
2022
import scala.collection.JavaConverters._
2123

2224
import org.apache.commons.lang3.StringUtils
@@ -45,22 +47,35 @@ class GetFunctions(
4547
val systemFunctions = filterPattern(
4648
tableEnv.listFunctions().diff(tableEnv.listUserDefinedFunctions()),
4749
functionPattern)
48-
.map { f => Row.of(null, null, f) }
50+
.map { f =>
51+
Row.of(null, null, f, null, Integer.valueOf(DatabaseMetaData.functionResultUnknown), null)
52+
}
4953
val catalogFunctions = tableEnv.listCatalogs()
5054
.filter { c => StringUtils.isEmpty(catalogName) || c == catalogName }
5155
.flatMap { c =>
5256
val catalog = tableEnv.getCatalog(c).get()
5357
filterPattern(catalog.listDatabases().asScala, schemaPattern)
5458
.flatMap { d =>
5559
filterPattern(catalog.listFunctions(d).asScala, functionPattern)
56-
.map { f => Row.of(c, d, f) }
60+
.map { f =>
61+
Row.of(
62+
c,
63+
d,
64+
f,
65+
null,
66+
Integer.valueOf(DatabaseMetaData.functionResultUnknown),
67+
null)
68+
}
5769
}
5870
}
5971
resultSet = ResultSet.builder.resultKind(ResultKind.SUCCESS_WITH_CONTENT)
6072
.columns(
6173
Column.physical(FUNCTION_CAT, DataTypes.STRING()),
6274
Column.physical(FUNCTION_SCHEM, DataTypes.STRING()),
63-
Column.physical(FUNCTION_NAME, DataTypes.STRING()))
75+
Column.physical(FUNCTION_NAME, DataTypes.STRING()),
76+
Column.physical(REMARKS, DataTypes.STRING()),
77+
Column.physical(FUNCTION_TYPE, DataTypes.INT()),
78+
Column.physical(SPECIFIC_NAME, DataTypes.STRING()))
6479
.data(systemFunctions ++: catalogFunctions)
6580
.build
6681
} catch {

externals/kyuubi-flink-sql-engine/src/test/scala/org/apache/kyuubi/engine/flink/operation/FlinkOperationSuite.scala

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.kyuubi.engine.flink.operation
1919

20+
import java.sql.DatabaseMetaData
21+
2022
import org.apache.flink.table.api.EnvironmentSettings.DEFAULT_BUILTIN_CATALOG
2123
import org.apache.flink.table.api.EnvironmentSettings.DEFAULT_BUILTIN_DATABASE
2224
import org.apache.flink.table.types.logical.LogicalTypeRoot
@@ -330,14 +332,14 @@ class FlinkOperationSuite extends WithFlinkSQLEngine with HiveJDBCTestHelper {
330332
val metaData = statement.getConnection.getMetaData
331333
var resultSet = metaData.getSchemas(null, null)
332334
while (resultSet.next()) {
333-
assert(resultSet.getString(TABLE_SCHEM) == DEFAULT_BUILTIN_DATABASE)
335+
assert(resultSet.getString(TABLE_SCHEM) === DEFAULT_BUILTIN_DATABASE)
334336
assert(resultSet.getString(TABLE_CATALOG) === DEFAULT_BUILTIN_CATALOG)
335337
}
336338
resultSet = metaData.getSchemas(
337339
DEFAULT_BUILTIN_CATALOG.split("_").apply(0),
338340
DEFAULT_BUILTIN_DATABASE.split("_").apply(0))
339341
while (resultSet.next()) {
340-
assert(resultSet.getString(TABLE_SCHEM) == DEFAULT_BUILTIN_DATABASE)
342+
assert(resultSet.getString(TABLE_SCHEM) === DEFAULT_BUILTIN_DATABASE)
341343
assert(resultSet.getString(TABLE_CATALOG) === DEFAULT_BUILTIN_CATALOG)
342344
}
343345
}
@@ -412,26 +414,28 @@ class FlinkOperationSuite extends WithFlinkSQLEngine with HiveJDBCTestHelper {
412414
val metaData = statement.getConnection.getMetaData
413415
Seq("currentTimestamp", "currentDate", "currentTime", "localTimestamp", "localTime")
414416
.foreach { func =>
415-
Seq(metaData.getFunctions _).foreach { apiFunc =>
416-
val resultSet = apiFunc(null, null, func)
417-
while (resultSet.next()) {
418-
assert(resultSet.getString(FUNCTION_CAT) == null)
419-
assert(resultSet.getString(FUNCTION_SCHEM) === null)
420-
assert(resultSet.getString(FUNCTION_NAME) === func)
421-
}
417+
val resultSet = metaData.getFunctions(null, null, func)
418+
while (resultSet.next()) {
419+
assert(resultSet.getString(FUNCTION_CAT) === null)
420+
assert(resultSet.getString(FUNCTION_SCHEM) === null)
421+
assert(resultSet.getString(FUNCTION_NAME) === func)
422+
assert(resultSet.getString(REMARKS) === null)
423+
assert(resultSet.getInt(FUNCTION_TYPE) === DatabaseMetaData.functionResultUnknown)
424+
assert(resultSet.getString(SPECIFIC_NAME) === null)
422425
}
423426
}
424427
val expected =
425428
List("currentTimestamp", "currentDate", "currentTime", "localTimestamp", "localTime")
426429
Seq("current", "local")
427430
.foreach { funcPattern =>
428-
Seq(metaData.getFunctions _).foreach { apiFunc =>
429-
val resultSet = apiFunc(null, null, funcPattern)
430-
while (resultSet.next()) {
431-
assert(resultSet.getString(FUNCTION_CAT) == null)
432-
assert(resultSet.getString(FUNCTION_SCHEM) === null)
433-
assert(expected.contains(resultSet.getString(FUNCTION_NAME)))
434-
}
431+
val resultSet = metaData.getFunctions(null, null, funcPattern)
432+
while (resultSet.next()) {
433+
assert(resultSet.getString(FUNCTION_CAT) === null)
434+
assert(resultSet.getString(FUNCTION_SCHEM) === null)
435+
assert(expected.contains(resultSet.getString(FUNCTION_NAME)))
436+
assert(resultSet.getString(REMARKS) === null)
437+
assert(resultSet.getString(FUNCTION_TYPE) === DatabaseMetaData.functionResultUnknown)
438+
assert(resultSet.getString(SPECIFIC_NAME) === null)
435439
}
436440
}
437441
}

0 commit comments

Comments
 (0)