[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-10 Thread Danny Chan (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859828#comment-16859828
 ] 

Danny Chan commented on CALCITE-2744:
-

Thanks [~julianhyde], i still apply the fix because i think the original name 
"MY_AVG" name is misleading. Fixed in 
[340e21a6a|https://github.com/apache/calcite/commit/340e21a6a93e0766acf3fa292c4ecd86d5f5f8ef]
 !

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.20.0
>
>  Time Spent: 3h
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-09 Thread Danny Chan (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859670#comment-16859670
 ] 

Danny Chan commented on CALCITE-2744:
-

[~julianhyde] I fired  a fix in [https://github.com/apache/calcite/pull/1263], 
can you take a look ?

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.20.0
>
>  Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-09 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859624#comment-16859624
 ] 

Julian Hyde commented on CALCITE-2744:
--

While you're in that code, modify the javadoc of MY_AVG and explain why it is 
special.

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.20.0
>
>  Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-09 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16859621#comment-16859621
 ] 

Julian Hyde commented on CALCITE-2744:
--

* It's usually not a good idea if the commit message describes the code change 
that you made. A better commit message (and JIRA case title) would have 
described the bug that the end-user sees, for example "RelDecorrelator throws 
when decorrelating an aggregate function with more than one argument". 
* This commit adds a call to a deprecated API (line 136 of 
MockSqlOperatorTable). Please fix ASAP.

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
> Fix For: 1.20.0
>
>  Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-05 Thread Danny Chan (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16857220#comment-16857220
 ] 

Danny Chan commented on CALCITE-2744:
-

Fixed in 
[https://github.com/apache/calcite/commit/7c319dbbce7957d622dcc47707f293ddaa5bcb34],
 thanks for your PR, [~godfreyhe] !

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 2h 20m
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-04 Thread Danny Chan (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16856331#comment-16856331
 ] 

Danny Chan commented on CALCITE-2744:
-

[~julianhyde] I think there is some problem with the original PR, so i fired a 
new one!

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-04 Thread Julian Hyde (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16856316#comment-16856316
 ] 

Julian Hyde commented on CALCITE-2744:
--

Why two PRs? I reviewed one of them.

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 40m
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> at 
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at 

[jira] [Commented] (CALCITE-2744) RelDecorrelator use wrong output map for LogicalAggregate decorrelate

2019-06-04 Thread Danny Chan (JIRA)


[ 
https://issues.apache.org/jira/browse/CALCITE-2744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16856237#comment-16856237
 ] 

Danny Chan commented on CALCITE-2744:
-

I digged into the code and found that it is not because the agg call use 
multiple parameters, it is because the final output map for the aggregate is 
totally wrong. Say, We have a "combinedMap" as the mapping between the old 
input and the new project:
{code:java}
Aggregate

|   new project  - - - - 

|   new_input         combinedMap

|   old_input    - - - -
{code}
This "combinedMap" can not be used as map of the old aggregate and the new 
generated aggregate. 

 

> RelDecorrelator use wrong output map for LogicalAggregate decorrelate
> -
>
> Key: CALCITE-2744
> URL: https://issues.apache.org/jira/browse/CALCITE-2744
> Project: Calcite
>  Issue Type: Bug
>  Components: core
>Affects Versions: 1.20.0
>Reporter: Wei Zhong
>Assignee: Danny Chan
>Priority: Major
>  Labels: pull-request-available
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> when running the following test in org.apache.calcite.test.RelOptRulesTest, 
> we will get a RuntimeException: 
> {code:java}
> @Test public void testDecorrelateWith2ParamsAgg() {
>   final HepProgram preProgram =
>   HepProgram.builder()
>   .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
>   .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
>   .addRuleInstance(ProjectMergeRule.INSTANCE)
>   .build();
>   final HepProgram program =
>   HepProgram.builder()
>   .addRuleInstance(SemiJoinRule.PROJECT)
>   .build();
>   final String sql = "select * from dept where exists (\n"
>   + "select UDF_AVG(sal, sal + 1) from sales.emp\n"
>   + "where emp.deptno = dept.deptno\n"
>   + "and emp.sal > 100)";
>   Sql sqlTest = sql(sql)
>   .withDecorrelation(true)
>   .withTrim(true)
>   .withPre(preProgram)
>   .with(program);
>   sqlTest.check();
> }
> {code}
> UDF_AVG code in MockSqlOperatorTable: 
> {code:java}
> public static void addRamp(MockSqlOperatorTable opTab) {
>   // Don't use anonymous inner classes. They can't be instantiated
>   // using reflection when we are deserializing from JSON.
>   opTab.addOperator(new RampFunction());
>   opTab.addOperator(new DedupFunction());
>   opTab.addOperator(UDF_AVG);
> }
> public static final SqlFunction UDF_AVG = new SqlAggFunction(
> "UDF_AVG",
> null,
> SqlKind.OTHER_FUNCTION,
> ReturnTypes.AVG_AGG_FUNCTION,
> null,
> OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
> SqlFunctionCategory.NUMERIC,
> false,
> false,
> Optionality.FORBIDDEN) {
>   @Override public boolean isDeterministic() {
> return false;
>   }
> };
> {code}
> The RuntimeExcpetion detail:
> {code:java}
> java.lang.RuntimeException: While invoking method 'public 
> org.apache.calcite.sql2rel.RelDecorrelator$Frame 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateRel(org.apache.calcite.rel.logical.LogicalProject)'
> at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:527)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.getInvoke(RelDecorrelator.java:613)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelate(RelDecorrelator.java:254)
> at 
> org.apache.calcite.sql2rel.RelDecorrelator.decorrelateQuery(RelDecorrelator.java:214)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelateQuery(SqlToRelConverter.java:3037)
> at 
> org.apache.calcite.sql2rel.SqlToRelConverter.decorrelate(SqlToRelConverter.java:481)
> at 
> org.apache.calcite.test.SqlToRelTestBase$TesterImpl.convertSqlToRel(SqlToRelTestBase.java:615)
> at 
> org.apache.calcite.test.RelOptTestBase.checkPlanning(RelOptTestBase.java:177)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:334)
> at org.apache.calcite.test.RelOptTestBase$Sql.check(RelOptTestBase.java:317)
> at 
> org.apache.calcite.test.RelOptRulesTest.testDecorrelateWith2ParamsAgg(RelOptRulesTest.java:4286)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at 
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at 
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at 
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at 
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at