You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/11/15 06:55:42 UTC

[groovy] branch master updated (0666530 -> e058092)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 0666530  Minor tweak: Support `avg` aggregate function in GINQ
     new 35350f9  Tweak error message
     new e058092  Trivial tweak: validate the order of `limit`, `groupby` and `orderby`

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/groovy/ginq/dsl/GinqAstBuilder.java | 14 +++++++++-
 .../provider/collection/runtime/Queryable.java     |  2 +-
 .../org/apache/groovy/ginq/GinqErrorTest.groovy    | 30 +++++++++++++++++++++-
 3 files changed, 43 insertions(+), 3 deletions(-)


[groovy] 02/02: Trivial tweak: validate the order of `limit`, `groupby` and `orderby`

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e058092e242b8346add308a54711e287541c39df
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 15 14:55:17 2020 +0800

    Trivial tweak: validate the order of `limit`, `groupby` and `orderby`
---
 .../org/apache/groovy/ginq/dsl/GinqAstBuilder.java | 12 ++++++++++
 .../org/apache/groovy/ginq/GinqErrorTest.groovy    | 28 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
index 815f66d..0cbcc31 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
@@ -223,6 +223,11 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
                         "The clause `" + methodName + "` should be in front of `orderby`",
                         call.getLineNumber(), call.getColumnNumber()
                 ));
+            } else if (latestGinqExpressionClause instanceof LimitExpression) {
+                this.collectSyntaxError(new GinqSyntaxError(
+                        "The clause `" + methodName + "` should be in front of `limit`",
+                        call.getLineNumber(), call.getColumnNumber()
+                ));
             }
 
             if (latestGinqExpressionClause instanceof DataSourceHolder) {
@@ -239,6 +244,13 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
 
             currentGinqExpression.setOrderExpression(orderExpression);
 
+            if (latestGinqExpressionClause instanceof LimitExpression) {
+                this.collectSyntaxError(new GinqSyntaxError(
+                        "The clause `" + methodName + "` should be in front of `limit`",
+                        call.getLineNumber(), call.getColumnNumber()
+                ));
+            }
+
             if (latestGinqExpressionClause instanceof DataSourceHolder) {
                 orderExpression.setDataSourceExpression(((DataSourceHolder) latestGinqExpressionClause).getDataSourceExpression());
             }
diff --git a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
index 56b01bc..63b954b 100644
--- a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
+++ b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
@@ -168,6 +168,34 @@ class GinqErrorTest {
     }
 
     @Test
+    void "testGinq - from limit orderby - 1"() {
+        def err = shouldFail '''\
+            GQ {
+                from n in [1, 2, 3]
+                limit 1
+                orderby n
+                select n
+            }
+        '''
+
+        assert err.toString().contains('The clause `orderby` should be in front of `limit` @ line 4, column 17.')
+    }
+
+    @Test
+    void "testGinq - from limit groupby - 1"() {
+        def err = shouldFail '''\
+            GQ {
+                from n in [1, 2, 3]
+                limit 1
+                groupby n
+                select n
+            }
+        '''
+
+        assert err.toString().contains('The clause `groupby` should be in front of `limit` @ line 4, column 17.')
+    }
+
+    @Test
     void "testGinq - from groupby select - 1"() {
         def err = shouldFail '''
             @groovy.transform.EqualsAndHashCode


[groovy] 01/02: Tweak error message

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 35350f9aa03caf181752486ea829af85ffa22560
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Nov 15 14:42:20 2020 +0800

    Tweak error message
---
 .../src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java      | 2 +-
 .../org/apache/groovy/ginq/provider/collection/runtime/Queryable.java   | 2 +-
 .../src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy         | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
index 08611c1..815f66d 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/dsl/GinqAstBuilder.java
@@ -220,7 +220,7 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
 
             if (latestGinqExpressionClause instanceof OrderExpression) {
                 this.collectSyntaxError(new GinqSyntaxError(
-                        "The preceding clause of `" + methodName + "` should not be `orderby`",
+                        "The clause `" + methodName + "` should be in front of `orderby`",
                         call.getLineNumber(), call.getColumnNumber()
                 ));
             }
diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
index ff1aaea..57d3298 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
@@ -295,7 +295,7 @@ public interface Queryable<T> {
      * Aggregate function {@code avg}, similar to SQL's {@code avg}
      *
      * @param mapper choose the field to calculate the average
-     * @return sum result
+     * @return avg result
      * @since 4.0.0
      */
     BigDecimal avg(Function<? super T, ? extends Number> mapper);
diff --git a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
index ea69ad7..56b01bc 100644
--- a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
+++ b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/GinqErrorTest.groovy
@@ -231,6 +231,6 @@ class GinqErrorTest {
             }.toList()
         '''
 
-        assert err.toString().contains("The preceding clause of `groupby` should not be `orderby` @ line 4, column 17.")
+        assert err.toString().contains("The clause `groupby` should be in front of `orderby` @ line 4, column 17.")
     }
 }