rdblue commented on code in PR #4956:
URL: https://github.com/apache/iceberg/pull/4956#discussion_r889116614
##########
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/source/TestDataSourceOptions.java:
##########
@@ -404,4 +414,61 @@ public void testExtraSnapshotMetadata() throws IOException
{
Assert.assertTrue(table.currentSnapshot().summary().get("extra-key").equals("someValue"));
Assert.assertTrue(table.currentSnapshot().summary().get("another-key").equals("anotherValue"));
}
+
+ @Test
+ public void testExtraSnapshotMetadataWithSQL() throws IOException {
+ String tableLocation = temp.newFolder("iceberg-table").toString();
+ HadoopTables tables = new HadoopTables(CONF);
+ int threadsCount = 3;
+ ExecutorService executorService =
Executors.newFixedThreadPool(threadsCount, new ThreadFactory() {
+
+ private AtomicInteger currentThreadCount = new AtomicInteger(0);
+
+ @Override
+ public Thread newThread(Runnable r) {
+ return new Thread(r, "thread-" + currentThreadCount.getAndIncrement());
+ }
+ });
+
+ Table table = tables.create(SCHEMA, PartitionSpec.unpartitioned(),
Maps.newHashMap(), tableLocation);
+
+ List<SimpleRecord> expectedRecords = Lists.newArrayList(
+ new SimpleRecord(1, "a"),
+ new SimpleRecord(2, "b")
+ );
+ Dataset<Row> originalDf = spark.createDataFrame(expectedRecords,
SimpleRecord.class);
+ originalDf.select("id", "data").write()
+ .format("iceberg")
+ .mode("append")
+ .option(SparkWriteOptions.SNAPSHOT_PROPERTY_PREFIX + ".extra-key",
"someValue")
+ .option(SparkWriteOptions.SNAPSHOT_PROPERTY_PREFIX + ".another-key",
"anotherValue")
+ .save(tableLocation);
+
spark.read().format("iceberg").load(tableLocation).createOrReplaceTempView("target");
+ Tasks
+ .range(threadsCount)
+ .stopOnFailure()
+ .throwFailureWhenFinished()
+ .executeWith(executorService)
+ .run(index -> {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put("writer-thread",
String.valueOf(Thread.currentThread().getName()));
+ try {
+ CommitMetadata.withCommitProperties(properties, () -> {
+ spark.sql("INSERT INTO target VALUES (3, 'c'), (4, 'd')");
+ return 0;
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
Review Comment:
This shouldn't print. Instead, wrap it in a `RuntimeException`.
Another option is to parameterize `withCommitProperties` so that you can
specify what type of exception may be thrown. Then you can use
`RuntimeException` here and not add the try/catch. An example of this is the
`runSafely` method:
https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/util/ExceptionUtil.java#L56
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]