You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by vl...@apache.org on 2019/12/15 17:05:11 UTC
[calcite] branch master updated: SqlValidatorMatchTest: Java ->
Kotlin
This is an automated email from the ASF dual-hosted git repository.
vladimirsitnikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new b93ec5a SqlValidatorMatchTest: Java -> Kotlin
b93ec5a is described below
commit b93ec5a9edb7459696385e6adad67b92b6d406d7
Author: Vladimir Sitnikov <si...@gmail.com>
AuthorDate: Sun Dec 15 16:08:43 2019 +0300
SqlValidatorMatchTest: Java -> Kotlin
---
.../apache/calcite/test/SqlValidatorMatchTest.java | 248 -----------------
.../apache/calcite/test/SqlValidatorMatchTest.kt | 297 +++++++++++++++++++++
2 files changed, 297 insertions(+), 248 deletions(-)
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.java
deleted file mode 100644
index 07387c2..0000000
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * 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.
- */
-package org.apache.calcite.test;
-
-import org.junit.jupiter.api.Test;
-
-/**
- * Validation tests for the {@code MATCH_RECOGNIZE} clause.
- */
-public class SqlValidatorMatchTest extends SqlValidatorTestCase {
- /** Tries to create a calls to some internal operators in
- * MATCH_RECOGNIZE. Should fail. */
- @Test public void testMatchRecognizeInternals() throws Exception {
- sql("values ^pattern_exclude(1, 2)^")
- .fails("No match found for function signature .*");
- sql("values ^\"|\"(1, 2)^")
- .fails("No match found for function signature .*");
- // FINAL and other functions should not be visible outside of
- // MATCH_RECOGNIZE
- sql("values ^\"FINAL\"(1, 2)^")
- .fails("No match found for function signature FINAL\\(<NUMERIC>, <NUMERIC>\\)");
- sql("values ^\"RUNNING\"(1, 2)^")
- .fails("No match found for function signature RUNNING\\(<NUMERIC>, <NUMERIC>\\)");
- sql("values ^\"FIRST\"(1, 2)^")
- .fails("Function 'FIRST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
- sql("values ^\"LAST\"(1, 2)^")
- .fails("Function 'LAST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
- sql("values ^\"PREV\"(1, 2)^")
- .fails("Function 'PREV\\(1, 2\\)' can only be used in MATCH_RECOGNIZE");
- }
-
- @Test public void testMatchRecognizeDefines() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > PREV(up.sal)\n"
- + " ) mr";
- sql(sql).ok();
- }
-
- @Test public void testMatchRecognizeDefines2() throws Exception {
- final String sql = "select *\n"
- + " from t match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.price < PREV(down.price),\n"
- + " ^down as up.price > PREV(up.price)^\n"
- + " ) mr";
- sql(sql).fails("Pattern variable 'DOWN' has already been defined");
- }
-
- @Test public void testMatchRecognizeDefines3() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " pattern (strt down+up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > PREV(up.sal)\n"
- + " ) mr";
- sql(sql).ok();
- }
-
- @Test public void testMatchRecognizeDefines4() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > FIRST(^PREV(up.sal)^)\n"
- + " ) mr";
- sql(sql)
- .fails("Cannot nest PREV/NEXT under LAST/FIRST 'PREV\\(`UP`\\.`SAL`, 1\\)'");
- }
-
- @Test public void testMatchRecognizeDefines5() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > FIRST(^FIRST(up.sal)^)\n"
- + " ) mr";
- sql(sql)
- .fails("Cannot nest PREV/NEXT under LAST/FIRST 'FIRST\\(`UP`\\.`SAL`, 0\\)'");
- }
-
- @Test public void testMatchRecognizeDefines6() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > ^COUNT(down.sal, up.sal)^\n"
- + " ) mr";
- sql(sql)
- .fails("Invalid number of parameters to COUNT method");
- }
-
- @Test public void testMatchRecognizeMeasures1() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " measures STRT.sal as start_sal,"
- + " ^LAST(null)^ as bottom_sal,"
- + " LAST(up.ts) as end_sal"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Null parameters in 'LAST\\(NULL, 0\\)'");
- }
-
- @Test public void testMatchRecognizeSkipTo1() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " after match skip to ^null^\n"
- + " measures\n"
- + " STRT.sal as start_sal,\n"
- + " LAST(up.ts) as end_sal\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("(?s).*Encountered \"null\" at .*");
- }
-
- @Test public void testMatchRecognizeSkipTo2() throws Exception {
- final String sql = "select *\n"
- + " from emp match_recognize (\n"
- + " after match skip to ^no_exists^\n"
- + " measures\n"
- + " STRT.sal as start_sal,"
- + " LAST(up.ts) as end_sal"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("(?s).*Encountered \"measures\" at .*");
- }
-
- @Test public void testMatchRecognizeSkipTo3() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " measures\n"
- + " STRT.sal as start_sal,\n"
- + " LAST(up.sal) as end_sal\n"
- + " after match skip to ^no_exists^\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Unknown pattern 'NO_EXISTS'");
- }
-
- @Test public void testMatchRecognizeSkipToCaseInsensitive() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " measures\n"
- + " STRT.sal as start_sal,\n"
- + " LAST(up.sal) as end_sal\n"
- + " after match skip to ^\"strt\"^\n"
- + " pattern (strt down+ up+)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Unknown pattern 'strt'");
- sql(sql)
- .withCaseSensitive(false)
- .sansCarets()
- .ok();
- }
-
- @Test public void testMatchRecognizeSubset() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " subset stdn = (^strt1^, down)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Unknown pattern 'STRT1'");
- }
-
- @Test public void testMatchRecognizeSubset2() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " pattern (strt down+ up+)\n"
- + " subset ^strt^ = (strt, down)\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Pattern variable 'STRT' has already been defined");
- }
-
- @Test public void testMatchRecognizeWithin() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " pattern (strt down+ up+) within ^interval '3:10' minute to second^\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("Must contain an ORDER BY clause when WITHIN is used");
- }
-
- @Test public void testMatchRecognizeWithin2() throws Exception {
- final String sql = "select *\n"
- + "from emp match_recognize (\n"
- + " order by sal\n"
- + " pattern (strt down+ up+) within ^interval '3:10' minute to second^\n"
- + " define\n"
- + " down as down.sal < PREV(down.sal),\n"
- + " up as up.sal > prev(up.sal)\n"
- + " ) mr";
- sql(sql)
- .fails("First column of ORDER BY must be of type TIMESTAMP");
- }
-}
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.kt b/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.kt
new file mode 100644
index 0000000..0c331c8
--- /dev/null
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorMatchTest.kt
@@ -0,0 +1,297 @@
+/*
+ * 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.
+ */
+package org.apache.calcite.test
+
+import org.junit.jupiter.api.Test
+
+/**
+ * Validation tests for the `MATCH_RECOGNIZE` clause.
+ */
+class SqlValidatorMatchTest : SqlValidatorTestCase() {
+ /** Tries to create a calls to some internal operators in
+ * MATCH_RECOGNIZE. Should fail. */
+ @Test
+ fun `match recognize internals`() {
+ sql("values ^pattern_exclude(1, 2)^")
+ .fails("No match found for function signature .*")
+ sql("values ^\"|\"(1, 2)^")
+ .fails("No match found for function signature .*")
+ // FINAL and other functions should not be visible outside of
+ // MATCH_RECOGNIZE
+ sql("values ^\"FINAL\"(1, 2)^")
+ .fails("No match found for function signature FINAL\\(<NUMERIC>, <NUMERIC>\\)")
+ sql("values ^\"RUNNING\"(1, 2)^")
+ .fails("No match found for function signature RUNNING\\(<NUMERIC>, <NUMERIC>\\)")
+ sql("values ^\"FIRST\"(1, 2)^")
+ .fails("Function 'FIRST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE")
+ sql("values ^\"LAST\"(1, 2)^")
+ .fails("Function 'LAST\\(1, 2\\)' can only be used in MATCH_RECOGNIZE")
+ sql("values ^\"PREV\"(1, 2)^")
+ .fails("Function 'PREV\\(1, 2\\)' can only be used in MATCH_RECOGNIZE")
+ }
+
+ @Test
+ fun `match recognize defines`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > PREV(up.sal)
+ ) mr
+ """.trimIndent()
+ ).ok()
+ }
+
+ @Test
+ fun `match recognize defines2`() {
+ sql(
+ """
+ select *
+ from t match_recognize (
+ pattern (strt down+ up+)
+ define
+ down as down.price < PREV(down.price),
+ ^down as up.price > PREV(up.price)^
+ ) mr
+ """.trimIndent()
+ ).fails("Pattern variable 'DOWN' has already been defined")
+ }
+
+ @Test
+ fun `match recognize defines3`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > PREV(up.sal)
+ ) mr
+ """.trimIndent()
+ ).ok()
+ }
+
+ @Test
+ fun `match recognize defines4`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > FIRST(^PREV(up.sal)^)
+ ) mr
+ """.trimIndent()
+ ).fails("Cannot nest PREV/NEXT under LAST/FIRST 'PREV\\(`UP`\\.`SAL`, 1\\)'")
+ }
+
+ @Test
+ fun `match recognize defines5`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > FIRST(^FIRST(up.sal)^)
+ ) mr
+ """.trimIndent()
+ ).fails("Cannot nest PREV/NEXT under LAST/FIRST 'FIRST\\(`UP`\\.`SAL`, 0\\)'")
+ }
+
+ @Test
+ fun `match recognize defines6`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > ^COUNT(down.sal, up.sal)^
+ ) mr
+ """.trimIndent()
+ ).fails("Invalid number of parameters to COUNT method")
+ }
+
+ @Test
+ fun `match recognize measures1`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ measures
+ STRT.sal as start_sal,
+ ^LAST(null)^ as bottom_sal,
+ LAST(up.ts) as end_sal
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Null parameters in 'LAST\\(NULL, 0\\)'")
+ }
+
+ @Test
+ fun `match recognize skip to1`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ after match skip to ^null^
+ measures
+ STRT.sal as start_sal,
+ LAST(up.ts) as end_sal
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("(?s).*Encountered \"null\" at .*")
+ }
+
+ @Test
+ fun `match recognize skip to2`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ after match skip to ^no_exists^
+ measures
+ STRT.sal as start_sal,
+ LAST(up.ts) as end_sal
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("(?s).*Encountered \"measures\" at .*")
+ }
+
+ @Test
+ fun `match recognize skip to3`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ measures
+ STRT.sal as start_sal,
+ LAST(up.sal) as end_sal
+ after match skip to ^no_exists^
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Unknown pattern 'NO_EXISTS'")
+ }
+
+ @Test
+ fun `match recognize skip to case insensitive`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ measures
+ STRT.sal as start_sal,
+ LAST(up.sal) as end_sal
+ after match skip to ^"strt"^
+ pattern (strt down+ up+)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Unknown pattern 'strt'")
+ .withCaseSensitive(false)
+ .sansCarets()
+ .ok()
+ }
+
+ @Test
+ fun `match recognize subset`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ subset stdn = (^strt1^, down)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Unknown pattern 'STRT1'")
+ }
+
+ @Test
+ fun `match recognize subset2`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+)
+ subset ^strt^ = (strt, down)
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Pattern variable 'STRT' has already been defined")
+ }
+
+ @Test
+ fun `match recognize within`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ pattern (strt down+ up+) within ^interval '3:10' minute to second^
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("Must contain an ORDER BY clause when WITHIN is used")
+ }
+
+ @Test
+ fun `match recognize within2`() {
+ sql(
+ """
+ select *
+ from emp match_recognize (
+ order by sal
+ pattern (strt down+ up+) within ^interval '3:10' minute to second^
+ define
+ down as down.sal < PREV(down.sal),
+ up as up.sal > prev(up.sal)
+ ) mr
+ """.trimIndent()
+ ).fails("First column of ORDER BY must be of type TIMESTAMP")
+ }
+}