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 2022/04/11 19:10:16 UTC

[groovy] branch GROOVY_4_0_X updated: Add one more test case for GINQ

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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 4533a7b303 Add one more test case for GINQ
4533a7b303 is described below

commit 4533a7b303e9cfe3cd37a7d16a813b2b28155852
Author: Daniel Sun <su...@apache.org>
AuthorDate: Tue Apr 12 02:53:36 2022 +0800

    Add one more test case for GINQ
    
    (cherry picked from commit 5e939022d01dfbe55c78b8610f545be8bdc3985d)
---
 subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc    |  4 ++++
 .../src/spec/test/org/apache/groovy/ginq/GinqTest.groovy    | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
index afe44b2de2..6138cc9519 100644
--- a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
+++ b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
@@ -431,6 +431,10 @@ include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_03,in
 `_g` is an implicit variable for `agg` aggregate function,
 it represents the grouped `Queryable` object and its record(e.g. `r`) could reference the data source by alias(e.g. `n`)
 
+[source, sql]
+----
+include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_13,indent=0]
+----
 
 Also, we could apply the aggregate functions for the whole GINQ result, i.e. no `groupby` clause is needed:
 [source, groovy]
diff --git a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
index 03b1ba00f1..2c491f9dc0 100644
--- a/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
+++ b/subprojects/groovy-ginq/src/spec/test/org/apache/groovy/ginq/GinqTest.groovy
@@ -3005,6 +3005,19 @@ class GinqTest {
         '''
     }
 
+    @Test
+    void "testGinq - from groupby select - 31"() {
+        assertGinqScript '''
+            assert [['A', ['Apple', 'Apricot']], ['B', ['Banana']], ['C', ['Cantaloupe']]] == GQ {
+// tag::ginq_grouping_13[]
+                from fruit in ['Apple', 'Apricot', 'Banana', 'Cantaloupe']
+                groupby fruit.substring(0, 1) as firstChar
+                select firstChar, agg(_g.stream().map(r -> r.fruit).toList()) as fruit_list
+// end::ginq_grouping_13[]
+            }.toList()
+        '''
+    }
+
     @Test
     void "testGinq - from where groupby select - 1"() {
         assertGinqScript '''