This is an automated email from the ASF dual-hosted git repository.
ppa pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new b7581c42a3 IGNITE-22635 Sql. Fix "unable to optimize plan" error for
input out of range (#4179)
b7581c42a3 is described below
commit b7581c42a34d8a98e2d2e796b6f366c6a92f41ec
Author: Pavel Pereslegin <[email protected]>
AuthorDate: Thu Aug 8 15:30:44 2024 +0300
IGNITE-22635 Sql. Fix "unable to optimize plan" error for input out of
range (#4179)
---
.../sql/engine/datatypes/ItCastToIntTest.java | 18 +++++++++---
...tCastToIntWithoutFastQueryOptimizationTest.java | 32 ++++++++++++++++++++++
.../internal/sql/engine/prepare/PlannerHelper.java | 10 ++-----
3 files changed, 49 insertions(+), 11 deletions(-)
diff --git
a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntTest.java
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntTest.java
index 45f9d53810..6e8eeebe42 100644
---
a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntTest.java
+++
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntTest.java
@@ -80,7 +80,8 @@ public class ItCastToIntTest extends BaseSqlIntegrationTest {
void implicitCastOfLiteralsOnInsertWithOverflow(String literal) {
SqlTestUtils.assertThrowsSqlException(
Sql.RUNTIME_ERR,
- "INTEGER out of range",
+ // TODO IGNITE-22932 The message must be "INTEGER out of range"
+ "out of range",
() -> sql(format("INSERT INTO test VALUES ({})", literal))
);
}
@@ -101,7 +102,8 @@ public class ItCastToIntTest extends BaseSqlIntegrationTest
{
void explicitCastOfLiteralsOnInsertWithOverflow(String literal) {
SqlTestUtils.assertThrowsSqlException(
Sql.RUNTIME_ERR,
- "INTEGER out of range",
+ // TODO IGNITE-22932 The message must be "INTEGER out of range"
+ "out of range",
() -> sql(format("INSERT INTO test VALUES (CAST({} as
INTEGER))", literal))
);
}
@@ -120,7 +122,8 @@ public class ItCastToIntTest extends BaseSqlIntegrationTest
{
void explicitCastOfLiteralsOnSelectWithOverflow(String literal) {
SqlTestUtils.assertThrowsSqlException(
Sql.RUNTIME_ERR,
- "INTEGER out of range",
+ // TODO IGNITE-22932 The message must be "INTEGER out of range"
+ "out of range",
() -> sql(format("SELECT CAST({} as INTEGER)", literal))
);
}
@@ -665,7 +668,14 @@ public class ItCastToIntTest extends
BaseSqlIntegrationTest {
"2147483648", "2147483648.0", "2147483648.1", "-2147483649",
"-2147483649.0",
"-2147483649.1", "decimal '2147483648'", "decimal
'2147483648.1'", "decimal '-2147483649'",
"decimal '-2147483649.1'", "'2147483648'", "'2147483648.0'",
"'2147483648.1'", "'-2147483649'",
- "'-2147483649.1'"
+ "'-2147483649.1'",
+ // Literals that don't fit into BIGINT
+ "9223372036854775808", "9223372036854775808.0",
"9223372036854775808.1",
+ "-9223372036854775809", "-9223372036854775809.0",
"-9223372036854775809.1",
+ "decimal '9223372036854775808'", "decimal
'9223372036854775808.1'",
+ "decimal '-9223372036854775809'", "decimal
'-9223372036854775809.1'", "'9223372036854775808'",
+ "'9223372036854775808.0'", "'9223372036854775808.1'",
"'-9223372036854775809'",
+ "'-9223372036854775809.1'"
).map(Arguments::of);
}
diff --git
a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntWithoutFastQueryOptimizationTest.java
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntWithoutFastQueryOptimizationTest.java
new file mode 100644
index 0000000000..343fa13807
--- /dev/null
+++
b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/ItCastToIntWithoutFastQueryOptimizationTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.sql.engine.datatypes;
+
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+
+/**
+ * Set of tests to ensure correctness of CAST expression to INTEGER
+ * without fast query optimization.
+ *
+ * @see ItCastToIntTest
+ * @see Commons#fastQueryOptimizationEnabled()
+ */
+@WithSystemProperty(key = "FAST_QUERY_OPTIMIZATION_ENABLED", value = "false")
+public class ItCastToIntWithoutFastQueryOptimizationTest extends
ItCastToIntTest {
+}
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
index 093c58f7d6..b99b903a6e 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java
@@ -28,7 +28,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.calcite.plan.RelOptPlanner.CannotPlanException;
import org.apache.calcite.plan.RelOptTable;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.plan.RelTraitSet;
@@ -61,7 +60,6 @@ import
org.apache.ignite.internal.sql.engine.schema.ColumnDescriptor;
import org.apache.ignite.internal.sql.engine.schema.IgniteTable;
import org.apache.ignite.internal.sql.engine.schema.TableDescriptor;
import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions;
-import org.apache.ignite.lang.ErrorGroups.Common;
import org.apache.ignite.sql.SqlException;
import org.jetbrains.annotations.Nullable;
@@ -180,14 +178,12 @@ public final class PlannerHelper {
LOG.debug(planner.dump());
}
- if (ex instanceof CannotPlanException) {
- throw ex;
- } else if (ex.getClass() == RuntimeException.class &&
ex.getCause() instanceof SqlException) {
+ if (ex.getClass() == RuntimeException.class && ex.getCause()
instanceof SqlException) {
SqlException sqlEx = (SqlException) ex.getCause();
throw new SqlException(sqlEx.traceId(), sqlEx.code(),
sqlEx.getMessage(), ex);
- } else {
- throw new SqlException(Common.INTERNAL_ERR, "Unable to
optimize plan due to internal error", ex);
}
+
+ throw ex;
}
}