use of io.confluent.ksql.parser.NodeLocation in project ksql by confluentinc.
the class CreateStreamTest method shouldThrowOnNonePrimaryKey.
@Test
public void shouldThrowOnNonePrimaryKey() {
// Given:
final NodeLocation loc = new NodeLocation(2, 3);
final ColumnName name = ColumnName.of("PK");
final TableElements invalidElements = TableElements.of(new TableElement(Optional.of(loc), name, new Type(SqlTypes.STRING), PRIMARY_KEY_CONSTRAINT), new TableElement(Optional.of(new NodeLocation(3, 4)), ColumnName.of("values are always valid"), new Type(SqlTypes.STRING), ColumnConstraints.NO_COLUMN_CONSTRAINTS));
// When:
final ParseFailedException e = assertThrows(ParseFailedException.class, () -> new CreateStream(SOME_NAME, invalidElements, false, false, SOME_PROPS, false));
// Then:
assertThat(e.getMessage(), containsString("Line: 2, Col: 4: Column `PK` is a 'PRIMARY KEY' column: " + "please use 'KEY' for streams.\n" + "Tables have PRIMARY KEYs, which are unique and NON NULL.\n" + "Streams have KEYs, which have no uniqueness or NON NULL constraints."));
}
use of io.confluent.ksql.parser.NodeLocation in project ksql by confluentinc.
the class CreateTableTest method shouldThrowOnNonePrimaryKey.
@Test
public void shouldThrowOnNonePrimaryKey() {
// Given:
final NodeLocation loc = new NodeLocation(2, 3);
final ColumnName name = ColumnName.of("K");
final TableElements invalidElements = TableElements.of(new TableElement(Optional.of(loc), name, new Type(SqlTypes.STRING), KEY_CONSTRAINT), new TableElement(Optional.of(new NodeLocation(3, 4)), ColumnName.of("values are always valid"), new Type(SqlTypes.STRING), ColumnConstraints.NO_COLUMN_CONSTRAINTS));
// When:
final ParseFailedException e = assertThrows(ParseFailedException.class, () -> new CreateTable(SOME_NAME, invalidElements, false, false, SOME_PROPS, false));
// Then:
assertThat(e.getMessage(), containsString("Line: 2, Col: 4: Column `K` is a 'KEY' column: " + "please use 'PRIMARY KEY' for tables.\n" + "Tables have PRIMARY KEYs, which are unique and NON NULL.\n" + "Streams have KEYs, which have no uniqueness or NON NULL constraints."));
}
Aggregations