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);
}
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));
}
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));
}
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");
}
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));
}
Aggregations