Skip to content

Commit

Permalink
IGNITE-20600 Sql. Fix a message of an error, which occurs while updat…
Browse files Browse the repository at this point in the history
…ing primary key column (#2695)
  • Loading branch information
lowka committed Oct 18, 2023
1 parent 7953fab commit 7aa17fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IgniteResource {
@Resources.BaseMessage("Illegal alias. {0} is reserved name")
Resources.ExInst<SqlValidatorException> illegalAlias(String a0);

@Resources.BaseMessage("Cannot update field \"{0}\". You cannot update key, key fields or val field in case the val is a complex type")
@Resources.BaseMessage("Cannot update field \"{0}\". Primary key columns are not modifiable")
Resources.ExInst<SqlValidatorException> cannotUpdateField(String field);

@Resources.BaseMessage("Illegal aggregate function. {0} is unsupported at the moment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,36 @@ private static Stream<String> basicStatements() {
);
}

/**
* Tests that primary key columns are not modifiable.
*/
@ParameterizedTest
@MethodSource("updatePrimaryKey")
public void testDoNotAllowToModifyPrimaryKeyColumns(String query) {
TestTable test = TestBuilders.table()
.name("TEST")
.addKeyColumn("ID", NativeTypes.INT32)
.addColumn("VAL", NativeTypes.INT32)
.distribution(IgniteDistributions.single())
.build();

IgniteSchema schema = createSchema(test);

IgniteTestUtils.assertThrowsWithCause(
() -> physicalPlan(query, schema),
SqlValidatorException.class,
"Primary key columns are not modifiable"
);
}

private static Stream<String> updatePrimaryKey() {
return Stream.of(
"UPDATE TEST SET ID = ID + 1",
"MERGE INTO test DST USING test SRC ON DST.VAL = SRC.VAL"
+ " WHEN MATCHED THEN UPDATE SET ID = SRC.ID + 1"
);
}

// Class name is fully-qualified because AbstractPlannerTest defines a class with the same name.
private static TestTable newTestTable(String tableName, IgniteDistribution distribution) {
return TestBuilders.table()
Expand Down

0 comments on commit 7aa17fe

Please sign in to comment.