You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/08/23 12:06:42 UTC
[GitHub] [calcite] MalteBellmann opened a new pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
MalteBellmann opened a new pull request #2118:
URL: https://github.com/apache/calcite/pull/2118
DatabaseMetaData.getFunctions() on a connection to Calcite now returns UDFs.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] chunweilei commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
chunweilei commented on a change in pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#discussion_r477023388
##########
File path: core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
##########
@@ -492,6 +493,48 @@ public MetaResultSet getTableTypes(ConnectionHandle ch) {
"TABLE_TYPE");
}
+ public MetaResultSet getFunctions(ConnectionHandle ch,
+ String catalog,
+ Pat schemaPattern,
+ Pat functionNamePattern) {
+ final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
+ return createResultSet(schemas(catalog)
+ .where(schemaMatcher)
+ .selectMany(schema -> functions(schema, catalog, matcher(functionNamePattern))),
+ MetaFunction.class,
+ "FUNCTION_CAT",
+ "FUNCTION_SCHEM",
+ "FUNCTION_NAME",
+ "REMARKS",
+ "FUNCTION_TYPE",
+ "SPECIFIC_NAME");
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalog) {
+ final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
+ return Linq4j.asEnumerable(schema.calciteSchema.getFunctionNames())
+ .selectMany(name ->
+ Linq4j.asEnumerable(schema.calciteSchema.getFunctions(name, true))
+ //exclude materialized views from the result set
+ .where(fn -> !(fn instanceof MaterializedViewTable.MaterializedViewTableMacro))
+ .select(fnx ->
+ new MetaFunction(
+ catalog,
+ schema.getName(),
+ name,
+ (short) DatabaseMetaData.functionResultUnknown,
+ name
+ )
+ )
+ );
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema, final String catalog,
+ final Predicate1<String> functionNameMatcher) {
+ return functions(schema, catalog)
Review comment:
Is it possible to add some tests?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] amaliujia commented on pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
amaliujia commented on pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#issuecomment-794830210
Merged via https://github.com/apache/calcite/commit/e447ff85a0a7d2037b819b7ced91177261974c7e
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] MalteBellmann commented on pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
MalteBellmann commented on pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#issuecomment-785216694
@chunweilei do you have time to review this updated PR? I think it is ready to merge
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] amaliujia commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
amaliujia commented on a change in pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#discussion_r589634229
##########
File path: core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
##########
@@ -502,6 +507,70 @@ CalciteConnectionImpl getConnection() {
"TABLE_TYPE");
}
+ @Override public MetaResultSet getFunctions(ConnectionHandle ch,
+ String catalog,
+ Pat schemaPattern,
+ Pat functionNamePattern) {
+ final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
+ return createResultSet(schemas(catalog)
+ .where(schemaMatcher)
+ .selectMany(schema -> functions(schema, catalog, matcher(functionNamePattern)))
+ .orderBy(x ->
+ (Comparable) FlatLists.of(
+ x.functionCat, x.functionSchem, x.functionName, x.specificName
+ )),
+ MetaFunction.class,
+ "FUNCTION_CAT",
+ "FUNCTION_SCHEM",
+ "FUNCTION_NAME",
+ "REMARKS",
+ "FUNCTION_TYPE",
+ "SPECIFIC_NAME");
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalog) {
+ final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
+ Enumerable<MetaFunction> opTableFunctions = Linq4j.emptyEnumerable();
+ if (schema.getName().equals("metadata")) {
Review comment:
Out of curiosity: why hardcode `metadata` as schema name?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] MalteBellmann commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
MalteBellmann commented on a change in pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#discussion_r589651624
##########
File path: core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
##########
@@ -502,6 +507,70 @@ CalciteConnectionImpl getConnection() {
"TABLE_TYPE");
}
+ @Override public MetaResultSet getFunctions(ConnectionHandle ch,
+ String catalog,
+ Pat schemaPattern,
+ Pat functionNamePattern) {
+ final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
+ return createResultSet(schemas(catalog)
+ .where(schemaMatcher)
+ .selectMany(schema -> functions(schema, catalog, matcher(functionNamePattern)))
+ .orderBy(x ->
+ (Comparable) FlatLists.of(
+ x.functionCat, x.functionSchem, x.functionName, x.specificName
+ )),
+ MetaFunction.class,
+ "FUNCTION_CAT",
+ "FUNCTION_SCHEM",
+ "FUNCTION_NAME",
+ "REMARKS",
+ "FUNCTION_TYPE",
+ "SPECIFIC_NAME");
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalog) {
+ final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
+ Enumerable<MetaFunction> opTableFunctions = Linq4j.emptyEnumerable();
+ if (schema.getName().equals("metadata")) {
Review comment:
The idea was: It is hardcoded in https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/jdbc/CalciteSchema.java#L525-L527 and I didn't see a better way.
But I just realized, I can use `MetadataSchema.INSTANCE` for the check. I will update the PR accordingly
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] amaliujia closed pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
amaliujia closed pull request #2118:
URL: https://github.com/apache/calcite/pull/2118
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] MalteBellmann commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
MalteBellmann commented on a change in pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#discussion_r477282840
##########
File path: core/src/main/java/org/apache/calcite/jdbc/CalciteMetaImpl.java
##########
@@ -492,6 +493,48 @@ public MetaResultSet getTableTypes(ConnectionHandle ch) {
"TABLE_TYPE");
}
+ public MetaResultSet getFunctions(ConnectionHandle ch,
+ String catalog,
+ Pat schemaPattern,
+ Pat functionNamePattern) {
+ final Predicate1<MetaSchema> schemaMatcher = namedMatcher(schemaPattern);
+ return createResultSet(schemas(catalog)
+ .where(schemaMatcher)
+ .selectMany(schema -> functions(schema, catalog, matcher(functionNamePattern))),
+ MetaFunction.class,
+ "FUNCTION_CAT",
+ "FUNCTION_SCHEM",
+ "FUNCTION_NAME",
+ "REMARKS",
+ "FUNCTION_TYPE",
+ "SPECIFIC_NAME");
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema_, final String catalog) {
+ final CalciteMetaSchema schema = (CalciteMetaSchema) schema_;
+ return Linq4j.asEnumerable(schema.calciteSchema.getFunctionNames())
+ .selectMany(name ->
+ Linq4j.asEnumerable(schema.calciteSchema.getFunctions(name, true))
+ //exclude materialized views from the result set
+ .where(fn -> !(fn instanceof MaterializedViewTable.MaterializedViewTableMacro))
+ .select(fnx ->
+ new MetaFunction(
+ catalog,
+ schema.getName(),
+ name,
+ (short) DatabaseMetaData.functionResultUnknown,
+ name
+ )
+ )
+ );
+ }
+
+ Enumerable<MetaFunction> functions(final MetaSchema schema, final String catalog,
+ final Predicate1<String> functionNameMatcher) {
+ return functions(schema, catalog)
Review comment:
Thanks for reviewing, i've added a test and sorting according to the JDBC specification.
FYI, there is also a discussion in JIRA on how to handle built-in functions.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] xy2953396112 commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
xy2953396112 commented on a change in pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#discussion_r589961429
##########
File path: core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
##########
@@ -760,6 +761,47 @@
});
}
+ @Test void testMetadataFunctions() {
+ final String model = ""
+ + "{\n"
+ + " version: '1.0',\n"
+ + " schemas: [\n"
+ + " {\n"
+ + " name: 'adhoc',\n"
+ + " functions: [\n"
+ + " {\n"
+ + " name: 'MY_STR',\n"
+ + " className: '" + Smalls.MyToStringFunction.class.getName() + "'\n"
+ + " },\n"
+ + " {\n"
+ + " name: 'FIBONACCI_TABLE',\n"
+ + " className: '" + Smalls.class.getName() + "',\n"
+ + " methodName: 'fibonacciTable'\n"
+ + " }\n"
+ + " ],\n"
+ + " materializations: [\n"
+ + " {\n"
+ + " table: 'TEST_VIEW',\n"
+ + " sql: 'SELECT 1'\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " ]\n"
+ + "}";
+ CalciteAssert.model(model)
+ .withDefaultSchema("adhoc")
Review comment:
LGTM
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [calcite] amaliujia commented on pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions
Posted by GitBox <gi...@apache.org>.
amaliujia commented on pull request #2118:
URL: https://github.com/apache/calcite/pull/2118#issuecomment-792956149
Overall makes sense to me
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org