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/04 09:34:09 UTC

[groovy] branch GROOVY-8258 updated: GROOVY-8258: add more aggregate function examples in the doco

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

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


The following commit(s) were added to refs/heads/GROOVY-8258 by this push:
     new f3adf96  GROOVY-8258: add more aggregate function examples in the doco
f3adf96 is described below

commit f3adf96622fa004d6b32c7f44ca9b55f3cfb5a01
Author: Daniel Sun <su...@apache.org>
AuthorDate: Wed Nov 4 17:33:56 2020 +0800

    GROOVY-8258: add more aggregate function examples in the doco
---
 subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc  | 15 +++++++++++++++
 .../src/spec/test/org/apache/groovy/ginq/GinqTest.groovy  |  7 ++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
index 3297c45..998dce5 100644
--- a/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
+++ b/subprojects/groovy-ginq/src/spec/doc/ginq-userguide.adoc
@@ -108,6 +108,21 @@ include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_01,in
 include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_02,indent=0]
 ----
 
+[source, sql]
+----
+include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_04,indent=0]
+----
+
+`_g` is an implicit variable representing the grouped `Queryable` object:
+[source, sql]
+----
+include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_grouping_03,indent=0]
+----
+
+[NOTE]
+GINQ supports some built-in aggregate functions, e.g.
+`count`, `sum`, `max`, `min` and the most powerful one `agg`
+
 === Sorting
 [source, sql]
 ----
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 de6c30c..8a7c905 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
@@ -1669,9 +1669,11 @@ class GinqTest {
     void "testGinq - from groupby select - 2"() {
         assertScript '''
             assert [[1, 2], [3, 6], [6, 18]] == GQ {
+// tag::ginq_grouping_04[]
                 from n in [1, 1, 3, 3, 6, 6, 6]
                 groupby n
                 select n, sum(n)
+// end::ginq_grouping_04[]
             }.toList()
         '''
     }
@@ -1779,10 +1781,13 @@ class GinqTest {
     @Test
     void "testGinq - from groupby select - 7"() {
         assertScript '''
+            // `agg` is the most powerful aggregate function, `_g` represents the grouped Queryable object
             assert [[1, 2], [3, 6], [6, 18]] == GQ {
+// tag::ginq_grouping_03[]
                 from n in [1, 1, 3, 3, 6, 6, 6]
                 groupby n
-                select n, agg(_g.stream().map(r -> r.n).reduce(BigDecimal.ZERO, BigDecimal::add)) // the most powerful aggregate function, `_g` represents the grouped Queryable object
+                select n, agg(_g.stream().map(r -> r.n).reduce(BigDecimal.ZERO, BigDecimal::add))
+// end::ginq_grouping_03[]
             }.toList()
         '''
     }