AMashenkov commented on code in PR #2105:
URL: https://github.com/apache/ignite-3/pull/2105#discussion_r1217745926
##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogServiceImpl.java:
##########
@@ -321,6 +341,89 @@ public CompletableFuture<Void>
dropColumn(AlterTableDropColumnParams params) {
});
}
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<Void> alterColumn(AlterColumnParams params) {
+ 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());
+ }
+
+ String columnName = params.columnName();
+
+ Optional<TableColumnDescriptor> source =
table.columns().stream().filter(desc ->
desc.name().equals(columnName)).findFirst();
+
+ if (source.isEmpty()) {
+ throw new ColumnNotFoundException(columnName);
+ }
+
+ TableColumnDescriptor origin = source.get();
+
+ if (table.isPrimaryKeyColumn(origin.name())) {
+ if (params.notNull() != null) {
+ throwUnsupportedDdl("Cannot change NOT NULL for the
primary key column '{}'.", origin.name());
+ }
+
+ if (params.type() != null) {
+ throwUnsupportedDdl("Cannot change data type for primary
key column '{}'.", origin.name());
+ }
+ }
+
+ boolean nullable = !Objects.requireNonNullElse(params.notNull(),
!origin.nullable());
+ DefaultValue defaultValue =
Objects.requireNonNullElse(params.defaultValue(origin.type()),
origin.defaultValue());
+ ColumnType type = Objects.requireNonNullElse(params.type(),
origin.type());
+ int scale = Objects.requireNonNullElse(params.scale(),
origin.scale());
+
+ boolean varLenType = type == ColumnType.STRING || type ==
ColumnType.BYTE_ARRAY;
+ int precision = varLenType ? origin.precision() :
Objects.requireNonNullElse(params.precision(), origin.precision());
+ int length = varLenType ?
Objects.requireNonNullElse(params.precision(), origin.length()) :
origin.length();
Review Comment:
Why do we need a different logic for varlen types?
This logic is incorrect when you change fixlen to varlen, but this
transition is forbidden now.
Why do you ignore precision and length from params? Maybe there should be an
assert, that we don't expect any changes here?
Also, `Objects.requireNonNullElse(params.precision(), origin.length())` - I
guess, here should be `params.length()`
--
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]