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

Group by without aggregation function cannot be translated to correct JSON in Elasticsearch Adapter

    XMLWordPrintableJSON

    Details

      Description

      The Elasticsearch Adapter of the current master branch has some problems when querying for group by clause without aggregation function. For example, when I query the following SQL:

      select state, city from zips group by state, city
      

      After translation, adapter should return the following JSON:

      {
      	"_source": false,
      	"size": 0,
      	"aggregations": {
      		"g_state": {
      			"terms": {
      				"field": "state",
      				"missing": "__MISSING__"
      			},
      			"aggregations": {
      				"g_city ": {
      				  "terms ": {
      					"field ":"city ",
      					  "missing":"__MISSING__ "
      				  }
      				}
      			}
      		}
      	}
      }
      

      But it returns the following JSON now:

      {
      	"_source": ["state", "city"]
      }
      

      The reason for this problem is that there is a missing condition for judging the aggregation query.
      In addition, there is the other associated problem. After building aggregation JSON, the code of current version will remove empty aggregation block in ElasticsearchTable class, the code just like this:

      JsonNode agg = query;
      while (agg.has(AGGREGATIONS) && agg.get(AGGREGATIONS).elements().hasNext()) {
        agg = agg.get(AGGREGATIONS);
      }
      ((ObjectNode) agg).remove(AGGREGATIONS);
      

      But if input the JSON like above, this code will not work out.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                julianhyde Julian Hyde
                Reporter:
                Functor10 Siyuan Liu
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: