You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "xtern (via GitHub)" <gi...@apache.org> on 2026/02/20 09:03:22 UTC

[PR] IGNITE-27730 Added validation that nut null column must have default [ignite-3]

xtern opened a new pull request, #7640:
URL: https://github.com/apache/ignite-3/pull/7640

   https://issues.apache.org/jira/browse/IGNITE-27730


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840163627


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   Lets also check here
   ```suggestion
           sql("ALTER TABLE t ADD COLUMN val VARCHAR DEFAULT NULL");
   ```
   Seems, we have no end-to-end test for such case.
   
   Do we have similar end2end test for ALTER COLUMN? like this?
   ```
   sql("ALTER TABLE test ALTER COLUMN val SET NOT NULL DEFAULT NULL");
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840398000


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   Got it.
   We have no e2e test for changing non-nullable column `ALTER COLUMN SET DEFAULT NULL` 



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840112323


##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/commands/AlterTableAddColumnCommandValidationTest.java:
##########
@@ -219,6 +222,36 @@ void cannotAddColumnWithFunctionalDefault() {
         );
     }
 
+    @Test
+    void cannotAddNonNullableColumnWithoutDefault() {
+        String tableName = "TEST";
+        String columnName = "TEST";
+        Catalog catalog = catalogWithTable(builder -> builder
+                .schemaName(SCHEMA_NAME)
+                .tableName(tableName)
+                .columns(List.of(ColumnParams.builder().name("ID").type(INT32).build()))

Review Comment:
   ```suggestion
                   .columns(List.of(ColumnParams.builder().name("ID").type(INT32).nullable(false).build()))
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840364753


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   > Let's check NOT NULL DEFAULT NULL case as well
   
   This case is covered in test `ItAlterTableDdlTest`.`cannotAddNonNullableColumnWithoutDefault`
   
   > Do we have similar end2end test for ALTER COLUMN? like this?
   > sql("ALTER TABLE test ALTER COLUMN val SET NOT NULL DEFAULT NULL");
   
   Currently `ALTER COLUMN` has  2 limitations:
   1. We don't support such syntax SET NOT NULL + DEFAULT (but we can SET DEFAULT separately)
   2. NULL -> NOT NULL is not allowed even if column has default 
   
   Should we create an issue to support NULL -> NOT NULL for column with default?
   
   



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that nut null column must have default [ignite-3]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2832165168


##########
modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/AlterTableAddColumnCommand.java:
##########
@@ -125,6 +126,10 @@ private void validate() {
 
             ensureTypeCanBeStored(column.name(), column.type());
             ensureNonFunctionalDefault(column.name(), column.defaultValueDefinition());
+
+            if (!column.nullable() && ((ConstantValue) column.defaultValueDefinition()).value() == null) {
+                throw new CatalogValidationException("Non-nullable column '{}' must have the default value.", column.name());

Review Comment:
   This code performs an unsafe cast to ConstantValue without a null check or type verification. While ensureNonFunctionalDefault on line 128 ensures the default is not a FunctionCall, it allows null values to pass through. If defaultValueDefinition is null, the cast will succeed but calling value() will throw a NullPointerException instead of a meaningful validation error. Consider adding an explicit null check or using instanceof before casting to provide better error messages and ensure robustness.
   ```suggestion
               Object defaultValueDefinition = column.defaultValueDefinition();
   
               if (!column.nullable()) {
                   if (!(defaultValueDefinition instanceof ConstantValue)) {
                       throw new CatalogValidationException(
                               "Non-nullable column '{}' must have the default value.",
                               column.name()
                       );
                   }
   
                   ConstantValue constantDefault = (ConstantValue) defaultValueDefinition;
   
                   if (constantDefault.value() == null) {
                       throw new CatalogValidationException(
                               "Non-nullable column '{}' must have the default value.",
                               column.name()
                       );
                   }
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2841689884


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   Added test `dropDefaultNonNullableColumn` to `ItAlterTableAlterColumnTest`



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840171429


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   Also, I see only positive test for CREATE TABLE `ItDmlTest.testNullDefault`.
   Let's check `NOT NULL DEFAULT NULL` case as well



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Added validation that not null column must have default [ignite-3]

Posted by "AMashenkov (via GitHub)" <gi...@apache.org>.
AMashenkov commented on code in PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640#discussion_r2840398000


##########
modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItAlterTableDdlTest.java:
##########
@@ -240,6 +240,26 @@ public void doNotAllowFunctionsInNonPkColumns() {
         );
     }
 
+    @Test
+    public void cannotAddNonNullableColumnWithoutDefault() {
+        sql("CREATE TABLE t (id VARCHAR PRIMARY KEY)");
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL")
+        );
+
+        assertThrowsSqlException(
+                STMT_VALIDATION_ERR,
+                "Non-nullable column 'VAL' must have the default value",
+                () -> sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT NULL")
+        );
+
+        // Should not throw an exception since default value is provided.
+        sql("ALTER TABLE t ADD COLUMN val VARCHAR NOT NULL DEFAULT 'a'");

Review Comment:
   Got it.
   We have no e2e test for  changing for non-nullable column `ALTER COLUMN SET DEFAULT NULL` 



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-27730 Sql. Added validation that not null column must have default value [ignite-3]

Posted by "xtern (via GitHub)" <gi...@apache.org>.
xtern merged PR #7640:
URL: https://github.com/apache/ignite-3/pull/7640


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org