Forbid complex aggregate function on sharded SQL, Closes #12

This commit is contained in:
jingxiaobing 2018-03-26 17:10:42 +08:00
parent 8d33ae2151
commit 59cead53a1
3 changed files with 19 additions and 4 deletions

View File

@ -951,6 +951,9 @@ func_expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(R). {
} }
if (sql_func_type(X.z) != FT_UNKNOWN) { if (sql_func_type(X.z) != FT_UNKNOWN) {
A->flags |= EP_AGGREGATE; A->flags |= EP_AGGREGATE;
if (context->parsing_place == SELECT_COLUMN) {
context->clause_flags |= CF_AGGREGATE;
}
} }
if (D) { if (D) {
A->flags |= EP_DISTINCT; A->flags |= EP_DISTINCT;
@ -961,6 +964,9 @@ func_expr(A) ::= ID(X) LP STAR RP(R). {
A = function_expr_new(&X, 0, &R); A = function_expr_new(&X, 0, &R);
if (sql_func_type(X.z) != FT_UNKNOWN) { if (sql_func_type(X.z) != FT_UNKNOWN) {
A->flags |= EP_AGGREGATE; A->flags |= EP_AGGREGATE;
if (context->parsing_place == SELECT_COLUMN) {
context->clause_flags |= CF_AGGREGATE;
}
} }
} }
func_expr(A) ::= JOIN_KW(N) LP expr(X) COMMA expr(Y) RP(R). { func_expr(A) ::= JOIN_KW(N) LP expr(X) COMMA expr(Y) RP(R). {

View File

@ -120,6 +120,7 @@ enum sql_clause_flag_t {
CF_LOCAL_QUERY = 0x20, CF_LOCAL_QUERY = 0x20,
CF_DISTINCT_AGGR = 0x40, CF_DISTINCT_AGGR = 0x40,
CF_SUBQUERY = 0x80, CF_SUBQUERY = 0x80,
CF_AGGREGATE = 0x0100,
}; };
enum sql_sort_order_t { enum sql_sort_order_t {

View File

@ -1724,10 +1724,18 @@ sharding_filter_sql(sql_context_t *context)
} }
} }
} }
if (select_has_AVG(select)) { if (context->clause_flags & CF_AGGREGATE) {
sql_context_set_error(context, PARSE_NOT_SUPPORT, if (select_has_AVG(select)) {
"(cetus)this AVG would be routed to multiple shards, not allowed"); sql_context_set_error(context, PARSE_NOT_SUPPORT,
return; "(cetus)this AVG would be routed to multiple shards, not allowed");
return;
}
/* if we can't find simple aggregates, it's inside complex expressions */
if (sql_expr_list_find_aggregate(select->columns) == 0) {
sql_context_set_error(context, PARSE_NOT_SUPPORT,
"(cetus) Complex aggregate function not allowed on sharded sql");
return;
}
} }
if (select->groupby_clause && select->orderby_clause && !select_groupby_orderby_have_same_column(select)) { if (select->groupby_clause && select->orderby_clause && !select_groupby_orderby_have_same_column(select)) {
sql_context_set_error(context, PARSE_NOT_SUPPORT, sql_context_set_error(context, PARSE_NOT_SUPPORT,