You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by al...@apache.org on 2021/05/04 07:01:58 UTC
[ignite] branch sql-calcite updated: IGNITE-14552 Add "length"
function - Fixes #9025.
This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch sql-calcite
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/sql-calcite by this push:
new d2ee759 IGNITE-14552 Add "length" function - Fixes #9025.
d2ee759 is described below
commit d2ee7595de563ec4d7ec387262dcc02f3f8b9942
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Tue May 4 10:00:40 2021 +0300
IGNITE-14552 Add "length" function - Fixes #9025.
Signed-off-by: Aleksey Plekhanov <pl...@gmail.com>
---
modules/calcite/src/main/codegen/config.fmpp | 1 +
.../query/calcite/CalciteQueryProcessor.java | 18 ++++---
.../query/calcite/fun/IgniteSqlFunctions.java | 37 +++++++++++++++
.../processors/query/calcite/FunctionsTest.java | 55 ++++++++++++++++++++++
.../ignite/testsuites/IgniteCalciteTestSuite.java | 2 +
parent/pom.xml | 2 +-
6 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/modules/calcite/src/main/codegen/config.fmpp b/modules/calcite/src/main/codegen/config.fmpp
index 635bf1f..df0c7a8 100644
--- a/modules/calcite/src/main/codegen/config.fmpp
+++ b/modules/calcite/src/main/codegen/config.fmpp
@@ -306,6 +306,7 @@ data: {
"LEADING"
# "LEAVE" # not a keyword in Calcite
# "LEFT"
+ "LENGTH"
"LEVEL"
"LIKE"
"LIKE_REGEX"
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
index 9a52947..a0fe72d4 100644
--- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java
@@ -18,12 +18,13 @@
package org.apache.ignite.internal.processors.query.calcite;
import java.util.List;
-
import org.apache.calcite.config.Lex;
import org.apache.calcite.plan.Contexts;
+import org.apache.calcite.prepare.CalciteCatalogReader;
import org.apache.calcite.sql.fun.SqlLibrary;
import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory;
import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.util.SqlOperatorTables;
import org.apache.calcite.sql.validate.SqlConformanceEnum;
import org.apache.calcite.sql.validate.SqlValidator;
import org.apache.calcite.sql2rel.SqlToRelConverter;
@@ -45,6 +46,7 @@ import org.apache.ignite.internal.processors.query.calcite.exec.MailboxRegistry;
import org.apache.ignite.internal.processors.query.calcite.exec.MailboxRegistryImpl;
import org.apache.ignite.internal.processors.query.calcite.exec.QueryTaskExecutor;
import org.apache.ignite.internal.processors.query.calcite.exec.QueryTaskExecutorImpl;
+import org.apache.ignite.internal.processors.query.calcite.fun.IgniteSqlFunctions;
import org.apache.ignite.internal.processors.query.calcite.message.MessageService;
import org.apache.ignite.internal.processors.query.calcite.message.MessageServiceImpl;
import org.apache.ignite.internal.processors.query.calcite.metadata.AffinityService;
@@ -85,12 +87,14 @@ public class CalciteQueryProcessor extends GridProcessorAdapter implements Query
.withIdentifierExpansion(true)
.withSqlConformance(SqlConformanceEnum.DEFAULT))
// Dialects support.
- .operatorTable(SqlLibraryOperatorTableFactory.INSTANCE
- .getOperatorTable(
- SqlLibrary.STANDARD,
- SqlLibrary.POSTGRESQL,
- SqlLibrary.ORACLE,
- SqlLibrary.MYSQL))
+ .operatorTable(SqlOperatorTables.chain(
+ SqlLibraryOperatorTableFactory.INSTANCE
+ .getOperatorTable(
+ SqlLibrary.STANDARD,
+ SqlLibrary.POSTGRESQL,
+ SqlLibrary.ORACLE,
+ SqlLibrary.MYSQL),
+ CalciteCatalogReader.operatorTable(IgniteSqlFunctions.class.getName())))
// Context provides a way to store data within the planner session that can be accessed in planner rules.
.context(Contexts.empty())
// Custom cost factory to use during optimization
diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/fun/IgniteSqlFunctions.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/fun/IgniteSqlFunctions.java
new file mode 100644
index 0000000..8f3174b
--- /dev/null
+++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/fun/IgniteSqlFunctions.java
@@ -0,0 +1,37 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.fun;
+
+import org.apache.calcite.linq4j.function.Strict;
+
+/**
+ * Ignite SQL functions.
+ */
+public class IgniteSqlFunctions {
+ /**
+ * Default constructor.
+ */
+ private IgniteSqlFunctions() {
+ // No-op.
+ }
+
+ /** SQL LENGTH(string) function. */
+ @Strict
+ public static int length(String str) {
+ return str.length();
+ }
+}
diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/FunctionsTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/FunctionsTest.java
new file mode 100644
index 0000000..851f11f
--- /dev/null
+++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/FunctionsTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.ignite.internal.processors.query.calcite;
+
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.QueryEngine;
+import org.apache.ignite.internal.processors.query.calcite.util.Commons;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/**
+ * Test Ignite SQL functions.
+ */
+public class FunctionsTest extends GridCommonAbstractTest {
+ /** */
+ private static QueryEngine qryEngine;
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ IgniteEx grid = startGrid();
+
+ qryEngine = Commons.lookupComponent(grid.context(), QueryEngine.class);
+ }
+
+ /** */
+ @Test
+ public void testLength() throws Exception {
+ checkQuery("SELECT LENGTH('TEST')").returns(4).check();
+ checkQuery("SELECT LENGTH(NULL)").returns(new Object[] { null }).check();
+ }
+
+ /** */
+ private QueryChecker checkQuery(String qry) {
+ return new QueryChecker(qry) {
+ @Override protected QueryEngine getEngine() {
+ return qryEngine;
+ }
+ };
+ }
+}
diff --git a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
index f9d8b0d..4414be0 100644
--- a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
+++ b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java
@@ -23,6 +23,7 @@ import org.apache.ignite.internal.processors.query.calcite.CalciteErrorHandlilng
import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessorTest;
import org.apache.ignite.internal.processors.query.calcite.CancelTest;
import org.apache.ignite.internal.processors.query.calcite.DateTimeTest;
+import org.apache.ignite.internal.processors.query.calcite.FunctionsTest;
import org.apache.ignite.internal.processors.query.calcite.LimitOffsetTest;
import org.apache.ignite.internal.processors.query.calcite.MetadataIntegrationTest;
import org.apache.ignite.internal.processors.query.calcite.QueryCheckerTest;
@@ -64,6 +65,7 @@ import org.junit.runners.Suite;
SqlDdlParserTest.class,
TableDdlIntegrationTest.class,
+ FunctionsTest.class,
})
public class IgniteCalciteTestSuite {
}
diff --git a/parent/pom.xml b/parent/pom.xml
index 3ef943d..518c2d5 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -78,7 +78,7 @@
<hamcrest.version>1.2</hamcrest.version>
<httpclient.version>4.5.1</httpclient.version>
<httpcore.version>4.4.3</httpcore.version>
- <jackson.version>2.9.10</jackson.version>
+ <jackson.version>2.12.3</jackson.version>
<jackson1.version>1.9.13</jackson1.version>
<jaxb.api.version>2.1</jaxb.api.version>
<jaxb.impl.version>2.1.14</jaxb.impl.version>