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 2019/12/05 00:16:59 UTC

[GitHub] [calcite] asereda-gs commented on a change in pull request #1626: [CALCITE-3561] Support using unnest in Interpreter

asereda-gs commented on a change in pull request #1626: [CALCITE-3561] Support using unnest in Interpreter
URL: https://github.com/apache/calcite/pull/1626#discussion_r354053829
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/interpreter/UncollectNode.java
 ##########
 @@ -0,0 +1,65 @@
+/*
+ * 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.interpreter;
+
+import org.apache.calcite.rel.core.Uncollect;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Interpreter node that implements a
+ * {@link org.apache.calcite.rel.core.Uncollect}.
+ */
+public class UncollectNode extends AbstractSingleNode<Uncollect> {
+
+  public UncollectNode(Compiler compiler, Uncollect uncollect) {
+    super(compiler, uncollect);
+  }
+
+  @Override public void run() throws InterruptedException {
+    Row row = null;
+    while ((row = source.receive()) != null) {
+      for (Object value: row.getValues()) {
+        int i = 1;
+        if (value instanceof List) {
+          List list = (List) value;
+          for (Object o : list) {
+            if (rel.withOrdinality) {
+              sink.send(Row.of(o, i++));
+            } else {
+              sink.send(Row.of(o));
+            }
+          }
+        } else if (value instanceof Map) {
+          Map map = (Map) value;
+          for (Object key : map.keySet()) {
+            if (rel.withOrdinality) {
+              sink.send(Row.of(key, map.get(key), i++));
+            } else {
+              sink.send(Row.of(key, map.get(key)));
+            }
+          }
+        } else {
+          throw new UnsupportedOperationException("Invalid type for unnest.");
 
 Review comment:
   Can you include the type of `value` in the error message so it easier to debug ? 

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


With regards,
Apache Git Services