use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class SchemaParserTest method shouldParseValidSchemaWithHeaderField.
@Test
public void shouldParseValidSchemaWithHeaderField() {
// Given:
final String schema = "K STRING HEADERS, bar INT";
// When:
final TableElements elements = parser.parse(schema);
// Then:
assertThat(elements, contains(new TableElement(ColumnName.of("K"), new Type(SqlTypes.STRING), HEADERS_CONSTRAINT), new TableElement(BAR, new Type(SqlTypes.INTEGER))));
}
use of io.confluent.ksql.execution.expression.tree.Type 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.execution.expression.tree.Type 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."));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class FeatureFlagCheckerTest method shouldNotThrowOnCreateStreamWithHeadersIfFeatureFlagIsEnabled.
@Test
public void shouldNotThrowOnCreateStreamWithHeadersIfFeatureFlagIsEnabled() {
// Given
final KsqlConfig config = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_HEADERS_COLUMNS_ENABLED, true));
final CreateStream createStream = new CreateStream(SourceName.of("stream1"), TableElements.of(new TableElement(ColumnName.of("col1"), new Type(SqlTypes.INTEGER), new ColumnConstraints.Builder().headers().build())), false, false, CreateSourceProperties.from(ImmutableMap.of(CommonCreateConfigs.KAFKA_TOPIC_NAME_PROPERTY, new StringLiteral("topic1"))), false);
final ConfiguredStatement configuredStatement = configured(config, createStream);
// When/Then
FeatureFlagChecker.throwOnDisabledFeatures(configuredStatement);
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class TableElementTest method shouldReturnKeyConstraint.
@Test
public void shouldReturnKeyConstraint() {
// Given:
final TableElement valueElement = new TableElement(NAME, new Type(SqlTypes.STRING), KEY_CONSTRAINT);
// Then:
assertThat(valueElement.getConstraints(), is(KEY_CONSTRAINT));
}
Aggregations