Search in sources :

Example 61 with Type

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))));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) TableElements(io.confluent.ksql.parser.tree.TableElements) Matchers.containsString(org.hamcrest.Matchers.containsString) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 62 with Type

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."));
}
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 63 with Type

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."));
}
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 64 with Type

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);
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Type(io.confluent.ksql.execution.expression.tree.Type) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ColumnConstraints(io.confluent.ksql.parser.tree.ColumnConstraints) KsqlConfig(io.confluent.ksql.util.KsqlConfig) CreateStream(io.confluent.ksql.parser.tree.CreateStream) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 65 with Type

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));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) Test(org.junit.Test)

Aggregations

Type (io.confluent.ksql.execution.expression.tree.Type)73 Test (org.junit.Test)71 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)23 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)19 Matchers.containsString (org.hamcrest.Matchers.containsString)16 Cast (io.confluent.ksql.execution.expression.tree.Cast)13 CreateStream (io.confluent.ksql.parser.tree.CreateStream)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)12 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)12 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)12 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)12