Aggregate and Group By in Apache Phoenix

3.2k views Asked by At

I am trying to execute a query in Apache Phoenix where i am using aggregate and groupby function. I have executed the same query in mysql and it works but in Phoenix I tried the query based on mysql query but it failed. Please see mysql query and Phoenix query below.

MySQL:

select id3, id4, name, descr, status, min(date) from table1
where status = "inactive" group by id3, id4, name, descr, status  

Result:
id3 id4 name descr status min(date)

17773 8001300701101 name1 descr1 INACTIVE 20121202
17785 9100000161822 name3 descr3 INACTIVE 20121201

Phoenix Query:

There is no difference in the query between MySQL and Phoenix.

select id3, id4, name, descr, status, min ( date )  from table1
WHERE status = 'inactive' group by  id3, id4, name, descr, status;  

But i am getting the below error Can any one explain please?

Error: ERROR 1018 (42Y27): Aggregate may not contain columns not in GROUP BY. ELS_NAME (state=42Y27,code=1018)
java.sql.SQLException: ERROR 1018 (42Y27): Aggregate may not contain columns not in GROUP BY. ELS_NAME
    at org.apache.phoenix.exception.SQLExceptionCode$Factory$1.newException(SQLExceptionCode.java:361)
    at org.apache.phoenix.exception.SQLExceptionInfo.buildException(SQLExceptionInfo.java:133)
    at org.apache.phoenix.compile.ExpressionCompiler.throwNonAggExpressionInAggException(ExpressionCompiler.java:1141)
    at org.apache.phoenix.compile.ProjectionCompiler.compile(ProjectionCompiler.java:378)
    at org.apache.phoenix.compile.QueryCompiler.compileSingleFlatQuery(QueryCompiler.java:490)
    at org.apache.phoenix.compile.QueryCompiler.compileSingleQuery(QueryCompiler.java:447)
    at org.apache.phoenix.compile.QueryCompiler.compile(QueryCompiler.java:154)
    at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:331)
    at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:314)
    at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:230)
    at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:226)
    at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
    at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:225)
    at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1066)
    at sqlline.Commands.execute(Commands.java:822)
    at sqlline.Commands.sql(Commands.java:732)
    at sqlline.SqlLine.dispatch(SqlLine.java:808)
    at sqlline.SqlLine.begin(SqlLine.java:681)
    at sqlline.SqlLine.start(SqlLine.java:398)
    at sqlline.SqlLine.main(SqlLine.java:292
1

There are 1 answers

1
Sergei Rodionov On

You might want to check into column naming.

All table, column family and column names are uppercased unless they are double quoted in which case they are case sensitive.

https://phoenix.apache.org/language/index.html