bchapuis commented on code in PR #2924:
URL: https://github.com/apache/calcite/pull/2924#discussion_r1040133298


##########
core/src/main/java/org/apache/calcite/runtime/SpatialTypeTableFunctions.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.calcite.runtime;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.AbstractQueryableTable;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.linq4j.AbstractEnumerable;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.QueryProvider;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.function.Deterministic;
+import org.apache.calcite.linq4j.function.Experimental;
+import org.apache.calcite.linq4j.function.Strict;
+import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.QueryableTable;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.Schema;
+import org.apache.calcite.schema.Schema.TableType;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.Statistic;
+import org.apache.calcite.schema.Statistics;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.type.SqlTypeName;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.locationtech.jts.geom.Geometry;
+
+import java.lang.reflect.Method;
+
+/**
+ * Helper methods to implement spatial type (ST) table functions.
+ */
+@Deterministic
+@Strict
+@Experimental
+public class SpatialTypeTableFunctions {
+
+  private SpatialTypeTableFunctions() {}
+
+  public static final Method EXPLODE =
+      Types.lookupMethod(SpatialTypeTableFunctions.class,
+          "explode", Geometry.class);
+
+  public static final Method EXPLODE_CURSOR =
+      Types.lookupMethod(SpatialTypeTableFunctions.class,
+          "explodeCursor", Enumerable.class);
+
+  public static ScannableTable explode(Geometry geometry) {
+    return new ScannableTable() {
+
+      @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+        return typeFactory.builder()
+            .add("geom", SqlTypeName.GEOMETRY)
+            .build();
+      }
+
+      @Override public Enumerable<@Nullable Object[]> scan(DataContext root) {
+        return new GeometryElements(geometry).select(g -> new Object[] {g});
+      }
+
+      @Override public Statistic getStatistic() {
+        return Statistics.UNKNOWN;
+      }
+
+      @Override public TableType getJdbcTableType() {
+        return Schema.TableType.TABLE;
+      }
+
+      @Override public boolean isRolledUp(String column) {
+        return false;
+      }
+
+      @Override public boolean rolledUpColumnValidInsideAgg(String column, 
SqlCall call,
+          @Nullable SqlNode parent, @Nullable CalciteConnectionConfig config) {
+        return true;
+      }
+    };
+  }
+
+  public static QueryableTable explodeCursor(final Enumerable<Object[]> a) {
+    return new AbstractQueryableTable(Object[].class) {
+      @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+        return typeFactory.builder()
+            .add("geom", SqlTypeName.GEOMETRY)
+            .build();
+      }
+
+      @Override public <T> Queryable<T> asQueryable(QueryProvider 
queryProvider,
+          SchemaPlus schema, String tableName) {
+        final Enumerable<Geometry> enumerable = a.selectMany(a0 -> {
+          final Geometry geometry = (Geometry) a0[0];
+          return new GeometryElements(geometry);
+        });
+        return (Queryable) enumerable.asQueryable();
+      }
+    };
+  }
+
+  /**

Review Comment:
   Thank you for the pointer on Linq4j, this has been fixed.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to