Search in sources :

Example 16 with Type

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

the class CreateSourceFactoryTest method shouldAllowNonStringKeyColumn.

@Test
public void shouldAllowNonStringKeyColumn() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("k", new Type(SqlTypes.INTEGER), KEY_CONSTRAINT)), false, true, withProperties, false);
    // When:
    final CreateStreamCommand cmd = createSourceFactory.createStreamCommand(statement, ksqlConfig);
    // Then:
    assertThat(cmd.getSchema().key(), contains(keyColumn(ColumnName.of("k"), SqlTypes.INTEGER)));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStreamCommand(io.confluent.ksql.execution.ddl.commands.CreateStreamCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 17 with Type

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

the class RegisterTypeFactoryTest method shouldCreateCommandForRegisterTypeWhenIfNotExitsSet.

@Test
public void shouldCreateCommandForRegisterTypeWhenIfNotExitsSet() {
    // Given:
    final RegisterType ddlStatement = new RegisterType(Optional.empty(), NOT_EXISTING_TYPE, new Type(SqlStruct.builder().field("foo", SqlPrimitiveType.of(SqlBaseType.STRING)).build()), true);
    // When:
    final RegisterTypeCommand result = factory.create(ddlStatement);
    // Then:
    assertThat(result.getType(), equalTo(ddlStatement.getType().getSqlType()));
    assertThat(result.getTypeName(), equalTo(NOT_EXISTING_TYPE));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) RegisterType(io.confluent.ksql.parser.tree.RegisterType) RegisterType(io.confluent.ksql.parser.tree.RegisterType) RegisterTypeCommand(io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand) Test(org.junit.Test)

Example 18 with Type

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

the class RegisterTypeFactoryTest method shouldCreateCommandForRegisterTypeWhenIfNotExitsNotSet.

@Test
public void shouldCreateCommandForRegisterTypeWhenIfNotExitsNotSet() {
    // Given:
    final RegisterType ddlStatement = new RegisterType(Optional.empty(), NOT_EXISTING_TYPE, new Type(SqlStruct.builder().field("foo", SqlPrimitiveType.of(SqlBaseType.STRING)).build()), false);
    // When:
    final RegisterTypeCommand result = factory.create(ddlStatement);
    // Then:
    assertThat(result.getType(), equalTo(ddlStatement.getType().getSqlType()));
    assertThat(result.getTypeName(), equalTo(NOT_EXISTING_TYPE));
}
Also used : Type(io.confluent.ksql.execution.expression.tree.Type) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) RegisterType(io.confluent.ksql.parser.tree.RegisterType) RegisterType(io.confluent.ksql.parser.tree.RegisterType) RegisterTypeCommand(io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand) Test(org.junit.Test)

Example 19 with Type

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

the class CreateSourceFactoryTest method shouldNotThrowOnCreateTableIfNotExistsIsSet.

@Test
public void shouldNotThrowOnCreateTableIfNotExistsIsSet() {
    // Given
    final CreateTable ddlStatement = new CreateTable(TABLE_NAME, TableElements.of(tableElement("COL1", new Type(BIGINT), PRIMARY_KEY_CONSTRAINT), tableElement("COL2", new Type(SqlTypes.STRING))), false, true, withProperties, false);
    // When:
    final CreateTableCommand result = createSourceFactory.createTableCommand(ddlStatement, ksqlConfig);
    // Then:
    assertThat(result.getSourceName(), is(TABLE_NAME));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateTable(io.confluent.ksql.parser.tree.CreateTable) CreateTableCommand(io.confluent.ksql.execution.ddl.commands.CreateTableCommand) Test(org.junit.Test)

Example 20 with Type

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

the class CreateSourceFactoryTest method shouldThrowOnWindowStartValueColumn.

@Test
public void shouldThrowOnWindowStartValueColumn() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement(WINDOWSTART_NAME.text(), new Type(BIGINT))), false, true, withProperties, false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> createSourceFactory.createStreamCommand(statement, ksqlConfig));
    // Then:
    assertThat(e.getMessage(), containsString("'WINDOWSTART' is a reserved column name."));
}
Also used : DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) Type(io.confluent.ksql.execution.expression.tree.Type) CreateStream(io.confluent.ksql.parser.tree.CreateStream) 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