morningman commented on code in PR #19473: URL: https://github.com/apache/doris/pull/19473#discussion_r1190089020
########## fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java: ########## @@ -342,6 +342,7 @@ private void init(String s, Type type) throws AnalysisException { Preconditions.checkArgument(type.isDateType()); TemporalAccessor dateTime = null; boolean parsed = false; + s = s.replace("'", ""); Review Comment: I still don't understand. Could you give an example to show how to reproduce this error if this line is removed? ########## fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java: ########## @@ -2076,6 +2092,160 @@ private void handleCtasRollback(TableName table) { } } + private void handleIotStmt() { + InsertOverwriteTableStmt iotStmt = (InsertOverwriteTableStmt) this.parsedStmt; + if (iotStmt.getPartitionNames().size() == 0) { + // insert overwrite table + handleOverwriteTable(iotStmt); + } else { + // insert overwrite table with partition + handleOverwritePartition(iotStmt); + } + } + + private void handleOverwriteTable(InsertOverwriteTableStmt iotStmt) { + UUID uuid = UUID.randomUUID(); + // to comply with naming rules + TableName tmpTableName = new TableName(null, iotStmt.getDb(), "tmp_table_" + uuid.toString().replace('-', '_')); + TableName targetTableName = new TableName(null, iotStmt.getDb(), iotStmt.getTbl()); + try { + // create a tmp table with uuid + parsedStmt = new CreateTableLikeStmt(false, tmpTableName, targetTableName, null, false); + parsedStmt.setUserInfo(context.getCurrentUserIdentity()); + execute(); + } catch (Exception e) { + // Maybe our bug + LOG.warn("IOT create a tmp table error, stmt={}", originStmt.originStmt, e); + context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage()); + return; + } + // after success create table insert data + try { + parsedStmt = new InsertStmt(tmpTableName, iotStmt.getQueryStmt()); + parsedStmt.setUserInfo(context.getCurrentUserIdentity()); + execute(); + if (MysqlStateType.ERR.equals(context.getState().getStateType())) { + LOG.warn("IOT insert data error, stmt={}", parsedStmt.toSql()); + handleIotRollback(tmpTableName); + return; + } + } catch (Exception e) { + LOG.warn("IOT insert data error, stmt={}", parsedStmt.toSql(), e); + context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage()); + handleIotRollback(tmpTableName); + return; + } + + // overwrite old table with tmp table + try { + List<AlterClause> ops = new ArrayList<>(); + Map<String, String> properties = new HashMap<>(); + properties.put("swap", "false"); + ops.add(new ReplaceTableClause(tmpTableName.getTbl(), properties)); + parsedStmt = new AlterTableStmt(targetTableName, ops); + parsedStmt.setUserInfo(context.getCurrentUserIdentity()); + execute(); + context.getState().setOk(); + } catch (Exception e) { + // Maybe our bug + LOG.warn("IOT overwrite table error, stmt={}", parsedStmt.toSql(), e); + context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage()); + handleIotRollback(tmpTableName); + } + + } + + private void handleOverwritePartition(InsertOverwriteTableStmt iotStmt) { + TableName targetTableName = new TableName(null, iotStmt.getDb(), iotStmt.getTbl()); + List<String> partitionNames = iotStmt.getPartitionNames(); + List<String> tempPartitionName = new ArrayList<>(); + try { + // create tmp partitions with uuid + for (String partitionName : partitionNames) { + UUID uuid = UUID.randomUUID(); + // to comply with naming rules + String tempPartName = "tmp_partition_" + uuid.toString().replace('-', '_'); + tempPartitionName.add(tempPartName); + List<AlterClause> ops = new ArrayList<>(); + ops.add(new AddPartitionLikeClause(tempPartName, partitionName, true)); + parsedStmt = new AlterTableStmt(targetTableName, ops); + parsedStmt.setUserInfo(context.getCurrentUserIdentity()); + execute(); + } + } catch (Exception e) { + // Maybe our bug + LOG.warn("IOT create tmp table partitions error, stmt={}", originStmt.originStmt, e); + context.getState().setError(ErrorCode.ERR_UNKNOWN_ERROR, "Unexpected exception: " + e.getMessage()); Review Comment: Here we need to rollback all partitions which already been created. ########## fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java: ########## @@ -1253,6 +1254,51 @@ public void replayCreateTable(String dbName, Table table) throws MetaNotFoundExc } } + public void addPartitionLike(Database db, String tableName, AddPartitionLikeClause addPartitionLikeClause) + throws DdlException { + try { + Table table = db.getTableOrDdlException(tableName); + + if (table.getType() != TableType.OLAP) { + throw new DdlException("Only support create partition from a OLAP table"); + } + + // Lock the table to prevent other SQL from performing write operation during table structure modification + AddPartitionClause clause = null; + try { + table.readLock(); Review Comment: move `table.readLock()` outside the `try{`, it is a traditional -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org