From 6933eeea1fa43ea4c4ed0e30a105a5ed6c9955a1 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 6 Apr 2015 19:09:15 +0300 Subject: [PATCH] cql3: enable grammar for COUNT(*) and COUNT(1) --- cql3/Cql.g | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cql3/Cql.g b/cql3/Cql.g index 785c758e0a..b9033b6d86 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -279,9 +279,7 @@ selectStatement returns [shared_ptr expr] } : K_SELECT ( ( K_DISTINCT { is_distinct = true; } )? sclause=selectClause -#if 0 | sclause=selectCountClause -#endif ) K_FROM cf=columnFamilyName ( K_WHERE wclause=whereClause )? @@ -327,17 +325,22 @@ selectionFunctionArgs returns [std::vector> a] ')' ; -#if 0 -selectCountClause returns [List expr] - @init{ ColumnIdentifier alias = new ColumnIdentifier("count", false); } - : K_COUNT '(' countArgument ')' (K_AS c=ident { alias = c; })? { $expr = new ArrayList(); $expr.add( new RawSelector(new Selectable.WithFunction.Raw(FunctionName.nativeFunction("countRows"), Collections.emptyList()), alias));} +selectCountClause returns [std::vector> expr] + @init{ auto alias = make_shared("count", false); } + : K_COUNT '(' countArgument ')' (K_AS c=ident { alias = c; })? { + auto&& with_fn = ::make_shared( + cql3::functions::function_name::native_function("countRows"), + std::vector>()); + $expr.push_back(make_shared(with_fn, alias)); + } ; countArgument - : '\*' - | i=INTEGER { if (!i.getText().equals("1")) addRecognitionError("Only COUNT(1) is supported, got COUNT(" + i.getText() + ")");} + : '*' + | i=INTEGER { if (i->getText() != "1") { + add_recognition_error("Only COUNT(1) is supported, got COUNT(" + i->getText() + ")"); + } } ; -#endif whereClause returns [std::vector clause] : relation[$clause] (K_AND relation[$clause])*