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/26 13:03:36 UTC

[GitHub] [calcite] MalteBellmann commented on a change in pull request #2118: [CALCITE-2317] Support JDBC DatabaseMetaData.getFunctions

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