guoyangqiao created CALCITE-3202:
------------------------------------

             Summary: ElasticsearchAggregate constructor throws an 
AssertionError while applying AggregateProjectMergeRule by VolcanoPlanner
                 Key: CALCITE-3202
                 URL: https://issues.apache.org/jira/browse/CALCITE-3202
             Project: Calcite
          Issue Type: Bug
          Components: elasticsearch-adapter
    Affects Versions: 1.21.0
            Reporter: guoyangqiao
         Attachments: log.log.zip, mapping.json

Thanks for viewing this issue! The error occurs when I was trying to execute a 
query with some subquery: 
{code:java}
select distinct uni_id
from (
select uni_id from sample_index where customer_child = 'customer' and 
customer_from_plat = 'FOO'
and uni_id in (select  uni_id from sample_index where customer_child = 'trade' 
and shop_id = '60790435')
and uni_id in (select  uni_id from sample_index where customer_child = 'member' 
and member_id = '884225534')
)
{code}
While running code below:
{code:java}
ElasticsearchAggregate(RelOptCluster cluster,
    RelTraitSet traitSet,
    RelNode input,
    ImmutableBitSet groupSet,
    List<ImmutableBitSet> groupSets,
    List<AggregateCall> aggCalls) throws InvalidRelException  {
  super(cluster, traitSet, input, groupSet, groupSets, aggCalls);

  if (getConvention() != input.getConvention()) {
    String message = String.format(Locale.ROOT, "%s != %s", getConvention(),
        input.getConvention());
    throw new AssertionError(message);
  }{code}
an AssertionError which means an input of ElasticsearchAggregate has a 
Convention of NONE throws out. stack traces shows as below:  
{code:java}
java.lang.AssertionError: ELASTICSEARCH != NONE
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate.<init>(ElasticsearchAggregate.java:66)
at 
org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate.copy(ElasticsearchAggregate.java:112)
at 
org.apache.calcite.rel.rules.AggregateProjectMergeRule.apply(AggregateProjectMergeRule.java:113)
at 
org.apache.calcite.rel.rules.AggregateProjectMergeRule.onMatch(AggregateProjectMergeRule.java:72)
at 
org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:208)
at 
org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:631)
at org.apache.calcite.tools.Programs.lambda$standard$3(Programs.java:283)
at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:343)
at org.apache.calcite.prepare.Prepare.optimize(Prepare.java:189)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:320)
at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:231)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:637)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:501)
at 
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:471)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:231)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:213)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:202)
at 
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:93)
at 
org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:175)
at SearchTest.main(SearchTest.java:25)

{code}
And before the volcano planner start to work, the algebra expression looks like 
this:
{code:java}
LogicalAggregate(group=[{0}])
  LogicalProject(uni_id=[$2])
    LogicalFilter(condition=[AND(=($0, 'customer'), =($1, 'FOO'))])
      LogicalJoin(condition=[=($2, $4)], joinType=[inner])
        LogicalJoin(condition=[=($2, $3)], joinType=[inner])
          LogicalProject(customer_child=[CAST(ITEM($0, 
'customer_child')):VARCHAR(65535)], customer_from_plat=[CAST(ITEM($0, 
'customer_from_plat')):VARCHAR(255)], uni_id=[CAST(ITEM($0, 
'uni_id')):VARCHAR(255)])
            ElasticsearchTableScan(table=[[elasticsearch_raw, sample_index]])
          LogicalAggregate(group=[{0}])
            LogicalProject(uni_id=[$2])
              LogicalFilter(condition=[AND(=($0, 'trade'), =($1, '60790435'))])
                LogicalProject(customer_child=[CAST(ITEM($0, 
'customer_child')):VARCHAR(65535)], shop_id=[CAST(ITEM($0, 
'shop_id')):VARCHAR(255)], uni_id=[CAST(ITEM($0, 'uni_id')):VARCHAR(255)])
                  ElasticsearchTableScan(table=[[elasticsearch_raw, 
sample_index]])
        LogicalAggregate(group=[{0}])
          LogicalProject(uni_id=[$2])
            LogicalFilter(condition=[AND(=($0, 'member'), =($1, '884225534'))])
              LogicalProject(customer_child=[CAST(ITEM($0, 
'customer_child')):VARCHAR(65535)], member_id=[CAST(ITEM($0, 
'member_id')):VARCHAR(255)], uni_id=[CAST(ITEM($0, 'uni_id')):VARCHAR(255)])
                ElasticsearchTableScan(table=[[elasticsearch_raw, 
sample_index]]){code}
 Attachment:

log.log.zip is a compressed log file with DEBUG level.

mapping.json is the ES sample_index's mapping information.

Please check them if needed.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to