Skip to content

Commit

Permalink
[BugFix] fix immediate refresh semantic (StarRocks#31258)
Browse files Browse the repository at this point in the history
Signed-off-by: Murphy <[email protected]>
  • Loading branch information
murphyatwork authored Sep 18, 2023
1 parent 6a1675e commit eab4553
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3280,9 +3280,7 @@ private void createTaskForMaterializedView(String dbName, MaterializedView mater

TaskManager taskManager = GlobalStateMgr.getCurrentState().getTaskManager();
taskManager.createTask(task, false);
// for event triggered type, run task
if (task.getType() == Constants.TaskType.EVENT_TRIGGERED &&
!refreshMoment.equals(MaterializedView.RefreshMoment.DEFERRED)) {
if (refreshMoment.equals(MaterializedView.RefreshMoment.IMMEDIATE)) {
taskManager.executeTask(task.getName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2777,22 +2777,69 @@ public void testCreateSyncMVWithCaseWhenComplexExpression1() {
}

@Test
public void testCreateImmediateDeferred(@Mocked TaskManager taskManager) throws Exception {
public void testCreateAsync_Deferred(@Mocked TaskManager taskManager) throws Exception {
new Expectations() {
{
taskManager.executeTask((String) any);
times = 1;
times = 0;
}
};
String createImmediate =
"create materialized view immediate_mv refresh deferred async distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1";
starRocksAssert.withMaterializedView(createImmediate);

String createDeferred =
"create materialized view deferred_mv refresh immediate async distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1";
starRocksAssert.withMaterializedView(createDeferred);
starRocksAssert.withMaterializedView(
"create materialized view deferred_async " +
"refresh deferred async distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view deferred_manual " +
"refresh deferred manual distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view deferred_scheduled " +
"refresh deferred async every(interval 1 day) distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
}

@Test
public void testCreateAsync_Immediate(@Mocked TaskManager taskManager) throws Exception {
new Expectations() {
{
taskManager.executeTask((String) any);
times = 3;
}
};
starRocksAssert.withMaterializedView(
"create materialized view async_immediate " +
"refresh immediate async distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view manual_immediate " +
"refresh immediate manual distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view schedule_immediate " +
"refresh immediate async every(interval 1 day) distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
}

@Test
public void testCreateAsync_Immediate_Implicit(@Mocked TaskManager taskManager) throws Exception {
new Expectations() {
{
taskManager.executeTask((String) any);
times = 3;
}
};
starRocksAssert.withMaterializedView(
"create materialized view async_immediate_implicit " +
"refresh async distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view manual_immediate_implicit " +
"refresh manual distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
starRocksAssert.withMaterializedView(
"create materialized view schedule_immediate_implicit " +
"refresh async every(interval 1 day) distributed by hash(c_1_9) as" +
" select c_1_9, c_1_4 from t1");
}

private void testMVColumnAlias(String expr) throws Exception {
Expand Down

0 comments on commit eab4553

Please sign in to comment.