cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation

2015-08-20 Thread blerer
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 benjamin.le...@datastax.com
Authored: Thu Aug 20 14:01:37 2015 +0200
Committer: blerer benjamin.le...@datastax.com
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.Selectable.RawemptyList());}
| 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 [ListSelectable.Raw a]
   ')' { $a = args; }
 ;
 
-selectCountClause returns [ListRawSelector expr]
-@init{ ColumnIdentifier alias = new ColumnIdentifier(count, false); }
-: K_COUNT '(' countArgument ')' (K_AS c=ident { alias = c; })? { $expr = 
new ArrayListRawSelector(); $expr.add( new RawSelector(new 
Selectable.WithFunction.Raw(FunctionName.nativeFunction(countRows), 
Collections.Selectable.RawemptyList()), 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 codetrue/code if the 

[1/3] cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation

2015-08-20 Thread blerer
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 benjamin.le...@datastax.com
Authored: Thu Aug 20 14:01:37 2015 +0200
Committer: blerer benjamin.le...@datastax.com
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.Selectable.RawemptyList());}
| 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 [ListSelectable.Raw a]
   ')' { $a = args; }
 ;
 
-selectCountClause returns [ListRawSelector expr]
-@init{ ColumnIdentifier alias = new ColumnIdentifier(count, false); }
-: K_COUNT '(' countArgument ')' (K_AS c=ident { alias = c; })? { $expr = 
new ArrayListRawSelector(); $expr.add( new RawSelector(new 
Selectable.WithFunction.Raw(FunctionName.nativeFunction(countRows), 
Collections.Selectable.RawemptyList()), 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 codetrue/code if the specified function is 

[1/2] cassandra git commit: Allow count(*) and count(1) to be use as normal aggregation

2015-08-20 Thread blerer
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 benjamin.le...@datastax.com
Authored: Thu Aug 20 14:01:37 2015 +0200
Committer: blerer benjamin.le...@datastax.com
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.Selectable.RawemptyList());}
| 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 [ListSelectable.Raw a]
   ')' { $a = args; }
 ;
 
-selectCountClause returns [ListRawSelector expr]
-@init{ ColumnIdentifier alias = new ColumnIdentifier(count, false); }
-: K_COUNT '(' countArgument ')' (K_AS c=ident { alias = c; })? { $expr = 
new ArrayListRawSelector(); $expr.add( new RawSelector(new 
Selectable.WithFunction.Raw(FunctionName.nativeFunction(countRows), 
Collections.Selectable.RawemptyList()), 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 codetrue/code if the