You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/03/31 22:57:44 UTC

[GitHub] [druid] jihoonson opened a new pull request #11058: Add a planner rule to handle empty tables

jihoonson opened a new pull request #11058:
URL: https://github.com/apache/druid/pull/11058


   ### Description
   
   This PR adds a new planner rule, `DruidLogicalValuesRule`, that can interpret logical tuples into `InlineDataSource`. This can be useful when you have a query that Calcite can reduce empty tables into empty tuples. For example, given a query of `SELECT * FROM table WHERE 1 = 0`, Calcite can reduce this query to `SELECT * FROM empty_tuples`.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `DruidLogicalValuesRule`
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #11058: Add a planner rule to handle empty tables

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #11058:
URL: https://github.com/apache/druid/pull/11058#discussion_r608074271



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRule.java
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.druid.sql.calcite.rule;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.query.InlineDataSource;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.sql.calcite.planner.Calcites;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+import org.apache.druid.sql.calcite.rel.DruidQueryRel;
+import org.apache.druid.sql.calcite.rel.QueryMaker;
+import org.apache.druid.sql.calcite.table.DruidTable;
+import org.apache.druid.sql.calcite.table.RowSignatures;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DruidLogicalValuesRule extends RelOptRule

Review comment:
       I agree javadoc would be nice to have. Added some.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #11058: Add a planner rule to handle empty tables

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #11058:
URL: https://github.com/apache/druid/pull/11058#discussion_r608083691



##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -174,7 +180,28 @@ public void testSelectNonNumericNumberLiterals() throws Exception
         + " CAST(-1 / 0.0 AS BIGINT),"
         + " CAST(-1 / -0.0 AS BIGINT),"
         + " CAST(0/ 0.0 AS BIGINT)",
-        ImmutableList.of(),
+        ImmutableList.of(

Review comment:
       Good point. I added a section for the release note.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] clintropolis commented on a change in pull request #11058: Add a planner rule to handle empty tables

Posted by GitBox <gi...@apache.org>.
clintropolis commented on a change in pull request #11058:
URL: https://github.com/apache/druid/pull/11058#discussion_r607419873



##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -174,7 +180,28 @@ public void testSelectNonNumericNumberLiterals() throws Exception
         + " CAST(-1 / 0.0 AS BIGINT),"
         + " CAST(-1 / -0.0 AS BIGINT),"
         + " CAST(0/ 0.0 AS BIGINT)",
-        ImmutableList.of(),
+        ImmutableList.of(

Review comment:
       I think we should call out in the release notes about this behavior change just in case, where using Druid like a calculator is going to do scans with an inline datasource now instead of going down the bindable path (which i think is an improvement, makes things more visible and we want to drop the bindable path at some point in the future)

##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRule.java
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.druid.sql.calcite.rule;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.query.InlineDataSource;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.sql.calcite.planner.Calcites;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+import org.apache.druid.sql.calcite.rel.DruidQueryRel;
+import org.apache.druid.sql.calcite.rel.QueryMaker;
+import org.apache.druid.sql.calcite.table.DruidTable;
+import org.apache.druid.sql.calcite.table.RowSignatures;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DruidLogicalValuesRule extends RelOptRule

Review comment:
       nit: javadoc might be nice, something about translating queries on literals to inline datasource, but i don't feel too strongly about it since many of our RelOptRule implementations are missing 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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] jihoonson commented on a change in pull request #11058: Add a planner rule to handle empty tables

Posted by GitBox <gi...@apache.org>.
jihoonson commented on a change in pull request #11058:
URL: https://github.com/apache/druid/pull/11058#discussion_r608083691



##########
File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java
##########
@@ -174,7 +180,28 @@ public void testSelectNonNumericNumberLiterals() throws Exception
         + " CAST(-1 / 0.0 AS BIGINT),"
         + " CAST(-1 / -0.0 AS BIGINT),"
         + " CAST(0/ 0.0 AS BIGINT)",
-        ImmutableList.of(),
+        ImmutableList.of(

Review comment:
       Good point. I added a section for the release note in the PR description.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] suneet-s merged pull request #11058: Add a planner rule to handle empty tables

Posted by GitBox <gi...@apache.org>.
suneet-s merged pull request #11058:
URL: https://github.com/apache/druid/pull/11058


   


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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org