xtern commented on code in PR #2105:
URL: https://github.com/apache/ignite-3/pull/2105#discussion_r1217769560


##########
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 you ignore precision and length from params?
   
   Currently I don't have length in params. After parsing we have RelDataType, 
which doesn't have a length.
   But since there is a length in the TableColumnDescriptor - for 
VARCHAR/VARBINARY precision is used as the length.
   
   If you think this is the wrong place for this transformation, I can add 
length to the params and set it earlier, when converting, WDYT?



-- 
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]

Reply via email to