Skip to content

Commit

Permalink
[Fix](insert-job)Fix Issue with Missing StatementContext in StmtExecu…
Browse files Browse the repository at this point in the history
…tor, Leading to Incorrect SQL_BLOCK Handling

During the task construction process of the Insert Job, the StmtExecutor was not provided with a corresponding StatementContext, which causes a default StatementContext to be generated. This can lead to issues where certain properties related to ↳StatementContext, such as the globally set SQL_BLOCK, do not function correctly.
  • Loading branch information
CalvinKirs committed Jan 9, 2025
1 parent c206a6b commit 2da9255
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions fe/fe-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ under the License.
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.thrift/libthrift -->
<dependency>
<groupId>org.apache.thrift</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.doris.load.FailMsg;
import org.apache.doris.load.loadv2.LoadJob;
import org.apache.doris.load.loadv2.LoadStatistic;
import org.apache.doris.nereids.StatementContext;
import org.apache.doris.nereids.glue.LogicalPlanAdapter;
import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand;
import org.apache.doris.qe.ConnectContext;
Expand Down Expand Up @@ -159,13 +161,15 @@ public void before() throws JobException {
ctx.setDatabase(currentDb);
}
TUniqueId queryId = generateQueryId(UUID.randomUUID().toString());
stmtExecutor = new StmtExecutor(ctx, (String) null);
StatementContext statementContext = new StatementContext();
ctx.setQueryId(queryId);
ctx.setStatementContext(statementContext);
if (StringUtils.isNotEmpty(sql)) {
NereidsParser parser = new NereidsParser();
this.command = (InsertIntoTableCommand) parser.parseSingle(sql);
this.command.setLabelName(Optional.of(getJobId() + LABEL_SPLITTER + getTaskId()));
this.command.setJobId(getTaskId());
stmtExecutor = new StmtExecutor(ctx, new LogicalPlanAdapter(command, ctx.getStatementContext()));
}

super.before();
Expand Down
14 changes: 14 additions & 0 deletions regression-test/suites/job_p0/test_base_insert_job.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ suite("test_base_insert_job") {
"replication_allocation" = "tag.location.default: 1"
);
"""
sql """
DROP SQL_BLOCK_RULE IF EXISTS test_base_insert_job_rule
"""
sql """
CREATE SQL_BLOCK_RULE test_base_insert_job_rule
PROPERTIES(
"sql"="select \\\\* from test_base_insert_job_rule",
"global"="true",
"enable"="true"
);
"""
sql """
insert into ${tableName} values
('2023-03-18', 1, 1)
Expand Down Expand Up @@ -242,6 +253,9 @@ suite("test_base_insert_job") {
//resume tasks size should be greater than before pause
afterResumeTasks.size() > tasks.size()
})
sql """
DROP SQL_BLOCK_RULE IF EXISTS test_base_insert_job_rule
"""
// check resume job status
def afterResumeJobStatus = sql """
select status from jobs("type"="insert") where Name='${jobName}'
Expand Down

0 comments on commit 2da9255

Please sign in to comment.