Skip to content

Commit f15e9c2

Browse files
committed
ice/watch: Recreate table if deleted (and --create-table/-p is used)
1 parent d50e363 commit f15e9c2

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

ice/src/main/java/com/altinity/ice/cli/internal/cmd/Insert.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.apache.iceberg.data.parquet.GenericParquetWriter;
6262
import org.apache.iceberg.exceptions.AlreadyExistsException;
6363
import org.apache.iceberg.exceptions.BadRequestException;
64+
import org.apache.iceberg.exceptions.NoSuchTableException;
6465
import org.apache.iceberg.io.CloseableIterable;
6566
import org.apache.iceberg.io.FileAppender;
6667
import org.apache.iceberg.io.FileIO;
@@ -92,7 +93,7 @@ private Insert() {}
9293
// TODO: refactor
9394
public static void run(
9495
RESTCatalog catalog, TableIdentifier nsTable, String[] files, Options options)
95-
throws IOException, InterruptedException {
96+
throws NoSuchTableException, IOException, InterruptedException {
9697
if (files.length == 0) {
9798
// no work to be done
9899
return;

ice/src/main/java/com/altinity/ice/cli/internal/cmd/InsertWatch.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323
import java.util.function.Supplier;
2424
import org.apache.iceberg.catalog.TableIdentifier;
25+
import org.apache.iceberg.exceptions.NoSuchTableException;
2526
import org.apache.iceberg.rest.RESTCatalog;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
@@ -83,8 +84,6 @@ public static void run(
8384
// TODO: implement
8485
};
8586

86-
boolean createTableExecuted = false;
87-
8887
//noinspection LoopConditionNotUpdatedInsideLoop
8988
do {
9089
List<Message> batch = new LinkedList<>();
@@ -117,22 +116,23 @@ public static void run(
117116
if (!insertBatch.isEmpty()) {
118117
logger.info("Inserting {}", insertBatch);
119118

120-
if (createTableIfNotExists && !createTableExecuted) {
121-
if (!catalog.tableExists(nsTable)) {
122-
CreateTable.run(
123-
catalog,
124-
nsTable,
125-
insertBatch.iterator().next(),
126-
null,
127-
true,
128-
options.s3NoSignRequest(),
129-
null,
130-
null);
119+
try {
120+
Insert.run(catalog, nsTable, insertBatch.toArray(String[]::new), options);
121+
} catch (NoSuchTableException e) {
122+
if (!createTableIfNotExists) {
123+
throw e;
131124
}
132-
createTableExecuted = true;
125+
CreateTable.run(
126+
catalog,
127+
nsTable,
128+
insertBatch.iterator().next(),
129+
null,
130+
true,
131+
options.s3NoSignRequest(),
132+
null,
133+
null);
134+
Insert.run(catalog, nsTable, insertBatch.toArray(String[]::new), options);
133135
}
134-
135-
Insert.run(catalog, nsTable, insertBatch.toArray(String[]::new), options);
136136
}
137137

138138
confirmProcessed(sqs, sqsQueueURL, batch);

0 commit comments

Comments
 (0)