baremaps-calcite/src/main/java/org/apache/baremaps/calcite/BaremapsDdlExecutor.java [236:320]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public void execute(SqlCreateForeignSchema create,
      CalcitePrepare.Context context) {
    final SchemaInfo schemaInfo =
        schema(context, true, create.name);
    requireNonNull(schemaInfo.schema()); // TODO: should not assume parent schema exists
    if (schemaInfo.schema().plus().getSubSchema(schemaInfo.name()) != null) {
      if (!create.getReplace() && !create.ifNotExists) {
        throw SqlUtil.newContextException(create.name.getParserPosition(),
            RESOURCE.schemaExists(schemaInfo.name()));
      }
    }
    final Schema subSchema;
    final String libraryName;
    if (create.type != null) {
      checkArgument(create.library == null);
      final String typeName = (String) requireNonNull(value(create.type));
      final JsonSchema.Type type =
          Util.enumVal(JsonSchema.Type.class,
              typeName.toUpperCase(Locale.ROOT));
      if (type != null) {
        switch (type) {
          case JDBC:
            libraryName = JdbcSchema.Factory.class.getName();
            break;
          default:
            libraryName = null;
        }
      } else {
        libraryName = null;
      }
      if (libraryName == null) {
        throw SqlUtil.newContextException(create.type.getParserPosition(),
            RESOURCE.schemaInvalidType(typeName,
                Arrays.toString(JsonSchema.Type.values())));
      }
    } else {
      libraryName =
          requireNonNull((String) value(requireNonNull(create.library)));
    }
    final SchemaFactory schemaFactory =
        AvaticaUtils.instantiatePlugin(SchemaFactory.class, libraryName);
    final Map<String, Object> operandMap = new LinkedHashMap<>();
    for (Pair<SqlIdentifier, SqlNode> option : create.options()) {
      operandMap.put(option.left.getSimple(),
          requireNonNull(value(option.right)));
    }
    subSchema =
        schemaFactory.create(schemaInfo.schema().plus(), schemaInfo.name(), operandMap);
    schemaInfo.schema().add(schemaInfo.name(), subSchema);
  }

  /** Executes a {@code CREATE FUNCTION} command. */
  public void execute(SqlCreateFunction create,
      CalcitePrepare.Context context) {
    throw new UnsupportedOperationException("CREATE FUNCTION is not supported");
  }

  /**
   * Executes {@code DROP FUNCTION}, {@code DROP TABLE}, {@code DROP MATERIALIZED VIEW},
   * {@code DROP TYPE}, {@code DROP VIEW} commands.
   */
  public void execute(SqlDropObject drop,
      CalcitePrepare.Context context) {
    final SchemaInfo schemaInfo =
        schema(context, false, drop.name);
    final @Nullable CalciteSchema schema =
        schemaInfo.schema(); // null if schema does not exist
    final String objectName = schemaInfo.name();

    boolean existed;
    switch (drop.getKind()) {
      case DROP_TABLE:
      case DROP_MATERIALIZED_VIEW:
        Table materializedView =
            schema != null
                && drop.getKind() == SqlKind.DROP_MATERIALIZED_VIEW
                    ? schema.plus().getTable(objectName)
                    : null;

        existed = schema != null && schema.removeTable(objectName);
        if (existed) {
          if (materializedView instanceof Wrapper) {
            ((Wrapper) materializedView).maybeUnwrap(MaterializationKey.class)
                .ifPresent(materializationKey -> MaterializationService.instance()
                    .removeMaterialization(materializationKey));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



baremaps-calcite/src/main/java/org/apache/baremaps/calcite/postgres/PostgresDdlExecutor.java [281:365]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public void execute(SqlCreateForeignSchema create,
      CalcitePrepare.Context context) {
    final SchemaInfo schemaInfo =
        schema(context, true, create.name);
    requireNonNull(schemaInfo.schema()); // TODO: should not assume parent schema exists
    if (schemaInfo.schema().plus().getSubSchema(schemaInfo.name()) != null) {
      if (!create.getReplace() && !create.ifNotExists) {
        throw SqlUtil.newContextException(create.name.getParserPosition(),
            RESOURCE.schemaExists(schemaInfo.name()));
      }
    }
    final Schema subSchema;
    final String libraryName;
    if (create.type != null) {
      checkArgument(create.library == null);
      final String typeName = (String) requireNonNull(value(create.type));
      final JsonSchema.Type type =
          Util.enumVal(JsonSchema.Type.class,
              typeName.toUpperCase(Locale.ROOT));
      if (type != null) {
        switch (type) {
          case JDBC:
            libraryName = JdbcSchema.Factory.class.getName();
            break;
          default:
            libraryName = null;
        }
      } else {
        libraryName = null;
      }
      if (libraryName == null) {
        throw SqlUtil.newContextException(create.type.getParserPosition(),
            RESOURCE.schemaInvalidType(typeName,
                Arrays.toString(JsonSchema.Type.values())));
      }
    } else {
      libraryName =
          requireNonNull((String) value(requireNonNull(create.library)));
    }
    final SchemaFactory schemaFactory =
        AvaticaUtils.instantiatePlugin(SchemaFactory.class, libraryName);
    final Map<String, Object> operandMap = new LinkedHashMap<>();
    for (Pair<SqlIdentifier, SqlNode> option : create.options()) {
      operandMap.put(option.left.getSimple(),
          requireNonNull(value(option.right)));
    }
    subSchema =
        schemaFactory.create(schemaInfo.schema().plus(), schemaInfo.name(), operandMap);
    schemaInfo.schema().add(schemaInfo.name(), subSchema);
  }

  /** Executes a {@code CREATE FUNCTION} command. */
  public void execute(SqlCreateFunction create,
      CalcitePrepare.Context context) {
    throw new UnsupportedOperationException("CREATE FUNCTION is not supported");
  }

  /**
   * Executes {@code DROP FUNCTION}, {@code DROP TABLE}, {@code DROP MATERIALIZED VIEW},
   * {@code DROP TYPE}, {@code DROP VIEW} commands.
   */
  public void execute(SqlDropObject drop,
      CalcitePrepare.Context context) {
    final SchemaInfo schemaInfo =
        schema(context, false, drop.name);
    final @Nullable CalciteSchema schema =
        schemaInfo.schema(); // null if schema does not exist
    final String objectName = schemaInfo.name();

    boolean existed;
    switch (drop.getKind()) {
      case DROP_TABLE:
      case DROP_MATERIALIZED_VIEW:
        Table materializedView =
            schema != null
                && drop.getKind() == SqlKind.DROP_MATERIALIZED_VIEW
                    ? schema.plus().getTable(objectName)
                    : null;

        existed = schema != null && schema.removeTable(objectName);
        if (existed) {
          if (materializedView instanceof Wrapper) {
            ((Wrapper) materializedView).maybeUnwrap(MaterializationKey.class)
                .ifPresent(materializationKey -> MaterializationService.instance()
                    .removeMaterialization(materializationKey));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



