tech.ydb.table.settings.AlterTableSettings Maven / Gradle / Ivy
package tech.ydb.table.settings;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import tech.ydb.table.description.TableColumn;
import tech.ydb.table.description.TableIndex;
import tech.ydb.table.values.OptionalType;
import tech.ydb.table.values.Type;
/**
* @author Sergey Polovko
*/
public class AlterTableSettings extends RequestSettings {
private final Map addColumns = new HashMap<>();
private final Map addChangefeeds = new HashMap<>();
private final Map addIndexes = new HashMap<>();
private final Set dropColumns = new HashSet<>();
private final Set dropChangefeeds = new HashSet<>();
private final Set dropIndexes = new HashSet<>();
@Nullable
private TtlSettings ttlSettings;
@Nullable
private PartitioningSettings partitioningSettings;
public AlterTableSettings() {
}
@Deprecated
public AlterTableSettings addColumn(String name, Type type) {
addColumns.put(name, new TableColumn(name, type));
return this;
}
public AlterTableSettings addNonnullColumn(String name, Type type) {
addColumns.put(name, new TableColumn(name, type));
return this;
}
public AlterTableSettings addNonnullColumn(String name, Type type, String family) {
addColumns.put(name, new TableColumn(name, type, family));
return this;
}
public AlterTableSettings addNullableColumn(String name, Type type) {
addColumns.put(name, new TableColumn(name, OptionalType.of(type)));
return this;
}
public AlterTableSettings addNullableColumn(String name, Type type, String family) {
addColumns.put(name, new TableColumn(name, OptionalType.of(type), family));
return this;
}
public AlterTableSettings dropColumn(String name) {
dropColumns.add(name);
return this;
}
public AlterTableSettings addChangefeed(Changefeed changefeed) {
addChangefeeds.put(changefeed.getName(), changefeed);
return this;
}
public AlterTableSettings dropChangefeed(String changefeed) {
dropChangefeeds.add(changefeed);
return this;
}
public AlterTableSettings addGlobalIndex(String name, List columns) {
addIndexes.put(name, new TableIndex(name, columns, TableIndex.Type.GLOBAL));
return this;
}
public AlterTableSettings addGlobalIndex(String name, List columns, List dataColumns) {
addIndexes.put(name, new TableIndex(name, columns, dataColumns, TableIndex.Type.GLOBAL));
return this;
}
public AlterTableSettings addGlobalAsyncIndex(String name, List columns) {
addIndexes.put(name, new TableIndex(name, columns, TableIndex.Type.GLOBAL_ASYNC));
return this;
}
public AlterTableSettings addGlobalAsyncIndex(String name, List columns, List dataColumns) {
addIndexes.put(name, new TableIndex(name, columns, dataColumns, TableIndex.Type.GLOBAL_ASYNC));
return this;
}
public AlterTableSettings dropIndex(String index) {
dropIndexes.add(index);
return this;
}
public AlterTableSettings setTtlSettings(@Nullable TtlSettings ttlSettings) {
this.ttlSettings = ttlSettings;
return this;
}
public AlterTableSettings setPartitioningSettings(@Nullable PartitioningSettings partitioningSettings) {
this.partitioningSettings = partitioningSettings;
return this;
}
public Collection getAddColumns() {
return addColumns.values();
}
public Collection getAddChangefeeds() {
return addChangefeeds.values();
}
public Collection getAddIndexes() {
return addIndexes.values();
}
public Collection getDropColumns() {
return dropColumns;
}
public Collection getDropChangefeeds() {
return dropChangefeeds;
}
public Collection getDropIndexes() {
return dropIndexes;
}
@Nullable
public TtlSettings getTtlSettings() {
return ttlSettings;
}
@Nullable
public PartitioningSettings getPartitioningSettings() {
return partitioningSettings;
}
@Deprecated
public void forEachAddColumn(BiConsumer fn) {
addColumns.values().forEach(c -> fn.accept(c.getName(), c.getType()));
}
@Deprecated
public void forEachDropColumn(Consumer fn) {
dropColumns.forEach(fn);
}
@Deprecated
public void forEachAddChangefeed(Consumer fn) {
addChangefeeds.values().forEach(fn);
}
@Deprecated
public void forEachDropChangefeed(Consumer fn) {
dropChangefeeds.forEach(fn);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy