Skip to content

Commit

Permalink
feat(grammar): Support COLLECT function
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 26, 2024
1 parent 0e8bde4 commit 3689350
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1166,9 +1166,6 @@
"COLLATE-Operator-0.sql": [
4
],
"COLLECT-1.sql": [
5
],
"COLUMN_VALUE-Pseudocolumn-4.sql": [
7
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@
"source/check_object_grants.sql": [
8
],
"source/core/annotations/ut_annotation_cache_manager.pkb": [
19,
56,
84,
106,
106
],
"source/core/annotations/ut_annotation_cache_manager.pks": [
27,
35,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"source/core/annotations/ut_annotation_cache_info.sql": [
22
],
"source/core/annotations/ut_annotation_cache_manager.pkb": [
94
],
"source/core/coverage/ut_coverage_sources_tmp.sql": [
24
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"source/core/annotations/ut_annotation_cache_manager.pkb": [
24,
36,
60,
63,
99,
101
],
"source/core/coverage/ut_coverage_helper.pkb": [
69,
80
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"old_tests/ut_reporters/ut_documentation_reporter.reportTestTiming.sql": [
22
],
"source/core/annotations/ut_annotation_cache_manager.pkb": [
21
],
"source/core/coverage/ut_coverage_helper_block.pkb": [
46
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class AggregateSqlFunctionsGrammar : GrammarRuleKey {

LISTAGG_EXPRESSION,
XMLAGG_EXPRESSION,
COLLECT_EXPRESSION,
AGGREGATE_SQL_FUNCTION;

companion object {
Expand All @@ -49,7 +50,21 @@ enum class AggregateSqlFunctionsGrammar : GrammarRuleKey {
RPARENTHESIS
)

b.rule(AGGREGATE_SQL_FUNCTION).define(b.firstOf(LISTAGG_EXPRESSION, XMLAGG_EXPRESSION))
b.rule(COLLECT_EXPRESSION).define(
COLLECT, LPARENTHESIS,
b.optional(b.firstOf(DISTINCT, UNIQUE)),
EXPRESSION,
b.optional(ORDER, BY, EXPRESSION),
RPARENTHESIS
)

b.rule(AGGREGATE_SQL_FUNCTION).define(
b.firstOf(
LISTAGG_EXPRESSION,
XMLAGG_EXPRESSION,
COLLECT_EXPRESSION
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Z PL/SQL Analyzer
* Copyright (C) 2015-2024 Felipe Zorzo
* mailto:felipe AT felipezorzo DOT com DOT br
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.plsqlopen.api.expressions

import com.felipebz.flr.tests.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import org.sonar.plugins.plsqlopen.api.RuleTest

class CollectExpressionTest : RuleTest() {

@BeforeEach
fun init() {
setRootRule(PlSqlGrammar.EXPRESSION)
}

@Test
fun matchesSimpleCollect() {
assertThat(p).matches("collect(foo)")
}

@Test
fun matchesCollectWithDistinct() {
assertThat(p).matches("collect(distinct foo)")
}

@Test
fun matchesCollectWithUnique() {
assertThat(p).matches("collect(unique foo)")
}

@Test
fun matchesCollectWithDistinctAndOrderBy() {
assertThat(p).matches("collect(distinct foo order by bar)")
}

}

0 comments on commit 3689350

Please sign in to comment.