Search in sources :

Example 6 with NodeLocation

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."));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Type(io.confluent.ksql.execution.expression.tree.Type) NodeLocation(io.confluent.ksql.parser.NodeLocation) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) Test(org.junit.Test)

Example 7 with NodeLocation

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."));
}
Also used : ColumnName(io.confluent.ksql.name.ColumnName) Type(io.confluent.ksql.execution.expression.tree.Type) NodeLocation(io.confluent.ksql.parser.NodeLocation) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) Test(org.junit.Test)

Aggregations

NodeLocation (io.confluent.ksql.parser.NodeLocation)7 Type (io.confluent.ksql.execution.expression.tree.Type)3 Test (org.junit.Test)3 ColumnName (io.confluent.ksql.name.ColumnName)2 ParsingException (io.confluent.ksql.parser.ParsingException)2 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)2 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)1 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)1 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)1 HoppingWindowExpression (io.confluent.ksql.execution.windows.HoppingWindowExpression)1 KsqlWindowExpression (io.confluent.ksql.execution.windows.KsqlWindowExpression)1 SessionWindowExpression (io.confluent.ksql.execution.windows.SessionWindowExpression)1 TumblingWindowExpression (io.confluent.ksql.execution.windows.TumblingWindowExpression)1 WindowTimeClause (io.confluent.ksql.execution.windows.WindowTimeClause)1 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)1 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)1 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)1 RefinementInfo (io.confluent.ksql.serde.RefinementInfo)1 Type (io.confluent.ksql.test.parser.TestDirective.Type)1