cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2499 Support for COUNT(DISTINCT(column)) function aggregate - correct @since version - missing distinct() in parser
Date Mon, 17 Dec 2018 09:15:57 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 54b3f8110 -> 4724ab3f9


CAY-2499 Support for COUNT(DISTINCT(column)) function aggregate
 - correct @since version
 - missing distinct() in parser


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/4724ab3f
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/4724ab3f
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/4724ab3f

Branch: refs/heads/master
Commit: 4724ab3f97869620397e8801f97f9b88be8d972d
Parents: 54b3f81
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Dec 13 14:11:51 2018 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Dec 13 14:11:51 2018 +0300

----------------------------------------------------------------------
 .../apache/cayenne/exp/FunctionExpressionFactory.java |  1 +
 .../main/java/org/apache/cayenne/exp/Property.java    |  1 +
 .../org/apache/cayenne/exp/parser/ASTDistinct.java    |  2 +-
 .../apache/cayenne/exp/parser/ExpressionParser.java   |  5 ++++-
 .../apache/cayenne/exp/parser/ExpressionParser.jjt    |  2 +-
 .../apache/cayenne/exp/parser/ASTAggregateTest.java   | 14 ++++++++++++++
 6 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/main/java/org/apache/cayenne/exp/FunctionExpressionFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/FunctionExpressionFactory.java
b/cayenne-server/src/main/java/org/apache/cayenne/exp/FunctionExpressionFactory.java
index 7c3c980..4818f7b 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/FunctionExpressionFactory.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/FunctionExpressionFactory.java
@@ -326,6 +326,7 @@ public class FunctionExpressionFactory {
     
     /**
      * @return Expression COUNT(DISTINCT(exp))
+     * @since 4.1
      */
     public static Expression countDistinctExp(Expression exp) {
         return new ASTCount(new ASTDistinct(exp));

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
index 4df67b1..449934c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
@@ -646,6 +646,7 @@ public class Property<E> {
     
     /**
      * @see FunctionExpressionFactory#countDistinctExp(Expression)
+     * @since 4.1
      */
     public Property<Long> countDistinct() {
         return create(FunctionExpressionFactory.countDistinctExp(getExpression()), Long.class);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTDistinct.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTDistinct.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTDistinct.java
index 39088c3..63fed10 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTDistinct.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTDistinct.java
@@ -22,7 +22,7 @@ package org.apache.cayenne.exp.parser;
 import org.apache.cayenne.exp.Expression;
 
 /**
- * @since 4.0
+ * @since 4.1
  */
 public class ASTDistinct extends ASTAggregateFunctionCall {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
index cbab144..e644066 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
@@ -2157,6 +2157,9 @@ public class ExpressionParser/*@bgen(jjtree)*/implements ExpressionParserTreeCon
       case PROPERTY_PATH:
         pathExpression();
         break;
+      case DISTINCT:
+        distinct();
+        break;
       default:
         jj_la1[38] = jj_gen;
         jj_consume_token(-1);
@@ -2586,7 +2589,7 @@ public class ExpressionParser/*@bgen(jjtree)*/implements ExpressionParserTreeCon
       jj_la1_0 = new int[] {0x2,0x4,0x18,0x16010018,0x60,0x180,0x10000,0x4fff8,0x4fff8,0x16010000,0x18,0x10000,0x4e000,0x80000,0x16010000,0x0,0x0,0x16010000,0x0,0x100000,0x200000,0x400000,0x1800000,0x1800000,0x6000000,0x6000000,0x8000000,0x8000000,0x16010000,0x2000000,0x6010000,0x10000,0x0,0x80000,0x80000,0x0,0x80000,0x0,0x0,0x0,0x0,0x0,};
    }
    private static void jj_la1_init_1() {
-      jj_la1_1 = new int[] {0x0,0x0,0x0,0xfffffdfe,0x0,0x0,0x0,0x0,0x0,0xfffffdfe,0x0,0x0,0x0,0x0,0xfffffdf2,0x7c00,0x7c00,0xfffffdfe,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff8f8000,0x0,0xff8f8000,0xff8f8000,0x7c00,0x0,0x0,0xff8f8000,0x0,0x1f0,0x0,0x700000,0xff800000,0x0,};
+      jj_la1_1 = new int[] {0x0,0x0,0x0,0xfffffdfe,0x0,0x0,0x0,0x0,0x0,0xfffffdfe,0x0,0x0,0x0,0x0,0xfffffdf2,0x7c00,0x7c00,0xfffffdfe,0xc,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff8f8000,0x0,0xff8f8000,0xff8f8000,0x7c00,0x0,0x0,0xff8f8000,0x0,0x1f0,0x200,0x700000,0xff800000,0x0,};
    }
    private static void jj_la1_init_2() {
       jj_la1_2 = new int[] {0x0,0x0,0x0,0xe405f,0x0,0x0,0x2,0x0,0x0,0xe405f,0x0,0x2,0x0,0x0,0xe405f,0x2405c,0x24000,0xe405f,0xe4002,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20,0x20,0xc005f,0x0,0xc005f,0xc005f,0x0,0x0,0x0,0x1,0x0,0x0,0x7c,0x0,0x1,0x5c,};

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/main/jjtree/org/apache/cayenne/exp/parser/ExpressionParser.jjt
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/jjtree/org/apache/cayenne/exp/parser/ExpressionParser.jjt
b/cayenne-server/src/main/jjtree/org/apache/cayenne/exp/parser/ExpressionParser.jjt
index 8d40e1b..39dddea 100644
--- a/cayenne-server/src/main/jjtree/org/apache/cayenne/exp/parser/ExpressionParser.jjt
+++ b/cayenne-server/src/main/jjtree/org/apache/cayenne/exp/parser/ExpressionParser.jjt
@@ -354,7 +354,7 @@ void asterisk() #Asterisk : {}
 
 void count() #Count : { }
 {
-	<COUNT> "(" ( asterisk() | pathExpression() ) ")"
+	<COUNT> "(" ( asterisk() | pathExpression() | distinct() ) ")"
 }
 
 void avg() #Avg : { }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/4724ab3f/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
index f6e57c3..5a832ff 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTAggregateTest.java
@@ -84,6 +84,20 @@ public class ASTAggregateTest {
     }
 
     @Test
+    public void testCountDistinctParse() throws Exception {
+        String expressionString = "count(distinct(artistName))";
+        Expression exp = ExpressionFactory.exp(expressionString);
+        assertTrue(exp instanceof ASTCount);
+        assertEquals(1, exp.getOperandCount());
+        assertTrue(exp.getOperand(0) instanceof ASTDistinct);
+
+        ASTDistinct distinct = (ASTDistinct)exp.getOperand(0);
+        assertTrue(distinct.getOperand(0) instanceof ASTObjPath);
+
+        assertEquals(expressionString, exp.toString());
+    }
+
+    @Test
     public void testMinConstruct() throws Exception {
         ASTMin min = new ASTMin(null);
         assertEquals("MIN", min.getFunctionName());


Mime
View raw message