Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4130

Aggregation function in order by clause will throw exception in elasticsearch adapter

    XMLWordPrintableJSON

Details

    Description

      For sql like

      select id, count(id) from test group by id order by count(id)
      

      When execute query, `ElasticsearchTable#aggregate` will throw exception like

       Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
      

      Reproduce:

      Add test as below in AggregationTest
      CalciteAssert.that()
              .with(newConnectionFactory())
              .query("select cat2, count(cat2) from view group by cat2 order by count(cat2)")
              .returnsUnordered("cat2=g; EXPR$1=2",
                  "cat2=h; EXPR$1=1");
      

      result:

      Caused by: java.lang.IllegalArgumentException: Field EXPR$1 not defined for aggs
      	at org.apache.calcite.adapter.elasticsearch.ElasticsearchMapping.missingValueFor(ElasticsearchMapping.java:84)
      	at org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.aggregate(ElasticsearchTable.java:235)
      	at org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.find(ElasticsearchTable.java:130)
      	at org.apache.calcite.adapter.elasticsearch.ElasticsearchTable.access$000(ElasticsearchTable.java:70)
      	at org.apache.calcite.adapter.elasticsearch.ElasticsearchTable$ElasticsearchQueryable.find(ElasticsearchTable.java:411)
      	at Baz.bind(Unknown Source)
      	at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:355)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:315)
      	at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:507)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:498)
      	at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:182)
      	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
      	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
      	at org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:667)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:567)
      	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:675)
      	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
      	... 68 more
      

      till now, this problem can only be found in elasticsearch adapter

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              yuqi yuqi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h