xtern commented on code in PR #2119:
URL: https://github.com/apache/ignite-3/pull/2119#discussion_r1210560522
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java:
##########
@@ -205,13 +215,84 @@ public CompletableFuture<Void> dropTable(DropTableParams
params) {
/** {@inheritDoc} */
@Override
public CompletableFuture<Void> addColumn(AlterTableAddColumnParams params)
{
- return failedFuture(new UnsupportedOperationException("Not implemented
yet."));
+ if (params.columns().isEmpty()) {
+ return completedFuture(null);
+ }
+
+ return saveUpdate(catalog -> {
+ String schemaName =
Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
+
+ SchemaDescriptor schema =
Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " +
schemaName);
+
+ TableDescriptor table = schema.table(params.tableName());
+
+ if (table == null) {
+ throw new TableNotFoundException(schemaName,
params.tableName());
+ }
+
+ List<TableColumnDescriptor> columnDescriptors = new ArrayList<>();
+
+ for (ColumnParams col : params.columns()) {
+ if (table.column(col.name()) != null) {
+ throw new ColumnAlreadyExistsException(col.name());
+ }
+
+ columnDescriptors.add(CatalogUtils.fromParams(col));
+ }
+
+ return List.of(
+ new NewColumnsEntry(table.id(), columnDescriptors)
+ );
+ });
}
/** {@inheritDoc} */
@Override
public CompletableFuture<Void> dropColumn(AlterTableDropColumnParams
params) {
- return failedFuture(new UnsupportedOperationException("Not implemented
yet."));
+ if (params.columns().isEmpty()) {
+ return completedFuture(null);
+ } else if (params.columns().size() > 1 && params.ifColumnExists()) {
+ return failedFuture(new UnsupportedOperationException("Clause 'IF
NOT EXISTS' is not supported when adding multiple columns."));
+ }
+
+ return saveUpdate(catalog -> {
+ String schemaName =
Objects.requireNonNullElse(params.schemaName(), CatalogService.PUBLIC);
+
+ SchemaDescriptor schema =
Objects.requireNonNull(catalog.schema(schemaName), "No schema found: " +
schemaName);
+
+ TableDescriptor table = schema.table(params.tableName());
+
+ if (table == null) {
+ throw new TableNotFoundException(schemaName,
params.tableName());
+ }
+
+ Arrays.stream(schema.indexes())
+ .filter(index -> index.tableId() == table.id())
+ .flatMap(index -> index.columns().stream())
+ .filter(col -> params.columns().contains(col))
+ .findAny()
+ .ifPresent(columnName -> {
+ throw new IllegalArgumentException("Can't drop indexed
column: column=" + columnName);
+ });
+
+ for (String columnName : params.columns()) {
+ if (table.column(columnName) == null) {
+ throw new ColumnNotFoundException(columnName);
+ }
+ if (table.isPrimaryKeyColumn(columnName)) {
Review Comment:
Since the primary key column is always indexed column - this condition will
be hidden by the previous "indexed column" check. I suggest to move this before
"indexed column" check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]