Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.spark.sql.connector.catalog.CatalogManager;
import org.apache.spark.sql.connector.catalog.CatalogPlugin;
import org.apache.spark.sql.connector.catalog.Identifier;
import org.apache.spark.sql.connector.catalog.SessionConfigSupport;
import org.apache.spark.sql.connector.catalog.SupportsCatalogOptions;
import org.apache.spark.sql.connector.catalog.Table;
import org.apache.spark.sql.connector.catalog.TableCatalog;
Expand All @@ -61,7 +62,8 @@
* <p>The above list is in order of priority. For example: a matching catalog will take priority
* over any namespace resolution.
*/
public class IcebergSource implements DataSourceRegister, SupportsCatalogOptions {
public class IcebergSource
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another comment, is it now multiple ways to configure properties (including #4011), it may be confusing to user. Worth to add a documentation about it, listing the precedence, ie:

I guess using dataframe API (to be double-checked)

  • explicit dataframe option
  • dataframe session default
  • if table exists, explicit table option
  • if table exists, table default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the docs and hope it's clear now.

implements DataSourceRegister, SupportsCatalogOptions, SessionConfigSupport {
private static final String DEFAULT_CATALOG_NAME = "default_iceberg";
private static final String DEFAULT_CACHE_CATALOG_NAME = "default_cache_iceberg";
private static final String DEFAULT_CATALOG = "spark.sql.catalog." + DEFAULT_CATALOG_NAME;
Expand All @@ -80,6 +82,11 @@ public String shortName() {
return "iceberg";
}

@Override
public String keyPrefix() {
return shortName();
}

@Override
public StructType inferSchema(CaseInsensitiveStringMap options) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,52 @@ private void testWithFilter(String filterExpr, TableIdentifier tableIdentifier)
assertThat(actual).as("Rows must match").containsExactlyInAnyOrderElementsOf(expected);
}

@Test
public void testSessionConfigSupport() {
PartitionSpec spec = PartitionSpec.builderFor(SCHEMA).identity("id").build();
TableIdentifier tableIdentifier = TableIdentifier.of("db", "session_config_table");
Table table = createTable(tableIdentifier, SCHEMA, spec);

List<SimpleRecord> initialRecords =
Lists.newArrayList(
new SimpleRecord(1, "a"), new SimpleRecord(2, "b"), new SimpleRecord(3, "c"));

Dataset<Row> df = spark.createDataFrame(initialRecords, SimpleRecord.class);

df.select("id", "data")
.write()
.format("iceberg")
.mode(SaveMode.Append)
.save(loadLocation(tableIdentifier));

long s1 = table.currentSnapshot().snapshotId();

withSQLConf(
// set write option through session configuration
ImmutableMap.of("spark.datasource.iceberg.snapshot-property.foo", "bar"),
() -> {
df.select("id", "data")
.write()
.format("iceberg")
.mode(SaveMode.Append)
.save(loadLocation(tableIdentifier));
});

table.refresh();
assertThat(table.currentSnapshot().summary()).containsEntry("foo", "bar");

withSQLConf(
// set read option through session configuration
ImmutableMap.of("spark.datasource.iceberg.snapshot-id", String.valueOf(s1)),
() -> {
Dataset<Row> result = spark.read().format("iceberg").load(loadLocation(tableIdentifier));
List<SimpleRecord> actual = result.as(Encoders.bean(SimpleRecord.class)).collectAsList();
assertThat(actual)
.as("Rows must match")
.containsExactlyInAnyOrderElementsOf(initialRecords);
});
}

private GenericData.Record manifestRecord(
Table manifestTable, Long referenceSnapshotId, ManifestFile manifest) {
GenericRecordBuilder builder =
Expand Down