Skip to content

Commit 650f764

Browse files
jogroganclaude
andcommitted
refactor: unify DDL execution and dry-run into shared processCreate* methods
Extract TemporaryTable to a standalone public class. Add DdlMode enum (CREATE/UPDATE/SPECIFY), processCreateMaterializedView(), and processCreateTable() to HoptimatorDdlUtils so HoptimatorDdlExecutor fully delegates to them. Add specifyFromSql() and specifyCreateTable() as the unified !specify entry points used by QuidemTestBase and HoptimatorAppConfig. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 7db5c2c commit 650f764

10 files changed

Lines changed: 2476 additions & 2009 deletions

File tree

hoptimator-cli/src/main/java/sqlline/HoptimatorAppConfig.java

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package sqlline;
22

3-
import com.linkedin.hoptimator.Pipeline;
4-
import com.linkedin.hoptimator.Source;
53
import com.linkedin.hoptimator.SqlDialect;
64
import com.linkedin.hoptimator.jdbc.HoptimatorConnection;
75
import com.linkedin.hoptimator.jdbc.HoptimatorDdlUtils;
@@ -278,56 +276,13 @@ public void execute(String line, DispatchCallback dispatchCallback) {
278276
}
279277
String sql = split[1];
280278
HoptimatorConnection conn = (HoptimatorConnection) sqlline.getConnection();
281-
Pair<SchemaPlus, Table> schemaSnapshot = null;
282-
String viewName = "sink";
283279
try {
284-
String querySql = sql;
285-
SqlCreateMaterializedView create = null;
286-
SqlNode sqlNode = HoptimatorDriver.parseQuery(conn, sql);
287-
if (sqlNode.getKind().belongsTo(SqlKind.DDL)) {
288-
if (sqlNode instanceof SqlCreateMaterializedView) {
289-
create = (SqlCreateMaterializedView) sqlNode;
290-
final SqlNode q = HoptimatorDdlUtils.renameColumns(create.columnList, create.query);
291-
querySql = q.toSqlString(CalciteSqlDialect.DEFAULT).getSql();
292-
viewName = HoptimatorDdlUtils.viewName(create.name);
293-
} else {
294-
sqlline.error("Unsupported DDL statement: " + sql);
295-
dispatchCallback.setToFailure();
296-
return;
297-
}
298-
}
299-
300-
RelRoot root = HoptimatorDriver.convert(conn, querySql).root;
301-
Properties connectionProperties = conn.connectionProperties();
302-
RelOptTable table = root.rel.getTable();
303-
if (table != null) {
304-
connectionProperties.setProperty(DeploymentService.PIPELINE_OPTION, String.join(".", table.getQualifiedName()));
305-
} else if (create != null) {
306-
connectionProperties.setProperty(DeploymentService.PIPELINE_OPTION, create.name.toString());
307-
}
308-
PipelineRel.Implementor plan = DeploymentService.plan(root, conn.materializations(), connectionProperties);
309-
if (create != null) {
310-
schemaSnapshot = HoptimatorDdlUtils.snapshotAndSetSinkSchema(conn.createPrepareContext(),
311-
new HoptimatorDriver.Prepare(conn), plan, create, querySql);
312-
}
313-
Pipeline pipeline = plan.pipeline(viewName, conn);
314-
List<String> specs = new ArrayList<>();
315-
for (Source source : pipeline.sources()) {
316-
specs.addAll(DeploymentService.specify(source, conn));
317-
}
318-
specs.addAll(DeploymentService.specify(pipeline.sink(), conn));
319-
specs.addAll(DeploymentService.specify(pipeline.job(), conn));
280+
List<String> specs = HoptimatorDdlUtils.specifyFromSql(sql, conn).specs;
320281
specs.forEach(x -> sqlline.output(x + "\n\n---\n\n"));
321282
} catch (SQLException e) {
322283
sqlline.error(e);
323284
dispatchCallback.setToFailure();
324285
}
325-
if (schemaSnapshot != null) {
326-
if (schemaSnapshot.right != null) {
327-
schemaSnapshot.left.add(viewName, schemaSnapshot.right);
328-
}
329-
schemaSnapshot.left.removeTable(viewName);
330-
}
331286
}
332287

333288
@Override

0 commit comments

Comments
 (0)