Search in sources :

Example 1 with ColumnChange

use of org.apache.spark.sql.connector.catalog.TableChange.ColumnChange in project iceberg by apache.

the class SparkCatalog method alterTable.

@Override
public SparkTable alterTable(Identifier ident, TableChange... changes) throws NoSuchTableException {
    SetProperty setLocation = null;
    SetProperty setSnapshotId = null;
    SetProperty pickSnapshotId = null;
    List<TableChange> propertyChanges = Lists.newArrayList();
    List<TableChange> schemaChanges = Lists.newArrayList();
    for (TableChange change : changes) {
        if (change instanceof SetProperty) {
            SetProperty set = (SetProperty) change;
            if (TableCatalog.PROP_LOCATION.equalsIgnoreCase(set.property())) {
                setLocation = set;
            } else if ("current-snapshot-id".equalsIgnoreCase(set.property())) {
                setSnapshotId = set;
            } else if ("cherry-pick-snapshot-id".equalsIgnoreCase(set.property())) {
                pickSnapshotId = set;
            } else if ("sort-order".equalsIgnoreCase(set.property())) {
                throw new UnsupportedOperationException("Cannot specify the 'sort-order' because it's a reserved table " + "property. Please use the command 'ALTER TABLE ... WRITE ORDERED BY' to specify write sort-orders.");
            } else {
                propertyChanges.add(set);
            }
        } else if (change instanceof RemoveProperty) {
            propertyChanges.add(change);
        } else if (change instanceof ColumnChange) {
            schemaChanges.add(change);
        } else {
            throw new UnsupportedOperationException("Cannot apply unknown table change: " + change);
        }
    }
    try {
        Table table = load(ident).first();
        commitChanges(table, setLocation, setSnapshotId, pickSnapshotId, propertyChanges, schemaChanges);
        return new SparkTable(table, true);
    } catch (org.apache.iceberg.exceptions.NoSuchTableException e) {
        throw new NoSuchTableException(ident);
    }
}
Also used : RemoveProperty(org.apache.spark.sql.connector.catalog.TableChange.RemoveProperty) StagedSparkTable(org.apache.iceberg.spark.source.StagedSparkTable) StagedTable(org.apache.spark.sql.connector.catalog.StagedTable) Table(org.apache.iceberg.Table) SparkTable(org.apache.iceberg.spark.source.SparkTable) ColumnChange(org.apache.spark.sql.connector.catalog.TableChange.ColumnChange) NoSuchTableException(org.apache.spark.sql.catalyst.analysis.NoSuchTableException) SetProperty(org.apache.spark.sql.connector.catalog.TableChange.SetProperty) StagedSparkTable(org.apache.iceberg.spark.source.StagedSparkTable) SparkTable(org.apache.iceberg.spark.source.SparkTable) TableChange(org.apache.spark.sql.connector.catalog.TableChange)

Aggregations

Table (org.apache.iceberg.Table)1 SparkTable (org.apache.iceberg.spark.source.SparkTable)1 StagedSparkTable (org.apache.iceberg.spark.source.StagedSparkTable)1 NoSuchTableException (org.apache.spark.sql.catalyst.analysis.NoSuchTableException)1 StagedTable (org.apache.spark.sql.connector.catalog.StagedTable)1 TableChange (org.apache.spark.sql.connector.catalog.TableChange)1 ColumnChange (org.apache.spark.sql.connector.catalog.TableChange.ColumnChange)1 RemoveProperty (org.apache.spark.sql.connector.catalog.TableChange.RemoveProperty)1 SetProperty (org.apache.spark.sql.connector.catalog.TableChange.SetProperty)1