Search in sources :

Example 1 with RegisterTypeCommand

use of io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand in project ksql by confluentinc.

the class RegisterTypeFactory method create.

public RegisterTypeCommand create(final RegisterType statement) {
    final String name = statement.getName();
    final boolean ifNotExists = statement.getIfNotExists();
    final SqlType type = statement.getType().getSqlType();
    if (!ifNotExists && metaStore.resolveType(name).isPresent()) {
        throw new KsqlException("Cannot register custom type '" + name + "' " + "since it is already registered with type: " + metaStore.resolveType(name).get());
    }
    return new RegisterTypeCommand(type, name);
}
Also used : SqlType(io.confluent.ksql.schema.ksql.types.SqlType) KsqlException(io.confluent.ksql.util.KsqlException) RegisterTypeCommand(io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand)

Example 2 with RegisterTypeCommand

use of io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand 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 3 with RegisterTypeCommand

use of io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand 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 4 with RegisterTypeCommand

use of io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand in project ksql by confluentinc.

the class DdlCommandExecTest method setup.

@Before
public void setup() {
    when(source.getName()).thenReturn(STREAM_NAME);
    when(source.getDataSourceType()).thenReturn(DataSourceType.KSTREAM);
    when(source.getKafkaTopicName()).thenReturn(TOPIC_NAME);
    cmdExec = new DdlCommandExec(metaStore);
    dropType = new DropTypeCommand("type");
    registerType = new RegisterTypeCommand(type, "type");
}
Also used : DropTypeCommand(io.confluent.ksql.execution.ddl.commands.DropTypeCommand) RegisterTypeCommand(io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand) Before(org.junit.Before)

Example 5 with RegisterTypeCommand

use of io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand 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)

Aggregations

RegisterTypeCommand (io.confluent.ksql.execution.ddl.commands.RegisterTypeCommand)5 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)4 Type (io.confluent.ksql.execution.expression.tree.Type)3 RegisterType (io.confluent.ksql.parser.tree.RegisterType)3 SqlBaseType (io.confluent.ksql.schema.ksql.types.SqlBaseType)3 SqlPrimitiveType (io.confluent.ksql.schema.ksql.types.SqlPrimitiveType)3 Test (org.junit.Test)3 DropTypeCommand (io.confluent.ksql.execution.ddl.commands.DropTypeCommand)1 KsqlException (io.confluent.ksql.util.KsqlException)1 Before (org.junit.Before)1