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 2022/01/21 06:47:59 UTC

[GitHub] [calcite] Tartarus0zm opened a new pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Tartarus0zm opened a new pull request #2696:
URL: https://github.com/apache/calcite/pull/2696


   ## What is the purpose of the change
   Support hint for lateral table syntax
   
   ## Verifying this change
   * Add tests in `SqlHintsConverterTest` to validate the hint could be propagated to Correlate
   * Add tests in `RelToSqlConverterTest`


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] danny0405 commented on a change in pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#discussion_r800439312



##########
File path: core/src/main/codegen/templates/Parser.jj
##########
@@ -2173,10 +2176,23 @@ SqlNode TableRef2(boolean lateral) :
         <TABLE> { s = span(); } <LPAREN>
         tableRef = TableFunctionCall(s.pos())
         <RPAREN>
+        [
+            <HINT_BEG>
+            CommaSeparatedSqlHints(hints)
+            <COMMENT_END>
+        ]
         {
             if (lateral) {
-                tableRef = SqlStdOperatorTable.LATERAL.createCall(
-                    s.end(this), tableRef);
+                if (hints.size() > 0) {
+                    hintList = new SqlNodeList(hints, s.addAll(hints).end(this));
+                    SqlNode tmpTableRef = SqlStdOperatorTable.LATERAL.createCall(
+                                        s.end(this), tableRef);

Review comment:
       I feel it is more reasonable to include the `tableRef` into the `LATERAL` call not the other way around, say we should change the lateral call to support `tableRef` as the table reference, WDYT ?




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#issuecomment-1021987869


   @danny0405  I have updated the commit, please take a look


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] danny0405 commented on a change in pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
danny0405 commented on a change in pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#discussion_r790205396



##########
File path: core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
##########
@@ -2441,9 +2447,8 @@ private SqlNode registerFrom(
               null,
               forceRightNullable,
               lateral);
-      if (newRight != right) {
-        join.setRight(newRight);
-      }
+      // for check style.
+      swapJoinRightNode(join, right, newRight);

Review comment:
       Don't think this is a right change, you should make the `newRight` correct first.

##########
File path: core/src/main/java/org/apache/calcite/sql/SqlCorrelateTableRef.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;

Review comment:
       Can we just reuse `SqlTableRef` code ? We can switch the `tableName` to `tableRef` which is a `SqlNode`.

##########
File path: core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
##########
@@ -1225,7 +1226,7 @@ private SqlValidatorScope getScopeOrThrow(SqlNode node) {
     return getNamespace(id);
   }
 
-  @Override public @Nullable SqlValidatorNamespace getNamespace(SqlNode node) {
+  @Override public @Nullable SqlValidatorNamespace  getNamespace(SqlNode node) {
     switch (node.getKind()) {

Review comment:
       unnecessary change.

##########
File path: core/src/main/codegen/templates/Parser.jj
##########
@@ -2173,10 +2176,23 @@ SqlNode TableRef2(boolean lateral) :
         <TABLE> { s = span(); } <LPAREN>
         tableRef = TableFunctionCall(s.pos())
         <RPAREN>
+        [
+            <HINT_BEG>
+            CommaSeparatedSqlHints(hints)
+            <COMMENT_END>
+        ]
         {
             if (lateral) {
-                tableRef = SqlStdOperatorTable.LATERAL.createCall(
-                    s.end(this), tableRef);
+                if (hints.size() > 0) {
+                    hintList = new SqlNodeList(hints, s.addAll(hints).end(this));
+                    SqlNode tmpTableRef = SqlStdOperatorTable.LATERAL.createCall(
+                                        s.end(this), tableRef);

Review comment:
       `tmpTableRef ` => `lateralCall`

##########
File path: core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
##########
@@ -3001,12 +3009,20 @@ private void convertJoin(Blackboard bb, SqlJoin join) {
         throw Util.unexpected(conditionType);
       }
     }
+
+    final List<RelHint> hints;
+    if (right instanceof SqlCorrelateTableRef) {
+      hints = SqlUtil.getRelHint(hintStrategies, ((SqlCorrelateTableRef) right).operand(1));
+    } else {

Review comment:
       A way to avoid these `instanceOf` is add a new `SqlKind`.




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on a change in pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on a change in pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#discussion_r792401405



##########
File path: core/src/main/java/org/apache/calcite/sql/SqlCorrelateTableRef.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+import org.apache.calcite.sql.parser.SqlParserPos;
+
+import com.google.common.collect.ImmutableList;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.List;
+
+import static java.util.Objects.requireNonNull;

Review comment:
       good catch




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#issuecomment-1018228989


   @danny0405  please take a look, if you have time, thanks


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on a change in pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on a change in pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#discussion_r792401228



##########
File path: core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
##########
@@ -2441,9 +2447,8 @@ private SqlNode registerFrom(
               null,
               forceRightNullable,
               lateral);
-      if (newRight != right) {
-        join.setRight(newRight);
-      }
+      // for check style.
+      swapJoinRightNode(join, right, newRight);

Review comment:
       good catch




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on a change in pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on a change in pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#discussion_r804418141



##########
File path: core/src/main/codegen/templates/Parser.jj
##########
@@ -2173,10 +2176,23 @@ SqlNode TableRef2(boolean lateral) :
         <TABLE> { s = span(); } <LPAREN>
         tableRef = TableFunctionCall(s.pos())
         <RPAREN>
+        [
+            <HINT_BEG>
+            CommaSeparatedSqlHints(hints)
+            <COMMENT_END>
+        ]
         {
             if (lateral) {
-                tableRef = SqlStdOperatorTable.LATERAL.createCall(
-                    s.end(this), tableRef);
+                if (hints.size() > 0) {
+                    hintList = new SqlNodeList(hints, s.addAll(hints).end(this));
+                    SqlNode tmpTableRef = SqlStdOperatorTable.LATERAL.createCall(
+                                        s.end(this), tableRef);

Review comment:
       I've already changed it




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] Tartarus0zm commented on pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
Tartarus0zm commented on pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#issuecomment-1038603632


   @danny0405  I have updated the commit, please take a look, thanks


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] danny0405 edited a comment on pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
danny0405 edited a comment on pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#issuecomment-1072929150


   I can not find any vendor that supports hints for functions, let's be conservative here, does the query hints like
   
   ```java
   /*+ tvf_join('hash', 'table name') */
   ```
   
   works here ? You can add custom validations for the hint anyway.


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [calcite] danny0405 commented on pull request #2696: [CALCITE-4899] Support hint for lateral table syntax

Posted by GitBox <gi...@apache.org>.
danny0405 commented on pull request #2696:
URL: https://github.com/apache/calcite/pull/2696#issuecomment-1072929150


   I can not find any vendor that supports hints for functions, let's be conservative here, does the query hints like
   
   ```java
   /*+ tvf_join("hash", 'table name') */
   ```
   
   works here ? You can add custom validations for the hint anyway.


-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org