|
22 | 22 | import com.linkedin.hoptimator.Database;
|
23 | 23 | import com.linkedin.hoptimator.util.DeploymentService;
|
24 | 24 | import com.linkedin.hoptimator.util.MaterializedView;
|
| 25 | +import com.linkedin.hoptimator.util.Sink; |
| 26 | +import com.linkedin.hoptimator.util.planner.Pipeline; |
| 27 | +import com.linkedin.hoptimator.util.planner.PipelineRel; |
| 28 | +import com.linkedin.hoptimator.util.planner.ScriptImplementor; |
25 | 29 |
|
26 | 30 | import org.apache.calcite.jdbc.CalcitePrepare;
|
27 | 31 | import org.apache.calcite.jdbc.CalciteSchema;
|
| 32 | +import org.apache.calcite.rel.RelNode; |
28 | 33 | import org.apache.calcite.rel.type.RelDataType;
|
29 | 34 | import org.apache.calcite.rel.type.RelDataTypeSystem;
|
30 | 35 | import org.apache.calcite.server.DdlExecutor;
|
|
35 | 40 | import org.apache.calcite.schema.impl.ViewTable;
|
36 | 41 | import org.apache.calcite.schema.impl.ViewTableMacro;
|
37 | 42 | import org.apache.calcite.sql.SqlCall;
|
| 43 | +import org.apache.calcite.sql.SqlDialect; |
38 | 44 | import org.apache.calcite.sql.SqlIdentifier;
|
39 | 45 | import org.apache.calcite.sql.SqlNode;
|
40 | 46 | import org.apache.calcite.sql.SqlNodeList;
|
@@ -166,9 +172,18 @@ public void execute(SqlCreateMaterializedView create,
|
166 | 172 | MaterializedViewTable materializedViewTable = new MaterializedViewTable(viewTableMacro);
|
167 | 173 | RelDataType rowType = materializedViewTable.getRowType(new SqlTypeFactoryImpl(
|
168 | 174 | RelDataTypeSystem.DEFAULT));
|
169 |
| - MaterializedView hook = new MaterializedView(context, database, viewPath, rowType, sql, |
170 |
| - Collections.emptyMap()); // TODO support CREATE ... WITH (options...) |
| 175 | + |
| 176 | + // Plan a pipeline to materialize the view. |
| 177 | + RelNode rel = HoptimatorDriver.convert(context, sql).root.rel; |
| 178 | + PipelineRel.Implementor plan = DeploymentService.plan(rel); |
| 179 | + plan.setSink(database, viewPath, rowType, Collections.emptyMap()); |
| 180 | + Pipeline pipeline = plan.pipeline(); |
| 181 | + |
| 182 | + MaterializedView hook = new MaterializedView(database, viewPath, sql, plan.sql(), |
| 183 | + plan.pipeline()); |
| 184 | + // TODO support CREATE ... WITH (options...) |
171 | 185 | ValidationService.validateOrThrow(hook, MaterializedView.class);
|
| 186 | + pipeline.update(); |
172 | 187 | if (create.getReplace()) {
|
173 | 188 | DeploymentService.update(hook, MaterializedView.class);
|
174 | 189 | } else {
|
|
0 commit comments