Search in sources :

Example 31 with Type

use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.

the class SchemaParserTest method shouldParseValidSchema.

@Test
public void shouldParseValidSchema() {
    // Given:
    final String schema = "foo INTEGER, bar MAP<VARCHAR, VARCHAR>";
    // When:
    final TableElements elements = parser.parse(schema);
    // Then:
    assertThat(elements, contains(new TableElement(FOO, new Type(SqlTypes.INTEGER)), new TableElement(BAR, new Type(SqlTypes.map(SqlTypes.STRING, SqlTypes.STRING)))));
}
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 32 with Type

use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.

the class SchemaParserTest method shouldParseValidSchemaWithSingleHeaderKeyField.

@Test
public void shouldParseValidSchemaWithSingleHeaderKeyField() {
    // Given:
    final String schema = "K STRING HEADER('k1'), bar INT";
    // When:
    final TableElements elements = parser.parse(schema);
    // Then:
    assertThat(elements, contains(new TableElement(ColumnName.of("K"), new Type(SqlTypes.STRING), HEADER_KEY1_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 33 with Type

use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.

the class TableElementTest method shouldReturnType.

@Test
public void shouldReturnType() {
    // Given:
    final TableElement element = new TableElement(NAME, new Type(SqlTypes.STRING));
    // Then:
    assertThat(element.getType(), is(new Type(SqlTypes.STRING)));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) Test(org.junit.Test)

Example 34 with Type

use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.

the class TableElementsTest method shouldBuildLogicalSchemaWithWithHeaders.

@Test
public void shouldBuildLogicalSchemaWithWithHeaders() {
    // Given:
    final TableElements tableElements = TableElements.of(tableElement("v0", INT_TYPE), tableElement("h0", new Type(SqlArray.of(SqlStruct.builder().field("KEY", SqlTypes.STRING).field("VALUE", SqlTypes.BYTES).build())), HEADERS_CONSTRAINT));
    // When:
    final LogicalSchema schema = tableElements.toLogicalSchema();
    // Then:
    assertThat(schema, is(LogicalSchema.builder().valueColumn(ColumnName.of("v0"), SqlTypes.INTEGER).headerColumn(ColumnName.of("h0"), Optional.empty()).build()));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Test(org.junit.Test)

Example 35 with Type

use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.

the class FeatureFlagCheckerTest method shouldThrowOnCreateStreamWithHeadersIfFeatureFlagIsDisabled.

@Test
public void shouldThrowOnCreateStreamWithHeadersIfFeatureFlagIsDisabled() {
    // Given
    final KsqlConfig config = new KsqlConfig(ImmutableMap.of(KsqlConfig.KSQL_HEADERS_COLUMNS_ENABLED, false));
    final CreateStream createStream = new CreateStream(SourceName.of("stream1"), TableElements.of(new TableElement(ColumnName.of("col1"), new Type(SqlArray.of(SqlStruct.builder().field("KEY", SqlTypes.STRING).field("VALUE", SqlTypes.BYTES).build())), 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
    final Exception e = assertThrows(KsqlException.class, () -> FeatureFlagChecker.throwOnDisabledFeatures(configuredStatement));
    // Then
    assertThat(e.getMessage(), containsString("Cannot create Stream because schema with headers columns is disabled."));
}
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) KsqlException(io.confluent.ksql.util.KsqlException) 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