[ 
https://issues.apache.org/jira/browse/CALCITE-2679?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Siyuan Liu updated CALCITE-2679:
--------------------------------
    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:
{code:sql}
select state, city from zips group by state, city
{code}
After translation, adapter should return the following JSON:
{code:json}
{
        "_source": false,
        "size": 0,
        "aggregations": {
                "g_state": {
                        "terms": {
                                "field": "state",
                                "missing": "__MISSING__"
                        },
                        "aggregations": {
                                "g_city ": {
                                  "terms ": {
                                        "field ":"city ",
                                          "missing":"__MISSING__ "
                                  }
                                }
                        }
                }
        }
}
{code}
But it returns the following JSON now:
{code:sql}
{
        "_source": ["state", "city"]
}
{code}
The reason for this problem is that there is a missing condition for judging 
the aggregation query. 
In addition, there is the other associated issue. After building aggregation 
JSON, the code of current version will remove empty aggregation block in 
ElasticsearchTable class, the code just like this:
  {code:java}
    JsonNode agg = query;
    while (agg.has(AGGREGATIONS) && agg.get(AGGREGATIONS).elements().hasNext()) 
{
      agg = agg.get(AGGREGATIONS);
    }
    ((ObjectNode) agg).remove(AGGREGATIONS);
{code}
But if input the JSON like above, this code will not work out.

  was:```select state, city from zips group by state, city```


> Group by without aggregation function cannot be translated to correct JSON in 
> Elasticsearch Adapter
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-2679
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2679
>             Project: Calcite
>          Issue Type: Bug
>          Components: elasticsearch-adapter
>    Affects Versions: 1.18.0
>            Reporter: Siyuan Liu
>            Assignee: Julian Hyde
>            Priority: Major
>              Labels: easyfix
>
> 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:
> {code:sql}
> select state, city from zips group by state, city
> {code}
> After translation, adapter should return the following JSON:
> {code:json}
> {
>       "_source": false,
>       "size": 0,
>       "aggregations": {
>               "g_state": {
>                       "terms": {
>                               "field": "state",
>                               "missing": "__MISSING__"
>                       },
>                       "aggregations": {
>                               "g_city ": {
>                                 "terms ": {
>                                       "field ":"city ",
>                                         "missing":"__MISSING__ "
>                                 }
>                               }
>                       }
>               }
>       }
> }
> {code}
> But it returns the following JSON now:
> {code:sql}
> {
>       "_source": ["state", "city"]
> }
> {code}
> The reason for this problem is that there is a missing condition for judging 
> the aggregation query. 
> In addition, there is the other associated issue. After building aggregation 
> JSON, the code of current version will remove empty aggregation block in 
> ElasticsearchTable class, the code just like this:
>   {code:java}
>     JsonNode agg = query;
>     while (agg.has(AGGREGATIONS) && 
> agg.get(AGGREGATIONS).elements().hasNext()) {
>       agg = agg.get(AGGREGATIONS);
>     }
>     ((ObjectNode) agg).remove(AGGREGATIONS);
> {code}
> But if input the JSON like above, this code will not work out.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to