AMashenkov commented on code in PR #1109:
URL: https://github.com/apache/ignite-3/pull/1109#discussion_r977801767


##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/ColumnTypeValidatorImpl.java:
##########
@@ -53,11 +50,81 @@ public void validate(ColumnTypeValidator annotation, 
ValidationContext<ColumnTyp
                 || newType.precision() != oldType.precision()
                 || newType.scale() != oldType.scale()
                 || newType.length() != oldType.length()) {
-            ctx.addIssue(new ValidationIssue(ctx.currentKey(), "Unsupported 
column type change: " + ctx.currentKey()));
+            ColumnView columnView = ctx.getNewOwner();
+
+            assert columnView != null;
+
+            ctx.addIssue(new ValidationIssue(columnView.name(), "Column type 
can't be changed"));
         }
 
     }
 
+    private void validateLength(ValidationContext<ColumnTypeView> ctx, 
ColumnTypeView typeView) {
+        switch (typeView.type()) {
+            case "STRING":
+            case "BYTES":
+            case "BITMASK":
+                if (typeView.length() <= 0) {
+                    ColumnView columnView = ctx.getNewOwner();
+
+                    assert columnView != null;
+
+                    ctx.addIssue(new ValidationIssue(columnView.name(), 
"Length must by positive"));
+                }
+
+                break;
+            default:
+                // nothing to do
+                break;
+        }
+    }
+
+    private void validatePrecision(ValidationContext<ColumnTypeView> ctx, 
ColumnTypeView typeView) {
+        switch (typeView.type()) {
+            case "NUMBER":
+            case "DECIMAL":
+                if (typeView.precision() <= 0) {
+                    ColumnView columnView = ctx.getNewOwner();
+
+                    assert columnView != null;
+
+                    ctx.addIssue(new ValidationIssue(columnView.name(), 
"Precision must by positive"));

Review Comment:
   ```suggestion
                       ctx.addIssue(new ValidationIssue(columnView.name(), 
"Precision must be positive"));
   ```



##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/configuration/ColumnTypeValidatorImpl.java:
##########
@@ -53,11 +50,81 @@ public void validate(ColumnTypeValidator annotation, 
ValidationContext<ColumnTyp
                 || newType.precision() != oldType.precision()
                 || newType.scale() != oldType.scale()
                 || newType.length() != oldType.length()) {
-            ctx.addIssue(new ValidationIssue(ctx.currentKey(), "Unsupported 
column type change: " + ctx.currentKey()));
+            ColumnView columnView = ctx.getNewOwner();
+
+            assert columnView != null;
+
+            ctx.addIssue(new ValidationIssue(columnView.name(), "Column type 
can't be changed"));
         }
 
     }
 
+    private void validateLength(ValidationContext<ColumnTypeView> ctx, 
ColumnTypeView typeView) {
+        switch (typeView.type()) {
+            case "STRING":
+            case "BYTES":
+            case "BITMASK":
+                if (typeView.length() <= 0) {
+                    ColumnView columnView = ctx.getNewOwner();
+
+                    assert columnView != null;
+
+                    ctx.addIssue(new ValidationIssue(columnView.name(), 
"Length must by positive"));
+                }
+
+                break;
+            default:
+                // nothing to do
+                break;
+        }
+    }
+
+    private void validatePrecision(ValidationContext<ColumnTypeView> ctx, 
ColumnTypeView typeView) {
+        switch (typeView.type()) {
+            case "NUMBER":
+            case "DECIMAL":
+                if (typeView.precision() <= 0) {
+                    ColumnView columnView = ctx.getNewOwner();
+
+                    assert columnView != null;
+
+                    ctx.addIssue(new ValidationIssue(columnView.name(), 
"Precision must by positive"));
+                }
+
+                break;
+
+            case "TIME":
+            case "DATETIME":
+            case "TIMESTAMP":
+                if (typeView.precision() < 0 || typeView.precision() > 9) {
+                    ColumnView columnView = ctx.getNewOwner();
+
+                    assert columnView != null;
+
+                    ctx.addIssue(new ValidationIssue(columnView.name(), 
"Precision must by in range [0-9]"));

Review Comment:
   ```suggestion
                       ctx.addIssue(new ValidationIssue(columnView.name(), 
"Precision must be in range [0-9]"));
   ```



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