tkalkirill commented on code in PR #5300:
URL: https://github.com/apache/calcite/pull/5300#discussion_r4515470586


##########
core/src/main/java/org/apache/calcite/runtime/CursorInputs.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * 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.avatica.AvaticaResultSet;
+import org.apache.calcite.avatica.AvaticaResultSetMetaData;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.Meta;
+import org.apache.calcite.linq4j.AbstractEnumerable;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.util.CursorInput;
+import org.apache.calcite.util.Util;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+import java.util.TimeZone;
+
+import static java.util.Objects.requireNonNull;
+
+/** Utilities for working with {@link CursorInput}. */
+public final class CursorInputs {
+  private CursorInputs() {
+  }
+
+  public static CursorInput of(RelDataType rowType, Enumerable<Object[]> rows) 
{
+    return new CursorInput() {
+      @Override public RelDataType getRowType() {
+        return rowType;
+      }
+
+      @Override public Enumerable<Object[]> rows() {
+        return rows;
+      }
+    };
+  }
+
+  public static ResultSet metadataOnly(List<ColumnMetaData> columns) {
+    return resultSet(new AbstractEnumerable<Object[]>() {
+      @Override public Enumerator<Object[]> enumerator() {
+        throw new UnsupportedOperationException(
+            "Cursor rows are unavailable during type inference");

Review Comment:
   I’d keep the exception here. During type inference, Calcite has the cursor’s 
column metadata, but the query hasn’t run. Returning false from next() could 
cause a function to infer its output schema from an input it assumes is empty. 
getMetaData() works without calling next(), and the function can read rows when 
the returned table is scanned.



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