You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by weijietong <gi...@git.apache.org> on 2017/07/27 12:43:59 UTC
[GitHub] drill pull request #889: Drill 5691 enhance scalar sub queries checking for ...
GitHub user weijietong opened a pull request:
https://github.com/apache/drill/pull/889
Drill 5691 enhance scalar sub queries checking for the cartesian join
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/weijietong/drill drill-5691
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/drill/pull/889.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #889
----
commit b44f780a948c4a0898e7cee042c0590f0713f780
Author: weijietong <to...@gmail.com>
Date: 2017-06-08T08:03:46Z
Merge pull request #1 from apache/master
sync
commit b5d13847320120db4e5cd8371af3d03399fac7a8
Author: weijie.tong <we...@alipay.com>
Date: 2017-07-27T12:37:34Z
fix drill-5691
commit 940f6a2a3eb33d1f30c14a0a9c38a19f1f6195cf
Author: weijie.tong <we...@alipay.com>
Date: 2017-07-27T12:38:46Z
fix drill-5691
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva your test case can not reproduce the error . You can search the dev email to find the origin error description with the keyword "Drill query planning error". Your query already satisfy the NestedLoopJoinPrule. My case is that I add another rule to change the Aggregate-->Aggregate-->Scan to Scan as the transformed Scan relnode already holding the count(distinct ) value. When this transformation occurs, the NestedLoopJoinPrule's checkPreconditions method will invoke JoinUtils.hasScalarSubqueryInput. Then it will fail, as the transformed relnode has no aggregate node which does not satisfy the current scalar rule.
I think it's hard to reproduce this error without a specific rule like what I do. the precondition is:
1. a nested loop join
2. no (aggregate--> aggregate) count distinct relation nodes in the plan
3. the row number of one child of the nested loop join is 1 .
I wonder if the enhanced code does not break the current unit test ,it will be ok.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131871578
--- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/join/TestNestedLoopJoin.java ---
@@ -325,4 +325,5 @@ public void testNlJoinWithLargeRightInputSuccess() throws Exception {
test(RESET_JOIN_OPTIMIZATION);
}
}
+
--- End diff --
Please revert changes in this file.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva @amansinha100 any further advice ?
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r140756869
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdMaxRowCount.java ---
@@ -0,0 +1,42 @@
+/*
+ * 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.drill.exec.planner.cost;
+
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMdMaxRowCount;
+import org.apache.calcite.rel.metadata.RelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.drill.exec.planner.logical.DrillLimitRel;
+
+public class DrillRelMdMaxRowCount extends RelMdMaxRowCount {
+
+ private static final DrillRelMdMaxRowCount INSTANCE = new DrillRelMdMaxRowCount();
+
+ public static final RelMetadataProvider SOURCE = ReflectiveRelMetadataProvider.reflectiveSource(BuiltInMethod.MAX_ROW_COUNT.method, INSTANCE);
+
+ public Double getMaxRowCount(DrillLimitRel rel, RelMetadataQuery mq) {
+ return rel.getRows();
+ }
+
+ @Override
+ public Double getMaxRowCount(TableScan rel, RelMetadataQuery mq) {
+ return rel.getRows();
--- End diff --
@amansinha100 Your assumption is right. My initial motivation is to materialize the count distinct value of one table column without the group by clause into a single-row table i.e. a cache. To accelerate users' query time, this materialization seems reasonable.
Since getMaxRowCount() only invoked by the `JoinUtils.isScalarSubquery` ,there's no potential issues.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r137295692
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -203,35 +203,27 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
}
/**
- * Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * Utility method to check if a subquery (represented by its root RelNode) is provably scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
- DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
- // If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
- // Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
- } else {
- break;
- }
- }
-
- if (agg != null) {
- if (agg.getGroupSet().isEmpty()) {
- return true;
+ RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance();
+ RelNode currentRel = root;
+ for (; ; ) {
--- End diff --
If the currentRel happens to be null we should not enter the loop. Better to keep the while(currentRel != null) and have the return FALSE at the end.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131871049
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel)currentRel;
+ } else if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset)currentRel).getBest() ;
+ } else if (currentRel.getInputs().size() == 1) {
// If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
// Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
+ currentRel = currentRel.getInput(0);
} else {
+ if(currentRel.getInputs().size()>1){
--- End diff --
Please add spaces: `if (currentRel.getInputs().size() > 1) {`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva have passed all the unit tests under java-exec bundle , got some errors which are sure not associated with this change, maybe my branch was old from the master.
>
TestConstantFolding.testConstantFolding_allTypes:163 » org.apache.drill.commo...
TestCustomUserAuthenticator.positiveUserAuth » UserRemote SYSTEM ERROR: URISyn...
TestCustomUserAuthenticator.positiveUserAuthAfterNegativeUserAuth » UserRemote
TestInfoSchema.selectFromAllTables » UserRemote SYSTEM ERROR: URISyntaxExcepti...
TestViewSupport.infoSchemaWithView:355->BaseTestQuery.testRunAndReturn:331 » Rpc
TestInfoSchemaFilterPushDown.testFilterPushdown_NonEqual » UserRemote SYSTEM E...
TestParquetScan.testSuccessFile:64->BaseTestQuery.testRunAndReturn:331 » Rpc o...
TestTpchDistributedConcurrent.testConcurrentQueries:190 » test timed out afte...
I also found the error to do `mvn test` ,got the same error as JIRA DRILL-4104 . through `mvn test -pl exec/java-exec` this method,I got the unit test result. I wonder how the devs do the test result .
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131870970
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel)currentRel;
+ } else if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset)currentRel).getBest() ;
--- End diff --
`currentRel = ((RelSubset) currentRel).getBest() ;`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
@weijietong regarding the unit test, I have tried to reproduce the problem and written the following unit test:
```
@Test
public void test() throws Exception {
FileSystem fs = null;
try {
fs = FileSystem.get(new Configuration());
// create table with partition pruning
test("use dfs_test.tmp");
String tableName = "table_with_pruning";
Path dataFile = new Path(TestTools.getWorkingPath(),"src/test/resources/parquet/alltypes_required.parquet");
test("create table %s partition by (col_int) as select * from dfs.`%s`", tableName, dataFile);
// generate metadata
test("refresh table metadata `%s`", tableName);
// execute query
String query = String.format("select count(distinct col_int), count(distinct col_chr) from `%s` where col_int = 45436", tableName);
test(query);
} finally {
if (fs != null) {
fs.close();
}
}
}
```
`AbstractGroupScan.getScanStats` method returns one row but it does not fail. Can you please take a look?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
+1, LGMT.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on the issue:
https://github.com/apache/drill/pull/889
@weijietong I am interested in getting your basic changes in. It is unfortunate we are running into this issue with RelSubSet. Let me see if I can make some changes on top of your changes (I will keep your authorship) and have it pass all our functional regression tests.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r140161176
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -203,32 +203,23 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
}
/**
- * Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * Utility method to check if a subquery (represented by its root RelNode) is provably scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
- DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
- // If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
- // Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
- } else {
- break;
+ RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance();
+ RelNode currentRel = root;
+ while (currentRel != null) {
+ if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset) currentRel).getBest();
+ continue;
}
- }
-
- if (agg != null) {
- if (agg.getGroupSet().isEmpty()) {
+ Double rowCount = relMetadataQuery.getMaxRowCount(currentRel);
+ if (rowCount != null && rowCount.equals(1.0)) {
--- End diff --
For scalar, the value could be <= 1.0 (0 also qualifies).
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r135199961
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if (!hasMoreInputs && currentRel != null) {
+ Double rowSize = RelMetadataQuery.instance().getMaxRowCount(currentRel);
--- End diff --
Actually, I am thinking this entire method isScalarSubquery() should be rewritten to call RelMetadataQuery.getMaxRowCount(). Originally, when this was written, the max row count interface was not available.
I think your use case is somewhat specific that the table has 1 row. However, suppose we had LIMIT 1 in the subquery, we could still treat it as scalar since it would produce at most 1 row. My thought is instead of solving for your specific table scan case, we might as well address the generalized scalar check since Calcite already provides it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva thanks for the advice, has corrected that.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
On mine environment all tests pass. I used to have troubles but long time ago. I had to fix issues with timezones, memory usage `MAVEN_OPTS="-Xmx2048m -XX:MaxPermSize=1024m"`. Also I am pretty sure that some test have failed because the others did, usually the ones with Rpc exception. Maybe `UserRemote SYSTEM ERROR: URISyntaxException` is connected with your env. You should check that. Also please rebase on the latest master (you can do `push -f` again), also if `TestTpchDistributedConcurrent.testConcurrentQueries` will be failing again, try to disable it but make sure it passes separately.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r137424972
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -203,35 +203,27 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
}
/**
- * Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * Utility method to check if a subquery (represented by its root RelNode) is provably scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
- DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
- // If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
- // Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
- } else {
- break;
- }
- }
-
- if (agg != null) {
- if (agg.getGroupSet().isEmpty()) {
- return true;
+ RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance();
+ RelNode currentRel = root;
+ for (; ; ) {
+ if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset) currentRel).getBest();
+ } else if (currentRel != null) {
+ Double rowCount = relMetadataQuery.getRowCount(currentRel);
--- End diff --
@amansinha100 thanks for the review ,have updated
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r135249441
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel) currentRel;
+ } else if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset) currentRel).getBest();
+ } else if (currentRel.getInputs().size() == 1) {
// If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
// Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
+ currentRel = currentRel.getInput(0);
} else {
+ if (currentRel.getInputs().size() > 1) {
--- End diff --
@amansinha100 thanks for the review . this flag is to indicate that it's a single input relnode, not a join node.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r140160556
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/cost/DrillRelMdMaxRowCount.java ---
@@ -0,0 +1,42 @@
+/*
+ * 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.drill.exec.planner.cost;
+
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.metadata.ReflectiveRelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMdMaxRowCount;
+import org.apache.calcite.rel.metadata.RelMetadataProvider;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.util.BuiltInMethod;
+import org.apache.drill.exec.planner.logical.DrillLimitRel;
+
+public class DrillRelMdMaxRowCount extends RelMdMaxRowCount {
+
+ private static final DrillRelMdMaxRowCount INSTANCE = new DrillRelMdMaxRowCount();
+
+ public static final RelMetadataProvider SOURCE = ReflectiveRelMetadataProvider.reflectiveSource(BuiltInMethod.MAX_ROW_COUNT.method, INSTANCE);
+
+ public Double getMaxRowCount(DrillLimitRel rel, RelMetadataQuery mq) {
+ return rel.getRows();
+ }
+
+ @Override
+ public Double getMaxRowCount(TableScan rel, RelMetadataQuery mq) {
+ return rel.getRows();
--- End diff --
Sorry, I had been meaning to reply sooner. I think overloading the getMaxRowCount() to return rel.getRows() can create potential issues...because getMaxRowCount() should always return whatever is the *maximum* row count possible for that RelNode. Here, if you return TableScan.getRows(), the value is an *estimate*, which means in reality it could be higher. The caller might make incorrect decision based on this value.
I am thinking about your original motivation for the changes. Are you materializing the results into a single-row table ? It sounds like you want a special table scan whose max row count is 1. Is materializing the only option ? (the reason I am curious is it is odd to materialize very small data sets such as 1 row).
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r137291711
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -203,35 +203,27 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
}
/**
- * Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * Utility method to check if a subquery (represented by its root RelNode) is provably scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
- DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
- // If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
- // Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
- } else {
- break;
- }
- }
-
- if (agg != null) {
- if (agg.getGroupSet().isEmpty()) {
- return true;
+ RelMetadataQuery relMetadataQuery = RelMetadataQuery.instance();
+ RelNode currentRel = root;
+ for (; ; ) {
+ if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset) currentRel).getBest();
+ } else if (currentRel != null) {
+ Double rowCount = relMetadataQuery.getRowCount(currentRel);
--- End diff --
getRowCount() is not correct. Pls see my prior comment on using the RelMdMaxRowCount.getMaxRowCount() APIs. The reason is getRowCount() will give an estimate which may not match the actual run-time value, whereas the getMaxRowCount() is an assertion by the optimizer that row count cannot exceed a number N (in your case 1).
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva other tests have passed separately and time zone related test cases have been corrected in PR 5717
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on the issue:
https://github.com/apache/drill/pull/889
@weijietong I ran the functional tests with the PR and saw some failures. While debugging those failures, I found the simple scalar aggregate case works but anything with compound aggregate expressions throws a CannotPlanException, for example:
explain plan for select count(*) from cp.`tpch/lineitem.parquet` l where l_quantity < (select max(l2.l_quantity) + 1 from cp.`tpch/lineitem.parquet` l2)
Here, the right side of the inequality join is actually a scalar but the JoinUtils.isScalar() method does not detect it correctly. The reason is the right side is a DrillProjectRel whose input is a RelSubSet. The RelSubSet has a DrillAggregateRel but it looks like currently Calcite does not detect this is a scalar aggregate if it occurs as part of a RelSubSet. I see Calcite has a comment in [1] which points to an open JIRA CALCITE-1048.
[1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java#L165
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131871224
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel)currentRel;
+ } else if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset)currentRel).getBest() ;
+ } else if (currentRel.getInputs().size() == 1) {
// If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
// Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
+ currentRel = currentRel.getInput(0);
} else {
+ if(currentRel.getInputs().size()>1){
+ hasMoreInputs=true;
--- End diff --
Please add spaces: `hasMoreInputs = true;`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131871292
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if(!hasMoreInputs && currentRel!=null){
--- End diff --
Please add spaces: `if (!hasMoreInputs && currentRel != null) {`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: Drill 5691 enhance scalar sub queries checking for the car...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
The build process is good at my laptop. anyone please work this out.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
ping @arina-ielchiieva @amansinha100
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131870863
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel)currentRel;
--- End diff --
` agg = (DrillAggregateRel) currentRel;`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva I have corrected the codes as you guide. But sorry for the unit tests, I have tried a long time to simulate a scan with 1 row ,but failed to do that. The row count of a scan is fetched from the AbstractGroupScan.getScanStats method. At my plugin ,I override this method to ensure it will return 1 .
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva @amansinha100 isScalarSubquery method has been refactored , please review.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r135292416
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if (!hasMoreInputs && currentRel != null) {
+ Double rowSize = RelMetadataQuery.instance().getMaxRowCount(currentRel);
--- End diff --
You could see the usage of RelMdMaxRowCount in Calcite [1]. It has implementations for different Rels including Aggregate, sort+limit. I would recommend adding some unit tests though if you are going to make the code changes since this would be new functionality.
[1] https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r134424551
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if (!hasMoreInputs && currentRel != null) {
+ double rowSize = RelMetadataQuery.instance().getMaxRowCount(currentRel);
--- End diff --
As @vvysotskyi has noted, `getMaxRowCount` returns `Double` and may return `null` if this method is not overriden in the operator [1]. I guess it would be safer to assign value to `Double` and use `equals` for comparison in this case (`new Double(1.0).equals(rowSize)`).
[1] https://github.com/apache/calcite/blob/ceca631872ec64fa345f7df9cdf185e1f9252449/core/src/main/java/org/apache/calcite/rel/metadata/RelMdMaxRowCount.java#L182
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r135254275
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if (!hasMoreInputs && currentRel != null) {
+ Double rowSize = RelMetadataQuery.instance().getMaxRowCount(currentRel);
--- End diff --
I agree that we should rewrite the method by call RelMetadataQuery.getMaxRowCount(). btw, could you give a guide how calcite do that ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
@weijietong thanks for the PR.
1. Is it possible to add unit tests?
2. Can you please add in method description that a table scan with only one row should also be considered as a scalar as well.
3. Please fix indention in `if` statements and change `currentrel` to camel case [1].
[1] https://drill.apache.org/docs/apache-drill-contribution-guidelines/
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@amansinha100 I have removed the override of `getMaxRowCount` method of `TableScan` type to avoid your worry about unexpected results . This PR's target adjusts to just enhance the current cartesian join by leveraging Calcite's `RelMdMaxRowCount` method. I will solve our case specially at our env.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by paul-rogers <gi...@git.apache.org>.
Github user paul-rogers commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva, @amansinha100 can you take another look at this one and see if your concerns have been addressed?
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by paul-rogers <gi...@git.apache.org>.
Github user paul-rogers commented on the issue:
https://github.com/apache/drill/pull/889
@arina-ielchiieva, looks like Weijie added a couple of commits since your +1. Can you take a look at them?
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
Thanks @weijietong. LGTM.
@amansinha100 could you please do the final CR since you are familiar with this issue?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on the issue:
https://github.com/apache/drill/pull/889
@weijietong thanks for code formatting.
> I wonder if the enhanced code does not break the current unit test ,it will be ok.
Can you please check this? Did all unit tests pass after the change?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by amansinha100 <gi...@git.apache.org>.
Github user amansinha100 commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r135196236
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -204,24 +205,28 @@ public static void addLeastRestrictiveCasts(LogicalExpression[] leftExpressions,
/**
* Utility method to check if a subquery (represented by its root RelNode) is provably scalar. Currently
- * only aggregates with no group-by are considered scalar. In the future, this method should be generalized
- * to include more cases and reconciled with Calcite's notion of scalar.
+ * only aggregates with no group-by and sub input rel with one row are considered scalar. In the future,
+ * this method should be generalized to include more cases and reconciled with Calcite's notion of scalar.
* @param root The root RelNode to be examined
* @return True if the root rel or its descendant is scalar, False otherwise
*/
public static boolean isScalarSubquery(RelNode root) {
DrillAggregateRel agg = null;
- RelNode currentrel = root;
- while (agg == null && currentrel != null) {
- if (currentrel instanceof DrillAggregateRel) {
- agg = (DrillAggregateRel)currentrel;
- } else if (currentrel instanceof RelSubset) {
- currentrel = ((RelSubset)currentrel).getBest() ;
- } else if (currentrel.getInputs().size() == 1) {
+ RelNode currentRel = root;
+ boolean hasMoreInputs = false;
+ while (agg == null && currentRel != null) {
+ if (currentRel instanceof DrillAggregateRel) {
+ agg = (DrillAggregateRel) currentRel;
+ } else if (currentRel instanceof RelSubset) {
+ currentRel = ((RelSubset) currentRel).getBest();
+ } else if (currentRel.getInputs().size() == 1) {
// If the rel is not an aggregate or RelSubset, but is a single-input rel (could be Project,
// Filter, Sort etc.), check its input
- currentrel = currentrel.getInput(0);
+ currentRel = currentRel.getInput(0);
} else {
+ if (currentRel.getInputs().size() > 1) {
--- End diff --
It seems you are interested only in the 0 input case such as TableScan since later on line 239 you check for !hasMoreInputs. In that case, I don't think you need to set this flag. Why not just check currentRel.getInputs().size() == 0 on line 239 ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] drill issue #889: DRILL-5691: enhance scalar sub queries checking for the ca...
Posted by weijietong <gi...@git.apache.org>.
Github user weijietong commented on the issue:
https://github.com/apache/drill/pull/889
@amansinha100 thanks for sharing the information. Got your point. I think your propose on [CALCITE-1048](https://issues.apache.org/jira/browse/CALCITE-1048) is possible. Since [CALCITE-794](https://issues.apache.org/jira/browse/CALCITE-794) has completed at version 1.6 ,it seems there's a more perfect solution( to get the least max number of all the rels of the RelSubSet). But due to Drill's Caclite version is still based on 1.4 , I support your current temp solution. Only wonder that whether the explicitly searched RelNode's (such as DrillAggregateRel) maxRowCount can represent the best RelNode's maxRowCount ?
---
[GitHub] drill pull request #889: DRILL-5691: enhance scalar sub queries checking for...
Posted by arina-ielchiieva <gi...@git.apache.org>.
Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/889#discussion_r131871360
--- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/join/JoinUtils.java ---
@@ -231,6 +236,12 @@ public static boolean isScalarSubquery(RelNode root) {
return true;
}
}
+ if(!hasMoreInputs && currentRel!=null){
+ double rowSize = RelMetadataQuery.instance().getMaxRowCount(currentRel);
+ if(rowSize==1){
--- End diff --
Please add spaces: `if (rowSize == 1) {`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---