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);
  }
@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)
    );
  }