mirror of
https://github.com/apache/druid.git
synced 2025-02-22 18:30:13 +00:00
Add check for sqlOuterLimit to ingest queries (#12799)
* Add check for sqlOuterLimit to ingest queries * Fix checkstyle * Add comment
This commit is contained in:
parent
cc1ff56ca5
commit
f3272a25f9
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user