wuwenchi commented on code in PR #36289: URL: https://github.com/apache/doris/pull/36289#discussion_r1642051388
########## fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergTransaction.java: ########## @@ -59,140 +66,114 @@ public void updateIcebergCommitData(List<TIcebergCommitData> commitDataList) { } } - public void beginInsert(String dbName, String tbName) { - Table icebergTable = ops.getCatalog().loadTable(TableIdentifier.of(dbName, tbName)); - transaction = icebergTable.newTransaction(); + public void pendingCommit(SimpleTableInfo tableInfo) { + this.tableInfo = tableInfo; + this.transaction = getNativeTable(tableInfo).newTransaction(); } - public void finishInsert() { - Table icebergTable = transaction.table(); - AppendFiles appendFiles = transaction.newAppend(); - - for (CommitTaskData task : convertToCommitTaskData()) { - DataFiles.Builder builder = DataFiles.builder(icebergTable.spec()) - .withPath(task.getPath()) - .withFileSizeInBytes(task.getFileSizeInBytes()) - .withFormat(IcebergUtils.getFileFormat(icebergTable)) - .withMetrics(task.getMetrics()); - - if (icebergTable.spec().isPartitioned()) { - List<String> partitionValues = task.getPartitionValues() - .orElseThrow(() -> new VerifyException("No partition data for partitioned table")); - builder.withPartitionValues(partitionValues); - } - appendFiles.appendFile(builder.build()); - } + public void preCommit(SimpleTableInfo tableInfo, Optional<InsertCommandContext> insertCtx) { - // in appendFiles.commit, it will generate metadata(manifest and snapshot) - // after appendFiles.commit, in current transaction, you can already see the new snapshot - appendFiles.commit(); - } + LOG.info("iceberg table {} insert table finished!", tableInfo); - public List<CommitTaskData> convertToCommitTaskData() { - List<CommitTaskData> commitTaskData = new ArrayList<>(); - for (TIcebergCommitData data : this.commitDataList) { - commitTaskData.add(new CommitTaskData( - data.getFilePath(), - data.getFileSize(), - new Metrics( - data.getRowCount(), - Collections.EMPTY_MAP, - Collections.EMPTY_MAP, - Collections.EMPTY_MAP, - Collections.EMPTY_MAP - ), - data.isSetPartitionValues() ? Optional.of(data.getPartitionValues()) : Optional.empty(), - convertToFileContent(data.getFileContent()), - data.isSetReferencedDataFiles() ? Optional.of(data.getReferencedDataFiles()) : Optional.empty() - )); + //create start the iceberg transaction + TUpdateMode updateMode = TUpdateMode.APPEND; + if (insertCtx.isPresent()) { + updateMode = ((BaseExternalTableInsertCommandContext) insertCtx.get()).isOverwrite() ? TUpdateMode.OVERWRITE + : TUpdateMode.APPEND; } - return commitTaskData; + updateManifestAfterInsert(updateMode); } - private FileContent convertToFileContent(TFileContent content) { - if (content.equals(TFileContent.DATA)) { - return FileContent.DATA; - } else if (content.equals(TFileContent.POSITION_DELETES)) { - return FileContent.POSITION_DELETES; + private void updateManifestAfterInsert(TUpdateMode updateMode) { + + Table table = getNativeTable(tableInfo); Review Comment: Transactions are isolated and cache tables cannot be used -- 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