You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Andrei Sereda (JIRA)" <ji...@apache.org> on 2018/12/28 21:48:00 UTC

[jira] [Commented] (CALCITE-2679) Group by without aggregation function cannot be translated to correct JSON in Elasticsearch Adapter

    [ https://issues.apache.org/jira/browse/CALCITE-2679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16730473#comment-16730473 ] 

Andrei Sereda commented on CALCITE-2679:
----------------------------------------

[~Functor10], I believe a bug was introduced by this change.
Please check the following test cases (which currently fail):

{code:java}
    // combine any_value with other aggregation functions (eg. max)
    CalciteAssert.that()
        .with(newConnectionFactory())
        .query("select cat1, any_value(cat2), max(val1) from view group by cat1")
        .returnsUnordered("cat1=a; EXPR$1=g; EXPR$2=1.0",
            "cat1=null; EXPR$1=g; EXPR$2=null",
            "cat1=b; EXPR$1=h; EXPR$2=7.0");

    CalciteAssert.that()
        .with(newConnectionFactory())
        .query("select max(val1), cat1, any_value(cat2) from view group by cat1")
        .returnsUnordered("EXPR$0=1.0; cat1=a; EXPR$2=g",
            "EXPR$0=null; cat1=null; EXPR$2=g",
            "EXPR$0=7.0; cat1=b; EXPR$2=h");

    CalciteAssert.that()
        .with(newConnectionFactory())
        .query("select any_value(cat2), cat1, max(val1) from view group by cat1")
        .returnsUnordered("EXPR$0=g; cat1=a; EXPR$2=1.0",
            "EXPR$0=g; cat1=null; EXPR$2=null",
            "EXPR$0=h; cat1=b; EXPR$2=7.0");
{code}
 
Probable reason is that GroupValue is added multiple times resulting in more rows than necessary.

> 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
>             Fix For: 1.18.0
>
>
> 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 problem. 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)