<commit_before>//////////////////////////////////////////

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.

//////////////////////////////////////////

= Querying collections in a SQL-like style

Groovy's `groovy-ginq` module provides a higher-level abstraction over collections.
Also, querying XML, JSON, YAML, etc. could be supported by GINQ too because they can be parsed into collections.
As GORM and Hibernate are powerful enough to support DB populating, we will cover collections first.

== GINQ a.k.a. Groovy-Integrated Query

GINQ is a DSL for querying, which consists of the following structure:
```sql
GINQ
|__ from
|__ [innerjoin/leftjoin/rightjoin/fulljoin/crossjoin]*
|   |__ on (Note: `crossjoin` does not need the `on` clause)
|__ [where]
|__ [groupby]
|   |__ [having]
|__ [orderby]
|__ [limit]
|__ select
```
[NOTE]
`[]` means the related clause is optional. Also, the clauses of GINQ are order sensitive,
so the order of clauses should be kept as the above structure

As we could see, the simplest GINQ consists of a `from` clause and a `select` clause, which looks like:
[source, sql]
----
include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_simplest,indent=0]
----

As a DSL, GINQ should be wrapped with the following block to be executed:
```groovy
GQ { /* GINQ CODE */ }
```
For example,
[source, sql]<commit_msg>Tweak doco<commit_after>//////////////////////////////////////////

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.

//////////////////////////////////////////

= Querying collections in a SQL-like style

Groovy's `groovy-ginq` module provides a higher-level abstraction over collections.
It could perform queries against in-memory collections of objects in a SQL-like style.
Also, querying XML, JSON, YAML, etc. could be also supported because they can be parsed into collections.
As GORM and jOOQ are powerful enough to support querying DB, we will cover collections first.

== GINQ a.k.a. Groovy-Integrated Query

GINQ is a DSL for querying with SQL-like syntax, which consists of the following structure:
```sql
GINQ
|__ from
|__ [innerjoin/leftjoin/rightjoin/fulljoin/crossjoin]*
|   |__ on (Note: `crossjoin` does not need the `on` clause)
|__ [where]
|__ [groupby]
|   |__ [having]
|__ [orderby]
|__ [limit]
|__ select
```
[NOTE]
`[]` means the related clause is optional. Also, the clauses of GINQ are order sensitive,
so the order of clauses should be kept as the above structure

As we could see, the simplest GINQ consists of a `from` clause and a `select` clause, which looks like:
[source, sql]
----
include::../test/org/apache/groovy/ginq/GinqTest.groovy[tags=ginq_simplest,indent=0]
----
[NOTE]
__ONLY ONE__ `from` clause is required in GINQ. Also, GINQ supports multiple data sources through `from` and the related joins.

As a DSL, GINQ should be wrapped with the following block to be executed:
```groovy
GQ { /* GINQ CODE */ }
```
For example,
[source, sql]
{'fraction_non_alphanumeric': 0.11260236578707916, 'fraction_numerical': 0.0022747952684258415, 'mean_word_length': 3.4549138804457953, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4150549', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1197, 'n_words': 573}