Search in sources :

Example 46 with Type

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

the class CreateSourceFactoryTest method shouldCreateCommandForCreateTable.

@Test
public void shouldCreateCommandForCreateTable() {
    // Given:
    final CreateTable ddlStatement = new CreateTable(SOME_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(SOME_NAME));
    assertThat(result.getTopicName(), is(TOPIC_NAME));
    assertThat(result.getIsSource(), is(false));
}
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 47 with Type

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

the class RegisterTypeFactoryTest method shouldThrowOnRegisterExistingTypeWhenIfNotExistsNotSet.

@Test
public void shouldThrowOnRegisterExistingTypeWhenIfNotExistsNotSet() {
    // Given:
    final RegisterType ddlStatement = new RegisterType(Optional.empty(), EXISTING_TYPE, new Type(SqlStruct.builder().field("foo", SqlPrimitiveType.of(SqlBaseType.STRING)).build()), false);
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> factory.create(ddlStatement));
    // Then:
    assertThat(e.getMessage(), equalTo("Cannot register custom type '" + EXISTING_TYPE + "' since it is already registered with type: " + customType));
}
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) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 48 with Type

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

the class RegisterTypeFactoryTest method shouldNotThrowOnRegisterExistingTypeWhenIfNotExistsSet.

@Test
public void shouldNotThrowOnRegisterExistingTypeWhenIfNotExistsSet() {
    // Given:
    final RegisterType ddlStatement = new RegisterType(Optional.empty(), 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(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 49 with Type

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

the class CommandFactoriesTest method shouldCreateCommandForCreateSourceStream.

@Test
public void shouldCreateCommandForCreateSourceStream() {
    // Given:
    final CreateStream statement = new CreateStream(SOME_NAME, TableElements.of(tableElement("COL1", new Type(SqlTypes.BIGINT)), tableElement("COL2", new Type(SqlTypes.STRING))), false, true, withProperties, true);
    // When:
    final DdlCommand result = commandFactories.create(sqlExpression, statement, SessionConfig.of(ksqlConfig, emptyMap()));
    // Then:
    assertThat(result, is(createStreamCommand));
    verify(createSourceFactory).createStreamCommand(statement, ksqlConfig);
}
Also used : RegisterType(io.confluent.ksql.parser.tree.RegisterType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) Type(io.confluent.ksql.execution.expression.tree.Type) DropType(io.confluent.ksql.parser.DropType) DdlCommand(io.confluent.ksql.execution.ddl.commands.DdlCommand) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 50 with Type

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

the class CommandFactoriesTest method shouldCreateCommandForCreateSourceTable.

@Test
public void shouldCreateCommandForCreateSourceTable() {
    // Given:
    final CreateTable statement = new CreateTable(SOME_NAME, TableElements.of(tableElement("COL1", new Type(SqlTypes.BIGINT)), tableElement("COL2", new Type(SqlTypes.STRING))), false, true, withProperties, true);
    // When:
    final DdlCommand result = commandFactories.create(sqlExpression, statement, SessionConfig.of(ksqlConfig, emptyMap()));
    // Then:
    assertThat(result, is(createTableCommand));
    verify(createSourceFactory).createTableCommand(statement, ksqlConfig);
}
Also used : RegisterType(io.confluent.ksql.parser.tree.RegisterType) SqlPrimitiveType(io.confluent.ksql.schema.ksql.types.SqlPrimitiveType) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) Type(io.confluent.ksql.execution.expression.tree.Type) DropType(io.confluent.ksql.parser.DropType) DdlCommand(io.confluent.ksql.execution.ddl.commands.DdlCommand) CreateTable(io.confluent.ksql.parser.tree.CreateTable) 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