public static Task buildMvTask(MaterializedView materializedView, String dbName) {
        Task task = new Task(getMvTaskName(materializedView.getId()));
        task.setSource(Constants.TaskSource.MV);
        task.setDbName(dbName);

        Map<String, String> taskProperties = Maps.newHashMap();
        taskProperties.put(PartitionBasedMvRefreshProcessor.MV_ID,
                String.valueOf(materializedView.getId()));
        taskProperties.putAll(materializedView.getProperties());
        // In PropertyAnalyzer.analyzeMVProperties, it removed the warehouse property, because
        // it only keeps session started properties
        Warehouse warehouse = GlobalStateMgr.getCurrentState().getWarehouseMgr()
                .getWarehouse(materializedView.getWarehouseId());
        taskProperties.put(PropertyAnalyzer.PROPERTIES_WAREHOUSE, warehouse.getName());
        task.setProperties(taskProperties);

        task.setDefinition(materializedView.getTaskDefinition());
        task.setPostRun(getAnalyzeMVStmt(materializedView.getName()));
        task.setExpireTime(0L);
        if (ConnectContext.get() != null) {
            task.setCreateUser(ConnectContext.get().getCurrentUserIdentity().getUser());
            task.setUserIdentity(ConnectContext.get().getCurrentUserIdentity());
        }
        handleSpecialTaskProperties(task);
        return task;
    }
@Test
    public void testTaskBuilderForMv() {
        // mock the warehouse of MaterializedView for creating task
        new MockUp<WarehouseManager>() {
            @Mock
            public Warehouse getWarehouse(long warehouseId) {
                return new DefaultWarehouse(WarehouseManager.DEFAULT_WAREHOUSE_ID,
                        WarehouseManager.DEFAULT_WAREHOUSE_NAME);
            }

            @Mock
            public Warehouse getWarehouse(String warehouse) {
                return new DefaultWarehouse(WarehouseManager.DEFAULT_WAREHOUSE_ID,
                        WarehouseManager.DEFAULT_WAREHOUSE_NAME);
            }
        };

        MaterializedView mv = new MaterializedView();
        mv.setName("aa.bb.cc");
        mv.setViewDefineSql("select * from table1");
        mv.setTableProperty(new TableProperty());
        Task task = TaskBuilder.buildMvTask(mv, "test");
        Assert.assertEquals("insert overwrite `aa.bb.cc` select * from table1", task.getDefinition());
    }