use of io.crate.exceptions.TableAlreadyExistsException in project crate by crate.
the class CreateTableAnalyzedStatement method table.
public void table(TableIdent tableIdent, boolean ifNotExists, Schemas schemas) {
tableIdent.validate();
if (ifNotExists) {
noOp = schemas.tableExists(tableIdent);
} else if (schemas.tableExists(tableIdent)) {
throw new TableAlreadyExistsException(tableIdent);
}
this.ifNotExists = ifNotExists;
this.tableIdent = tableIdent;
}
use of io.crate.exceptions.TableAlreadyExistsException in project crate by crate.
the class RestoreSnapshotAnalyzer method analyze.
public RestoreSnapshotAnalyzedStatement analyze(RestoreSnapshot node, Analysis analysis) {
List<String> nameParts = node.name().getParts();
Preconditions.checkArgument(nameParts.size() == 2, "Snapshot name not supported, only <repository>.<snapshot> works.");
String repositoryName = nameParts.get(0);
repositoryService.failIfRepositoryDoesNotExist(repositoryName);
// validate and extract settings
Settings settings = GenericPropertiesConverter.settingsFromProperties(node.properties(), analysis.parameterContext(), SETTINGS).build();
if (node.tableList().isPresent()) {
List<Table> tableList = node.tableList().get();
Set<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> restoreTables = new HashSet<>(tableList.size());
for (Table table : tableList) {
TableIdent tableIdent = TableIdent.of(table, analysis.sessionContext().defaultSchema());
boolean tableExists = schemas.tableExists(tableIdent);
if (tableExists) {
if (table.partitionProperties().isEmpty()) {
throw new TableAlreadyExistsException(tableIdent);
}
TableInfo tableInfo = schemas.getTableInfo(tableIdent);
if (!(tableInfo instanceof DocTableInfo)) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Cannot restore snapshot of tables in schema '%s'", tableInfo.ident().schema()));
}
DocTableInfo docTableInfo = ((DocTableInfo) tableInfo);
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, docTableInfo, table.partitionProperties(), analysis.parameterContext().parameters());
if (docTableInfo.partitions().contains(partitionName)) {
throw new PartitionAlreadyExistsException(partitionName);
}
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
} else {
if (table.partitionProperties().isEmpty()) {
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, null));
} else {
PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableIdent, null, table.partitionProperties(), analysis.parameterContext().parameters());
restoreTables.add(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(tableIdent, partitionName));
}
}
}
return RestoreSnapshotAnalyzedStatement.forTables(nameParts.get(1), repositoryName, settings, ImmutableList.copyOf(restoreTables));
} else {
return RestoreSnapshotAnalyzedStatement.all(nameParts.get(1), repositoryName, settings);
}
}
Aggregations