Search in sources :

Example 1 with SnapshotTable

use of org.apache.iceberg.actions.SnapshotTable in project iceberg by apache.

the class SnapshotTableProcedure method call.

@Override
public InternalRow[] call(InternalRow args) {
    String source = args.getString(0);
    Preconditions.checkArgument(source != null && !source.isEmpty(), "Cannot handle an empty identifier for argument source_table");
    String dest = args.getString(1);
    Preconditions.checkArgument(dest != null && !dest.isEmpty(), "Cannot handle an empty identifier for argument table");
    String snapshotLocation = args.isNullAt(2) ? null : args.getString(2);
    Map<String, String> properties = Maps.newHashMap();
    if (!args.isNullAt(3)) {
        args.getMap(3).foreach(DataTypes.StringType, DataTypes.StringType, (k, v) -> {
            properties.put(k.toString(), v.toString());
            return BoxedUnit.UNIT;
        });
    }
    Preconditions.checkArgument(!source.equals(dest), "Cannot create a snapshot with the same name as the source of the snapshot.");
    SnapshotTable action = SparkActions.get().snapshotTable(source).as(dest);
    if (snapshotLocation != null) {
        action.tableLocation(snapshotLocation);
    }
    SnapshotTable.Result result = action.tableProperties(properties).execute();
    return new InternalRow[] { newInternalRow(result.importedDataFilesCount()) };
}
Also used : SnapshotTable(org.apache.iceberg.actions.SnapshotTable) InternalRow(org.apache.spark.sql.catalyst.InternalRow)

Aggregations

SnapshotTable (org.apache.iceberg.actions.SnapshotTable)1 InternalRow (org.apache.spark.sql.catalyst.InternalRow)1