[1/3] cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation
Repository: cassandra Updated Branches: refs/heads/trunk 0edf54777 -> 86bca3a0b Allow count(*) and count(1) to be use as normal aggregation patch by Benjamin Lerer; reviewed by Stefania Alborghetti for CASSANDRA-10114 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4fc58513 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4fc58513 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4fc58513 Branch: refs/heads/trunk Commit: 4fc58513dce5ee6acb83ba07d9f31c26812075f9 Parents: 62fc314 Author: blerer Authored: Thu Aug 20 14:01:37 2015 +0200 Committer: blerer Committed: Thu Aug 20 14:01:37 2015 +0200 -- NEWS.txt| 1 + src/java/org/apache/cassandra/cql3/Cql.g| 9 + .../cassandra/cql3/functions/AggregateFcts.java | 11 ++ .../selection/AbstractFunctionSelector.java | 6 +++ .../cassandra/cql3/selection/Selector.java | 1 - .../validation/operations/AggregationTest.java | 39 6 files changed, 59 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/NEWS.txt -- diff --git a/NEWS.txt b/NEWS.txt index 37a1b9e..a9cf70d 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -100,6 +100,7 @@ New features - The toTimestamp(date) and toUnixTimestamp(date) functions have been added to allow to convert from date into timestamp type and bigint raw value. - SizeTieredCompactionStrategy parameter cold_reads_to_omit has been removed. + - COUNT(*) and COUNT(1) can be selected with other columns or functions 2.1.9 http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/Cql.g -- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index 0db09b8..3d2aba5 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -295,8 +295,7 @@ selectStatement returns [SelectStatement.RawStatement expr] } : K_SELECT ( K_JSON { isJson = true; } )? - ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause -| sclause=selectCountClause ) + ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause ) K_FROM cf=columnFamilyName ( K_WHERE wclause=whereClause )? ( K_ORDER K_BY orderByClause[orderings] ( ',' orderByClause[orderings] )* )? @@ -324,6 +323,7 @@ selector returns [RawSelector s] unaliasedSelector returns [Selectable.Raw s] @init { Selectable.Raw tmp = null; } : ( c=cident { tmp = c; } + | K_COUNT '(' countArgument ')' { tmp = new Selectable.WithFunction.Raw(FunctionName.nativeFunction("countRows"), Collections.emptyList());} | K_WRITETIME '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, true); } | K_TTL '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, false); } | f=functionName args=selectionFunctionArgs { tmp = new Selectable.WithFunction.Raw(f, args); } @@ -337,11 +337,6 @@ selectionFunctionArgs returns [List a] ')' { $a = args; } ; -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));} -; - countArgument : '\*' | i=INTEGER { if (!i.getText().equals("1")) addRecognitionError("Only COUNT(1) is supported, got COUNT(" + i.getText() + ")");} http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java -- diff --git a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java index 1b22da6..41e43c0 100644 --- a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java +++ b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java @@ -38,6 +38,17 @@ import org.apache.cassandra.db.marshal.ShortType; public abstract class AggregateFcts { /** + * Checks if the specified function is the count rows (e.g. COUNT(*) or COUNT(1)) function. + * + * @param function the function to check + * @return true if the specified function is the count rows one, false otherwise. + */ +public static boolean isCountRows(Function function) +{ +
[1/2] cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation
Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 be2c26f18 -> 1964a82bf Allow count(*) and count(1) to be use as normal aggregation patch by Benjamin Lerer; reviewed by Stefania Alborghetti for CASSANDRA-10114 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4fc58513 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4fc58513 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4fc58513 Branch: refs/heads/cassandra-3.0 Commit: 4fc58513dce5ee6acb83ba07d9f31c26812075f9 Parents: 62fc314 Author: blerer Authored: Thu Aug 20 14:01:37 2015 +0200 Committer: blerer Committed: Thu Aug 20 14:01:37 2015 +0200 -- NEWS.txt| 1 + src/java/org/apache/cassandra/cql3/Cql.g| 9 + .../cassandra/cql3/functions/AggregateFcts.java | 11 ++ .../selection/AbstractFunctionSelector.java | 6 +++ .../cassandra/cql3/selection/Selector.java | 1 - .../validation/operations/AggregationTest.java | 39 6 files changed, 59 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/NEWS.txt -- diff --git a/NEWS.txt b/NEWS.txt index 37a1b9e..a9cf70d 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -100,6 +100,7 @@ New features - The toTimestamp(date) and toUnixTimestamp(date) functions have been added to allow to convert from date into timestamp type and bigint raw value. - SizeTieredCompactionStrategy parameter cold_reads_to_omit has been removed. + - COUNT(*) and COUNT(1) can be selected with other columns or functions 2.1.9 http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/Cql.g -- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index 0db09b8..3d2aba5 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -295,8 +295,7 @@ selectStatement returns [SelectStatement.RawStatement expr] } : K_SELECT ( K_JSON { isJson = true; } )? - ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause -| sclause=selectCountClause ) + ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause ) K_FROM cf=columnFamilyName ( K_WHERE wclause=whereClause )? ( K_ORDER K_BY orderByClause[orderings] ( ',' orderByClause[orderings] )* )? @@ -324,6 +323,7 @@ selector returns [RawSelector s] unaliasedSelector returns [Selectable.Raw s] @init { Selectable.Raw tmp = null; } : ( c=cident { tmp = c; } + | K_COUNT '(' countArgument ')' { tmp = new Selectable.WithFunction.Raw(FunctionName.nativeFunction("countRows"), Collections.emptyList());} | K_WRITETIME '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, true); } | K_TTL '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, false); } | f=functionName args=selectionFunctionArgs { tmp = new Selectable.WithFunction.Raw(f, args); } @@ -337,11 +337,6 @@ selectionFunctionArgs returns [List a] ')' { $a = args; } ; -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));} -; - countArgument : '\*' | i=INTEGER { if (!i.getText().equals("1")) addRecognitionError("Only COUNT(1) is supported, got COUNT(" + i.getText() + ")");} http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java -- diff --git a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java index 1b22da6..41e43c0 100644 --- a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java +++ b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java @@ -38,6 +38,17 @@ import org.apache.cassandra.db.marshal.ShortType; public abstract class AggregateFcts { /** + * Checks if the specified function is the count rows (e.g. COUNT(*) or COUNT(1)) function. + * + * @param function the function to check + * @return true if the specified function is the count rows one, false otherwise. + */ +public static boolean isCountRows(Function fun
cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation
Repository: cassandra Updated Branches: refs/heads/cassandra-2.2 62fc314c5 -> 4fc58513d Allow count(*) and count(1) to be use as normal aggregation patch by Benjamin Lerer; reviewed by Stefania Alborghetti for CASSANDRA-10114 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4fc58513 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4fc58513 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4fc58513 Branch: refs/heads/cassandra-2.2 Commit: 4fc58513dce5ee6acb83ba07d9f31c26812075f9 Parents: 62fc314 Author: blerer Authored: Thu Aug 20 14:01:37 2015 +0200 Committer: blerer Committed: Thu Aug 20 14:01:37 2015 +0200 -- NEWS.txt| 1 + src/java/org/apache/cassandra/cql3/Cql.g| 9 + .../cassandra/cql3/functions/AggregateFcts.java | 11 ++ .../selection/AbstractFunctionSelector.java | 6 +++ .../cassandra/cql3/selection/Selector.java | 1 - .../validation/operations/AggregationTest.java | 39 6 files changed, 59 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/NEWS.txt -- diff --git a/NEWS.txt b/NEWS.txt index 37a1b9e..a9cf70d 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -100,6 +100,7 @@ New features - The toTimestamp(date) and toUnixTimestamp(date) functions have been added to allow to convert from date into timestamp type and bigint raw value. - SizeTieredCompactionStrategy parameter cold_reads_to_omit has been removed. + - COUNT(*) and COUNT(1) can be selected with other columns or functions 2.1.9 http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/Cql.g -- diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g index 0db09b8..3d2aba5 100644 --- a/src/java/org/apache/cassandra/cql3/Cql.g +++ b/src/java/org/apache/cassandra/cql3/Cql.g @@ -295,8 +295,7 @@ selectStatement returns [SelectStatement.RawStatement expr] } : K_SELECT ( K_JSON { isJson = true; } )? - ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause -| sclause=selectCountClause ) + ( ( K_DISTINCT { isDistinct = true; } )? sclause=selectClause ) K_FROM cf=columnFamilyName ( K_WHERE wclause=whereClause )? ( K_ORDER K_BY orderByClause[orderings] ( ',' orderByClause[orderings] )* )? @@ -324,6 +323,7 @@ selector returns [RawSelector s] unaliasedSelector returns [Selectable.Raw s] @init { Selectable.Raw tmp = null; } : ( c=cident { tmp = c; } + | K_COUNT '(' countArgument ')' { tmp = new Selectable.WithFunction.Raw(FunctionName.nativeFunction("countRows"), Collections.emptyList());} | K_WRITETIME '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, true); } | K_TTL '(' c=cident ')' { tmp = new Selectable.WritetimeOrTTL.Raw(c, false); } | f=functionName args=selectionFunctionArgs { tmp = new Selectable.WithFunction.Raw(f, args); } @@ -337,11 +337,6 @@ selectionFunctionArgs returns [List a] ')' { $a = args; } ; -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));} -; - countArgument : '\*' | i=INTEGER { if (!i.getText().equals("1")) addRecognitionError("Only COUNT(1) is supported, got COUNT(" + i.getText() + ")");} http://git-wip-us.apache.org/repos/asf/cassandra/blob/4fc58513/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java -- diff --git a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java index 1b22da6..41e43c0 100644 --- a/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java +++ b/src/java/org/apache/cassandra/cql3/functions/AggregateFcts.java @@ -38,6 +38,17 @@ import org.apache.cassandra.db.marshal.ShortType; public abstract class AggregateFcts { /** + * Checks if the specified function is the count rows (e.g. COUNT(*) or COUNT(1)) function. + * + * @param function the function to check + * @return true if the specified function is the count rows one, false otherwise. + */ +public static boolean isCountRows(Function fun