|
48 | 48 | import io.dingodb.calcite.grammar.ddl.SqlAlterTenant;
|
49 | 49 | import io.dingodb.calcite.grammar.ddl.SqlAlterTruncatePart;
|
50 | 50 | import io.dingodb.calcite.grammar.ddl.SqlAlterUser;
|
| 51 | +import io.dingodb.calcite.grammar.ddl.SqlBatchCreateTable; |
51 | 52 | import io.dingodb.calcite.grammar.ddl.SqlCreateIndex;
|
52 | 53 | import io.dingodb.calcite.grammar.ddl.SqlCreateSchema;
|
53 | 54 | import io.dingodb.calcite.grammar.ddl.SqlCreateSequence;
|
@@ -518,9 +519,19 @@ public void execute(SqlCreateTable createT, CalcitePrepare.Context context) {
|
518 | 519 |
|
519 | 520 | tableDefinition.setIndices(indexTableDefinitions);
|
520 | 521 | DdlService ddlService = DdlService.root();
|
521 |
| - String connId = (String) context.getDataContext().get("connId"); |
522 |
| - ddlService.createTableWithInfo(schema.getSchemaName(), tableDefinition, |
523 |
| - connId, create.getOriginalCreateSql()); |
| 522 | + ActionType actionType; |
| 523 | + if (InfoSchemaService.root().getBatchCreateTable()) { |
| 524 | + tableDefinition.setSchemaState(SchemaState.SCHEMA_PUBLIC); |
| 525 | + List<IndexDefinition> indices = tableDefinition.getIndices(); |
| 526 | + if (indices != null) { |
| 527 | + indices.forEach(index -> index.setSchemaState(SchemaState.SCHEMA_PUBLIC)); |
| 528 | + } |
| 529 | + MetaService.root().createTables(schema.getSchemaId(), tableDefinition, indices); |
| 530 | + } else { |
| 531 | + String connId = (String) context.getDataContext().get("connId"); |
| 532 | + ddlService.createTableWithInfo(schema.getSchemaName(), tableDefinition, |
| 533 | + connId, create.getOriginalCreateSql()); |
| 534 | + } |
524 | 535 |
|
525 | 536 | RootCalciteSchema rootCalciteSchema = (RootCalciteSchema) context.getMutableRootSchema();
|
526 | 537 | RootSnapshotSchema rootSnapshotSchema = (RootSnapshotSchema) rootCalciteSchema.schema;
|
@@ -779,7 +790,7 @@ public void execute(DingoSqlCreateView sqlCreateView, CalcitePrepare.Context con
|
779 | 790 | String tableName = getTableName(sqlCreateView.name);
|
780 | 791 |
|
781 | 792 | // Check table exist
|
782 |
| - if (schema.getTable(tableName) != null) { |
| 793 | + if (schema.getTable(tableName) != null && !sqlCreateView.getReplace()) { |
783 | 794 | throw DINGO_RESOURCE.tableExists(tableName).ex();
|
784 | 795 | }
|
785 | 796 | SqlNode query = renameColumns(sqlCreateView.columnList, sqlCreateView.query);
|
@@ -863,7 +874,7 @@ public void execute(DingoSqlCreateView sqlCreateView, CalcitePrepare.Context con
|
863 | 874 | properties.setProperty("algorithm", sqlCreateView.alg);
|
864 | 875 | tableDefinition.setProperties(properties);
|
865 | 876 | DdlService ddlService = DdlService.root();
|
866 |
| - ddlService.createViewWithInfo(schemaName, tableDefinition, connId, null); |
| 877 | + ddlService.createViewWithInfo(schemaName, tableDefinition, connId, null, sqlCreateView.getReplace()); |
867 | 878 | }
|
868 | 879 |
|
869 | 880 | public void execute(@NonNull SqlCreateUser sqlCreateUser, CalcitePrepare.Context context) {
|
@@ -1889,6 +1900,15 @@ public void execute(SqlAlterExchangePart sqlAlterExchangePart, CalcitePrepare.Co
|
1889 | 1900 | }
|
1890 | 1901 | }
|
1891 | 1902 |
|
| 1903 | + public void execute(SqlBatchCreateTable sqlBatchCreateTable, CalcitePrepare.Context context) { |
| 1904 | + LogUtils.info(log, "DDL execute sql batch create table"); |
| 1905 | + InfoSchemaService.root().setBatchCreateTable(sqlBatchCreateTable.batchCreateTable); |
| 1906 | + // increment schema version |
| 1907 | + if (!sqlBatchCreateTable.batchCreateTable) { |
| 1908 | + InfoSchemaService.root().genSchemaVersion(101); |
| 1909 | + } |
| 1910 | + } |
| 1911 | + |
1892 | 1912 | public static void validatePartitionBy(
|
1893 | 1913 | @NonNull List<String> keyList,
|
1894 | 1914 | @NonNull TableDefinition tableDefinition,
|
@@ -2765,7 +2785,7 @@ public static DdlJob getRecoverJobBySql(String querySql, boolean table) {
|
2765 | 2785 | } catch (Exception e) {
|
2766 | 2786 | LogUtils.error(log, e.getMessage(), e);
|
2767 | 2787 | } finally {
|
2768 |
| - session.destroy(); |
| 2788 | + SessionUtil.INSTANCE.closeSession(session); |
2769 | 2789 | }
|
2770 | 2790 | return ddlJob;
|
2771 | 2791 | }
|
|
0 commit comments