[jira] [Created] (CALCITE-3519) `inheritPath` of `RelHint` represented by `ImmutableBitSet` may be incomplete.

2019-11-18 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3519:
---

 Summary: `inheritPath` of `RelHint` represented by 
`ImmutableBitSet` may be incomplete.
 Key: CALCITE-3519
 URL: https://issues.apache.org/jira/browse/CALCITE-3519
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.21.0
Reporter: Shuo Cheng
 Fix For: 1.22.0


Taking the following SQL with hint for example: (Copying from 
`org.apache.calcite.test.SqlHintsConverterTest.testQueryHint `)

 
{code:java}
select /*+ properties(k1='v1', k2='v2'), index(ename), no_hash_join */
from emp e1 
inner join dept d1 on e1.deptno = d1.deptno
inner join emp e2 on e1.ename = e2.job{code}
 

rel plan with hints should be following according to the hint design doc:
{code:java}
LogicalProject(EMPNO=[$0],...)([PROPERTIES inheritPath:[] options:{K1=v1, 
K2=v2}],[INDEX inheritPath:[] options:[ENAME]],[NO_HASH_JOIN inheritPath:[]])
  LogicalJoin(condition=[=($1, $20)], joinType=[inner]) ([NO_HASH_JOIN 
inheritPath:[0]])
LogicalJoin(condition=[=($7, $9)], joinType=[inner]) (NO_HASH_JOIN 
inheritPath:[0, 0]])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]]) ([PROPERTIES 
inheritPath:[0, 0, 0] options:{K1=v1, K2=v2}], [INDEX inheritPath:[0, 0, 0] 
options:[ENAME]])
  LogicalTableScan(table=[[CATALOG, SALES, DEPT]]) ([PROPERTIES 
inheritPath:[0, 0, 1] options:{K1=v1, K2=v2}], [INDEX inheritPath:[1, 0, 0] 
options:[ENAME]])
LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],...)
  LogicalTableScan(table=[[CATALOG, SALES, EMP]]) ([PROPERTIES 
inheritPath:[0, 1, 0] options:{K1=v1, K2=v2}], [INDEX inheritPath:[0, 1, 0] 
options:[ENAME]]){code}
 

But the expected result of  `SqlHintsConverterTest.testQueryHint` violates  the 
intention of Hint design doc.

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3527) enrich tests for sql hints.

2019-11-20 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3527:
---

 Summary: enrich tests for sql hints.
 Key: CALCITE-3527
 URL: https://issues.apache.org/jira/browse/CALCITE-3527
 Project: Calcite
  Issue Type: Sub-task
Affects Versions: 1.21.0
Reporter: Shuo Cheng
 Fix For: 1.22.0


* add more tests for sql hints 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3590) Support SQL hints for Aggregate.

2019-12-11 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3590:
---

 Summary: Support SQL hints for Aggregate.
 Key: CALCITE-3590
 URL: https://issues.apache.org/jira/browse/CALCITE-3590
 Project: Calcite
  Issue Type: Sub-task
  Components: core
Affects Versions: 1.21.0
Reporter: Shuo Cheng
 Fix For: 1.22.0






--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3631) Support SQL hints for Calc

2019-12-25 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3631:
---

 Summary: Support SQL hints for Calc
 Key: CALCITE-3631
 URL: https://issues.apache.org/jira/browse/CALCITE-3631
 Project: Calcite
  Issue Type: Sub-task
Reporter: Shuo Cheng


Calc combines the functionality of Project, and it's created in the later 
stages of optimization.

So it's necessary to make Calc hintable now.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3721) Filter of distinct aggregate call is lost after applying `AggregateExpandDistinctAggregatesRule`

2020-01-09 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3721:
---

 Summary: Filter of distinct aggregate call is lost after applying 
`AggregateExpandDistinctAggregatesRule`
 Key: CALCITE-3721
 URL: https://issues.apache.org/jira/browse/CALCITE-3721
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.21.0
Reporter: Shuo Cheng
Assignee: Shuo Cheng
 Fix For: 1.22.0


In `AggregateExpandDistinctAggregatesRule`, when the distinct aggregate call is 
rewriting using 

groupingSets, the filter of the distinct aggregate call itself is lost 
unexpected.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3830) Digest of AggregateCall do not consider the ''

2020-02-26 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3830:
---

 Summary: Digest of AggregateCall do not consider the ''
 Key: CALCITE-3830
 URL: https://issues.apache.org/jira/browse/CALCITE-3830
 Project: Calcite
  Issue Type: Bug
Reporter: Shuo Cheng






--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3893) Sql with GROUP_ID may generate wrong plan

2020-04-02 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3893:
---

 Summary: Sql with GROUP_ID may generate wrong plan
 Key: CALCITE-3893
 URL: https://issues.apache.org/jira/browse/CALCITE-3893
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.22.0
Reporter: Shuo Cheng
 Fix For: 1.23.0


Consider the following SQL:
{code:java}
select 
  deptno, group_id() as g, count(*) as c
from emp 
group by grouping sets (deptno, (), ())
{code}
the plan after SqlToRel is:
{code:java}
LogicalUnion(all=[true])
  LogicalProject(DEPTNO=[$0], G=[0:BIGINT], C=[$1])
LogicalAggregate(group=[{0}], groups=[[{0}, {}]], C=[COUNT()])
  LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
  LogicalProject(DEPTNO=[$0], G=[1:BIGINT], C=[$1])
LogicalAggregate(group=[{0}], groups=[[{}]], C=[COUNT()])
  LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
I'm afraid there's some semantic problems here. As `groups` of the aggregate is 
empty, then what is `$0` meaning in the project above the aggregate. Maybe that 
we want is:
{code:java}

