[feature](mtmv)(6)implement cancel method (#27541)

1.implement cancel task method
2.fix `show create table ` not display `comment`
This commit is contained in:
zhangdong
2023-11-27 09:49:46 +08:00
committed by GitHub
parent 5700332c3c
commit 3791de3cfa
5 changed files with 40 additions and 22 deletions

View File

@ -2965,7 +2965,7 @@ public class Env {
|| table.getType() == TableType.HIVE || table.getType() == TableType.JDBC) {
sb.append("EXTERNAL ");
}
sb.append("TABLE ");
sb.append(table.getType() != TableType.MATERIALIZED_VIEW ? "TABLE " : "MATERIALIZED VIEW ");
if (!Strings.isNullOrEmpty(dbName)) {
sb.append("`").append(dbName).append("`.");
@ -2995,7 +2995,7 @@ public class Env {
sb.append(" ").append(column.toSql());
}
}
if (table.getType() == TableType.OLAP) {
if (table instanceof OlapTable) {
OlapTable olapTable = (OlapTable) table;
if (CollectionUtils.isNotEmpty(olapTable.getIndexes())) {
for (Index index : olapTable.getIndexes()) {
@ -3007,7 +3007,7 @@ public class Env {
sb.append("\n) ENGINE=");
sb.append(table.getType().name());
if (table.getType() == TableType.OLAP || table.getType() == TableType.MATERIALIZED_VIEW) {
if (table instanceof OlapTable) {
OlapTable olapTable = (OlapTable) table;
// keys
String keySql = olapTable.getKeysType().toSql();
@ -3015,10 +3015,7 @@ public class Env {
// after #18621, use can create a DUP_KEYS olap table without key columns
// and get a ddl schema without key type and key columns
} else {
sb.append("\n").append(table.getType() == TableType.OLAP
? keySql
: keySql.substring("DUPLICATE ".length()))
.append("(");
sb.append("\n").append(keySql).append("(");
List<String> keysColumnNames = Lists.newArrayList();
Map<Integer, String> clusterKeysColumnNamesToId = new TreeMap<>();
for (Column column : olapTable.getBaseSchema()) {
@ -3047,9 +3044,7 @@ public class Env {
return;
}
if (table.getType() != TableType.MATERIALIZED_VIEW) {
addTableComment(olapTable, sb);
}
addTableComment(olapTable, sb);
// partition
PartitionInfo partitionInfo = olapTable.getPartitionInfo();

View File

@ -59,6 +59,7 @@ public class MTMVTask extends AbstractTask {
private MTMV mtmv;
private MTMVRelation relation;
private StmtExecutor executor;
public MTMVTask(long dbId, long mtmvId) {
this.dbId = dbId;
@ -73,7 +74,7 @@ public class MTMVTask extends AbstractTask {
// Every time a task is run, the relation is regenerated because baseTables and baseViews may change,
// such as deleting a table and creating a view with the same name
relation = MTMVCacheManager.generateMTMVRelation(mtmv, ctx);
StmtExecutor executor = new StmtExecutor(ctx, sql);
executor = new StmtExecutor(ctx, sql);
executor.execute(queryId);
} catch (Throwable e) {
LOG.warn(e);
@ -82,20 +83,23 @@ public class MTMVTask extends AbstractTask {
}
@Override
public void onFail() throws JobException {
public synchronized void onFail() throws JobException {
super.onFail();
after();
}
@Override
public void onSuccess() throws JobException {
public synchronized void onSuccess() throws JobException {
super.onSuccess();
after();
}
@Override
public void cancel() throws JobException {
public synchronized void cancel() throws JobException {
super.cancel();
if (executor != null) {
executor.cancel();
}
after();
}
@ -165,5 +169,6 @@ public class MTMVTask extends AbstractTask {
.addMTMVTaskResult(new TableNameInfo(mtmv.getQualifiedDbName(), mtmv.getName()), this, relation);
mtmv = null;
relation = null;
executor = null;
}
}

View File

@ -492,9 +492,12 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
bucketNum, ctx.HASH() != null ? visitIdentifierList(ctx.hashKeys) : null);
Map<String, String> properties = ctx.propertyClause() != null
? Maps.newHashMap(visitPropertyClause(ctx.propertyClause())) : Maps.newHashMap();
String comment = ctx.STRING_LITERAL() == null ? "" : LogicalPlanBuilderAssistant.escapeBackSlash(
ctx.STRING_LITERAL().getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1));
return new CreateMTMVCommand(new CreateMTMVInfo(ctx.EXISTS() != null, new TableNameInfo(nameParts),
ctx.keys != null ? visitIdentifierList(ctx.keys) : ImmutableList.of(),
ctx.STRING_LITERAL() != null ? ctx.STRING_LITERAL().getText() : null,
comment,
desc, properties, logicalPlan, querySql,
new MTMVRefreshInfo(buildMode, refreshMethod, refreshTriggerInfo),
ctx.cols == null ? Lists.newArrayList() : visitSimpleColumnDefs(ctx.cols)
@ -513,8 +516,10 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
@Override
public SimpleColumnDefinition visitSimpleColumnDef(SimpleColumnDefContext ctx) {
String comment = ctx.STRING_LITERAL() == null ? "" : LogicalPlanBuilderAssistant.escapeBackSlash(
ctx.STRING_LITERAL().getText().substring(1, ctx.STRING_LITERAL().getText().length() - 1));
return new SimpleColumnDefinition(ctx.colName.getText().toLowerCase(),
ctx.STRING_LITERAL() != null ? ctx.STRING_LITERAL().getText() : null);
comment);
}
/**