Search in sources :

Example 1 with RegisterType

use of io.confluent.ksql.parser.tree.RegisterType 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 2 with RegisterType

use of io.confluent.ksql.parser.tree.RegisterType 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 3 with RegisterType

use of io.confluent.ksql.parser.tree.RegisterType 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 4 with RegisterType

use of io.confluent.ksql.parser.tree.RegisterType 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 5 with RegisterType

use of io.confluent.ksql.parser.tree.RegisterType in project ksql by confluentinc.

the class TestCaseBuilderUtil method registerType.

private static void registerType(final PreparedStatement<?> prepare, final MetaStore metaStore) {
    if (prepare.getStatement() instanceof RegisterType) {
        final RegisterType statement = (RegisterType) prepare.getStatement();
        metaStore.registerType(statement.getName(), statement.getType().getSqlType());
    }
}
Also used : RegisterType(io.confluent.ksql.parser.tree.RegisterType)

Aggregations

RegisterType (io.confluent.ksql.parser.tree.RegisterType)7 Test (org.junit.Test)6 Type (io.confluent.ksql.execution.expression.tree.Type)5 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)5 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)5 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)4 RegisterTypeCommand (io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand)3 DdlCommand (io.confluent.ksql.execution.ddl.commands.DdlCommand)1 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)1 DropType (io.confluent.ksql.parser.DropType)1 SqlStruct (io.confluent.ksql.schema.ksql.types.SqlStruct)1 KsqlException (io.confluent.ksql.util.KsqlException)1