This is an automated email from the ASF dual-hosted git repository.
vogievetsky pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new f3272a25f9 Add check for sqlOuterLimit to ingest queries (#12799)
f3272a25f9 is described below
commit f3272a25f9d6b9c2b67d748b6b7a0077c0865400
Author: Adarsh Sanjeev <[email protected]>
AuthorDate: Tue Jul 19 21:32:43 2022 +0530
Add check for sqlOuterLimit to ingest queries (#12799)
* Add check for sqlOuterLimit to ingest queries
* Fix checkstyle
* Add comment
---
.../apache/druid/sql/calcite/planner/DruidPlanner.java | 5 +++++
.../apache/druid/sql/calcite/CalciteInsertDmlTest.java | 15 +++++++++++++++
.../apache/druid/sql/calcite/CalciteReplaceDmlTest.java | 13 +++++++++++++
3 files changed, 33 insertions(+)
diff --git
a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
index 4e1e9bb26f..abf602f4c0 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
@@ -153,6 +153,11 @@ public class DruidPlanner implements Closeable
final Set<ResourceAction> resourceActions = new
HashSet<>(resourceCollectorShuttle.getResourceActions());
if (parsed.getInsertOrReplace() != null) {
+ // Check if CTX_SQL_OUTER_LIMIT is specified and fail the query if it
is. CTX_SQL_OUTER_LIMIT being provided causes
+ // the number of rows inserted to be limited which is likely to be
confusing and unintended.
+ if
(plannerContext.getQueryContext().get(PlannerContext.CTX_SQL_OUTER_LIMIT) !=
null) {
+ throw new ValidationException(PlannerContext.CTX_SQL_OUTER_LIMIT + "
cannot be provided on INSERT or REPLACE queries.");
+ }
final String targetDataSource =
validateAndGetDataSourceForIngest(parsed.getInsertOrReplace());
resourceActions.add(new ResourceAction(new Resource(targetDataSource,
ResourceType.DATASOURCE), Action.WRITE));
}
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java
index 9c0c6545de..67865c076f 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java
@@ -39,12 +39,14 @@ import
org.apache.druid.sql.calcite.external.ExternalOperatorConversion;
import org.apache.druid.sql.calcite.filtration.Filtration;
import org.apache.druid.sql.calcite.parser.DruidSqlInsert;
import org.apache.druid.sql.calcite.planner.PlannerConfig;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
import org.apache.druid.sql.calcite.util.CalciteTests;
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.internal.matchers.ThrowableMessageMatcher;
+import java.util.HashMap;
import java.util.Map;
public class CalciteInsertDmlTest extends CalciteIngestionDmlTest
@@ -755,4 +757,17 @@ public class CalciteInsertDmlTest extends
CalciteIngestionDmlTest
)
.verify();
}
+
+ @Test
+ public void testInsertWithSqlOuterLimit()
+ {
+ HashMap<String, Object> context = new HashMap<>(DEFAULT_CONTEXT);
+ context.put(PlannerContext.CTX_SQL_OUTER_LIMIT, 100);
+
+ testIngestionQuery()
+ .context(context)
+ .sql("INSERT INTO dst SELECT * FROM foo PARTITIONED BY ALL TIME")
+ .expectValidationError(SqlPlanningException.class, "sqlOuterLimit
cannot be provided on INSERT or REPLACE queries.")
+ .verify();
+ }
}
diff --git
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java
index fed8e0cf0c..521b8989ea 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java
@@ -750,4 +750,17 @@ public class CalciteReplaceDmlTest extends
CalciteIngestionDmlTest
)
.verify();
}
+
+ @Test
+ public void testReplaceWithSqlOuterLimit()
+ {
+ HashMap<String, Object> context = new HashMap<>(DEFAULT_CONTEXT);
+ context.put(PlannerContext.CTX_SQL_OUTER_LIMIT, 100);
+
+ testIngestionQuery()
+ .context(context)
+ .sql("REPLACE INTO dst OVERWRITE ALL SELECT * FROM foo PARTITIONED BY
ALL TIME")
+ .expectValidationError(SqlPlanningException.class, "sqlOuterLimit
cannot be provided on INSERT or REPLACE queries.")
+ .verify();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]