LogicalUnion(all=[true])
  LogicalProject(DEPTNO=[$0], G=[0:BIGINT], C=[$1])
LogicalAggregate(group=[{0}], groups=[[{0}, {}]], C=[COUNT()])
  LogicalProject(DEPTNO=[$7])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
  LogicalProject(DEPTNO=[$0], G=[1:BIGINT], C=[$1])
LogicalAggregate(group=[{0}], groups=[[{0}]], C=[COUNT()])
  LogicalProject(DEPTNO=[null])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]){code}
I noticed this is introduced by CALCITE-1824, cc [~donnyzone], 
[~vladimirsitnikov].



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-3979) Unexpected removing of CAST in ReduceExpressionsRule

2020-05-08 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-3979:
---

 Summary: Unexpected removing of CAST in ReduceExpressionsRule
 Key: CALCITE-3979
 URL: https://issues.apache.org/jira/browse/CALCITE-3979
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.22.0
Reporter: Shuo Cheng
 Fix For: 1.23.0


{code:java}
@Test public void testCastRemove() throws Exception {
  final String sql = "select\n" +
  "case when cast(ename as double) < 5 then 0.0\n" +
  " else coalesce(cast(ename as double), 1.0)\n" +
  " end as t\n" +
  " from (\n" +
  "   select\n" +
  "  case when ename > 'abc' then ename\n" +
  "   else null\n" +
  "   end as ename from emp\n" +
  " )";
  sql(sql).withRule(ReduceExpressionsRule.PROJECT_INSTANCE).check();
}
{code}
As shown in the above test case, `cast(ename as double) < 5` was reduced as 
`ename < 5` when reducing expression, which lead to the following exception:
{code:java}
java.math.BigDecimal cannot be cast to 
org.apache.calcite.util.NlsStringjava.math.BigDecimal cannot be cast to 
org.apache.calcite.util.NlsStringjava.lang.ClassCastException: 
java.math.BigDecimal cannot be cast to org.apache.calcite.util.NlsString at 
org.apache.calcite.util.NlsString.compareTo(NlsString.java:47) at 
com.google.common.collect.Range.compareOrThrow(Range.java:672) at 
com.google.common.collect.Cut.compareTo(Cut.java:79) at 
com.google.common.collect.Range.isConnected(Range.java:526) at 
org.apache.calcite.rex.RexSimplify.residue(RexSimplify.java:1702) at 
org.apache.calcite.rex.RexSimplify.simplifyUsingPredicates(RexSimplify.java:1636)
 at org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:451) 
at org.apache.calcite.rex.RexSimplify.simplifyComparison(RexSimplify.java:321) 
at org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:292) at 
org.apache.calcite.rex.RexSimplify.simplifyAndTerms(RexSimplify.java:492) at 
org.apache.calcite.rex.RexSimplify.simplifyAnd(RexSimplify.java:1275) at 
org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:264) at 
org.apache.calcite.rex.RexSimplify.simplifyCase(RexSimplify.java:992) at 
org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:270) at 
org.apache.calcite.rex.RexSimplify.simplifyCase(RexSimplify.java:926) at 
org.apache.calcite.rex.RexSimplify.simplify(RexSimplify.java:270) at 
org.apache.calcite.rex.RexSimplify.simplifyUnknownAs(RexSimplify.java:235) at 
org.apache.calcite.rex.RexSimplify.simplifyPreservingType(RexSimplify.java:174) 
at 
org.apache.calcite.rel.rules.ReduceExpressionsRule.reduceExpressions(ReduceExpressionsRule.java:629)
 at 
org.apache.calcite.rel.rules.ReduceExpressionsRule$ProjectReduceExpressionsRule.onMatch(ReduceExpressionsRule.java:305)
 at 
org.apache.calcite.plan.AbstractRelOptPlanner.fireRule(AbstractRelOptPlanner.java:338)
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-4053) RexSimplify should not pass exprs containing non-const subExprs to RexExecutor#reduce

2020-06-08 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-4053:
---

 Summary: RexSimplify should not pass exprs containing non-const 
subExprs to RexExecutor#reduce
 Key: CALCITE-4053
 URL: https://issues.apache.org/jira/browse/CALCITE-4053
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.23.0
Reporter: Shuo Cheng
 Fix For: 1.24.0


Currently in RexSimplify#simplifyCast, if an expression is judged as a const 
expression but the outer CAST can not be removed, we pass the original 
expression to `RexExecutor` to reduce the expression which may leads to 
unexpected exception when the original expression contains `RexInputRef`.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Created] (CALCITE-4118) RexSimplify might remove CAST from RexNode incorrectly

2020-07-09 Thread Shuo Cheng (Jira)
Shuo Cheng created CALCITE-4118:
---

 Summary: RexSimplify might remove CAST from RexNode incorrectly
 Key: CALCITE-4118
 URL: https://issues.apache.org/jira/browse/CALCITE-4118
 Project: Calcite
  Issue Type: Bug
  Components: core
Affects Versions: 1.23.0
Reporter: Shuo Cheng
 Fix For: 1.24.0


{code:java}
@Test void testCastError() {
  final String sql = "select cast(cast(count(distinct empno) as varchar(65536)) 
as varbinary)\n"
  + "from emp group by deptno";
  sql(sql).ok();
}
{code}
Consider the above test case, we get the following plan after SqlToRel.
{code:java}
LogicalProject(EXPR$0=[CAST($1):VARBINARY NOT NULL])
  LogicalAggregate(group=[{0}], agg#0=[COUNT(DISTINCT $1)])
LogicalProject(DEPTNO=[$7], EMPNO=[$0])
  LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
As it is shown, `cast(* as varchar)` is removed (by RexSimplify#SimplifyCast), 
which is obviously wrong, because BIGINT can not cast to VARBINARY.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)