You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/04/13 16:43:25 UTC
[iceberg] branch master updated: Spark: Add format-version to table properties (#4540)
This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 9ccdb37d8 Spark: Add format-version to table properties (#4540)
9ccdb37d8 is described below
commit 9ccdb37d862c2471f6335d3841f028384af65641
Author: Mingliang Liu <li...@apache.org>
AuthorDate: Wed Apr 13 09:43:20 2022 -0700
Spark: Add format-version to table properties (#4540)
---
.../java/org/apache/iceberg/spark/source/SparkTable.java | 15 +++++++++++++--
.../apache/iceberg/spark/actions/TestCreateActions.java | 5 +++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java b/spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
index 0f43dd068..dfcba1f32 100644
--- a/spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
+++ b/spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java
@@ -22,6 +22,7 @@ package org.apache.iceberg.spark.source;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import org.apache.iceberg.BaseTable;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.FileScanTask;
import org.apache.iceberg.MetadataColumns;
@@ -29,6 +30,7 @@ import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Partitioning;
import org.apache.iceberg.Schema;
import org.apache.iceberg.Table;
+import org.apache.iceberg.TableOperations;
import org.apache.iceberg.TableProperties;
import org.apache.iceberg.TableScan;
import org.apache.iceberg.exceptions.ValidationException;
@@ -71,13 +73,17 @@ import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.iceberg.TableProperties.CURRENT_SNAPSHOT_ID;
+import static org.apache.iceberg.TableProperties.FORMAT_VERSION;
+
public class SparkTable implements org.apache.spark.sql.connector.catalog.Table,
SupportsRead, SupportsWrite, SupportsDelete, SupportsRowLevelOperations, SupportsMetadataColumns {
private static final Logger LOG = LoggerFactory.getLogger(SparkTable.class);
private static final Set<String> RESERVED_PROPERTIES =
- ImmutableSet.of("provider", "format", "current-snapshot-id", "location", "sort-order", "identifier-fields");
+ ImmutableSet.of("provider", "format", CURRENT_SNAPSHOT_ID, "location", FORMAT_VERSION, "sort-order",
+ "identifier-fields");
private static final Set<TableCapability> CAPABILITIES = ImmutableSet.of(
TableCapability.BATCH_READ,
TableCapability.BATCH_WRITE,
@@ -157,9 +163,14 @@ public class SparkTable implements org.apache.spark.sql.connector.catalog.Table,
propsBuilder.put("provider", "iceberg");
String currentSnapshotId = icebergTable.currentSnapshot() != null ?
String.valueOf(icebergTable.currentSnapshot().snapshotId()) : "none";
- propsBuilder.put("current-snapshot-id", currentSnapshotId);
+ propsBuilder.put(CURRENT_SNAPSHOT_ID, currentSnapshotId);
propsBuilder.put("location", icebergTable.location());
+ if (icebergTable instanceof BaseTable) {
+ TableOperations ops = ((BaseTable) icebergTable).operations();
+ propsBuilder.put(FORMAT_VERSION, String.valueOf(ops.current().formatVersion()));
+ }
+
if (!icebergTable.sortOrder().isUnsorted()) {
propsBuilder.put("sort-order", Spark3Util.describe(icebergTable.sortOrder()));
}
diff --git a/spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestCreateActions.java b/spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestCreateActions.java
index 8c475bf97..d6530c1d6 100644
--- a/spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestCreateActions.java
+++ b/spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/actions/TestCreateActions.java
@@ -490,6 +490,11 @@ public class TestCreateActions extends SparkCatalogTestBase {
Assert.assertEquals("Unexpected format", "iceberg/parquet", table.properties().get("format"));
Assert.assertNotEquals("No current-snapshot-id found", "none", table.properties().get("current-snapshot-id"));
Assert.assertTrue("Location isn't correct", table.properties().get("location").endsWith(destTableName));
+
+ Assert.assertEquals("Unexpected format-version", "1", table.properties().get("format-version"));
+ table.table().updateProperties().set("format-version", "2").commit();
+ Assert.assertEquals("Unexpected format-version", "2", table.properties().get("format-version"));
+
Assert.assertEquals("Sort-order isn't correct", "id ASC NULLS FIRST, data DESC NULLS LAST",
table.properties().get("sort-order"));
Assert.assertNull("Identifier fields should be null", table.properties().get("identifier-fields"));