gianm commented on code in PR #5349:
URL: https://github.com/apache/calcite/pull/5349#discussion_r4406889108


##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.

Review Comment:
   I got it from similar wording in `SelectNamespace`. However most of the 
other impls seem to use "Namespace for" so I changed it to that.



##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.
+ *
+ * <p>The query is validated through its surrogate SELECT; see

Review Comment:
   Moved it to `SqlPipeQuery#surrogateSelect`.



##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.
+ *
+ * <p>The query is validated through its surrogate SELECT; see
+ * {@link SqlPipeOperator#surrogateSelect()}.
+ */
+public class PipeNamespace extends AbstractNamespace {
+  private final SqlNode node;
+  /** This operator's surrogate SELECT. */
+  private final SqlSelect select;

Review Comment:
   Done.



##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.
+ *
+ * <p>The query is validated through its surrogate SELECT; see
+ * {@link SqlPipeOperator#surrogateSelect()}.
+ */
+public class PipeNamespace extends AbstractNamespace {
+  private final SqlNode node;
+  /** This operator's surrogate SELECT. */
+  private final SqlSelect select;
+  /** Scope that the query is written in, and that its input and surrogate

Review Comment:
   I tried to improve it:
   
   ```
     /** Scope that encloses the pipeline. */
     private final SqlValidatorScope scope;
   ```



##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.
+ *
+ * <p>The query is validated through its surrogate SELECT; see
+ * {@link SqlPipeOperator#surrogateSelect()}.
+ */
+public class PipeNamespace extends AbstractNamespace {
+  private final SqlNode node;
+  /** This operator's surrogate SELECT. */
+  private final SqlSelect select;
+  /** Scope that the query is written in, and that its input and surrogate
+   * are validated in. */
+  private final SqlValidatorScope scope;
+
+  /** Scope children that an operator applied to this one can see. Computed
+   * on demand, once this namespace has been validated. */
+  private @Nullable List<ScopeChild> outChildren;
+
+  //~ Constructors -----------------------------------------------------------
+
+  PipeNamespace(SqlValidatorImpl validator, SqlNode node,
+      SqlSelect select, SqlValidatorScope scope,
+      SqlNode enclosingNode) {
+    super(validator, enclosingNode);
+    this.node = node;

Review Comment:
   Only `SqlPipeQuery` is legal. I narrowed the type on the constructor.



##########
core/src/main/java/org/apache/calcite/sql/validate/PipeNamespace.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.sql.validate;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlPipeOperator;
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.SqlUtil;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * Namespace offered by a query written in SQL pipe syntax.
+ *
+ * <p>The query is validated through its surrogate SELECT; see
+ * {@link SqlPipeOperator#surrogateSelect()}.
+ */
+public class PipeNamespace extends AbstractNamespace {
+  private final SqlNode node;
+  /** This operator's surrogate SELECT. */
+  private final SqlSelect select;
+  /** Scope that the query is written in, and that its input and surrogate
+   * are validated in. */
+  private final SqlValidatorScope scope;
+
+  /** Scope children that an operator applied to this one can see. Computed
+   * on demand, once this namespace has been validated. */
+  private @Nullable List<ScopeChild> outChildren;
+
+  //~ Constructors -----------------------------------------------------------
+
+  PipeNamespace(SqlValidatorImpl validator, SqlNode node,
+      SqlSelect select, SqlValidatorScope scope,
+      SqlNode enclosingNode) {
+    super(validator, enclosingNode);
+    this.node = node;
+    this.select = select;
+    this.scope = scope;
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  @Override public SqlNode getNode() {
+    return node;
+  }
+
+  /** Returns this operator's surrogate SELECT. */
+  public SqlSelect getSelect() {
+    return select;
+  }
+
+  @Override protected RelDataType validateImpl(RelDataType targetRowType) {
+    if (node instanceof SqlPipeOperator) {
+      // Validate the input first, so its tables can take the placeholder's

Review Comment:
   The purpose of this block here (inside `node instanceof SqlPipeOperator`) is 
to make it so `emp.deptno` can be correctly resolved for SQL like `FROM emp |> 
WHERE emp.deptno = 10`. I changed this comment to try to be clearer about what 
is going on:
   
   ```
         // Scopes are built during registration, but which of the input's
         // tables this operator can see (and so which aliases resolve) is known
         // only once the input is validated. Replace the scope's children here
         // so this operator's expressions see the correct table aliases.
   ```



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