79282683

Date: 2024-12-15 16:14:33
Score: 1
Natty:
Report link

Commenting to follow. I have a different issue but this is closely related. I need to update snapshot properties after table is written due to work flows. Pyspark doesn’t seem to have a way I’ve only seen Java used

    import org.apache.iceberg.*;
    import org.apache.iceberg.nessie.NessieCatalog;
import org.apache.iceberg.catalog.TableIdentifier;
import io.kontainers.iceberg.nessie.NessieConfig;
import java.util.HashMap;
import java.util.Map;

public class ModifySnapshotExample {
    public static void main(String[] args) {
        // Connect to the Nessie catalog
        String nessieUrl = "http://your-nessie-server:19120";
        String catalogName = "nessie";
        String database = "your_database";
        String tableName = "your_table";

        NessieConfig config = new NessieConfig();
        config.setNessieUri(nessieUrl);

        // Instantiate the Nessie catalog
        NessieCatalog catalog = new NessieCatalog();
        catalog.configure(config);

        // Load the Iceberg table from the Nessie catalog
        Table table = catalog.loadTable(TableIdentifier.of(database, tableName));

        // Retrieve the current snapshot
        Snapshot currentSnapshot = table.currentSnapshot();
        if (currentSnapshot != null) {
            System.out.println("Current Snapshot ID: " + currentSnapshot.snapshotId());

            // Create a map of new properties to add to the snapshot
            Map<String, String> newProperties = new HashMap<>();
            newProperties.put("snapshot.custom.property", "new_value");

            // Apply the new properties to the snapshot
            // You could use the commit API or table metadata API
            table.updateProperties()
                 .set("snapshot.custom.property", "new_value")
                 .commit();

            System.out.println("Snapshot properties updated.");
        } else {
            System.out.println("No snapshot found.");
        }
    }
}`enter code here

`

But seems clunky.

Any other advice is appreciated.

Reasons:
  • Blacklisted phrase (1): appreciated
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Tobias Caouette