public Schema alterSchema()

in core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java [214:296]


  public Schema alterSchema(NameIdentifier ident, SchemaChange... changes)
      throws NoSuchSchemaException {

    NameIdentifier catalogIdent = getCatalogIdentifier(ident);
    // Gravitino does not support alter schema currently, so we do not need to check whether there
    // exists SchemaChange.renameSchema in the changes and can lock schema directly.
    return TreeLockUtils.doWithTreeLock(
        ident,
        LockType.WRITE,
        () -> {
          validateAlterProperties(ident, HasPropertyMetadata::schemaPropertiesMetadata, changes);
          Schema alteredSchema =
              doWithCatalog(
                  catalogIdent,
                  c -> c.doWithSchemaOps(s -> s.alterSchema(ident, changes)),
                  NoSuchSchemaException.class);

          // If the Schema is maintained by the Gravitino's store, we don't have to alter again.
          boolean isManagedSchema = isManagedEntity(catalogIdent, Capability.Scope.SCHEMA);
          if (isManagedSchema) {
            return EntityCombinedSchema.of(alteredSchema)
                .withHiddenProperties(
                    getHiddenPropertyNames(
                        catalogIdent,
                        HasPropertyMetadata::schemaPropertiesMetadata,
                        alteredSchema.properties()));
          }

          StringIdentifier stringId = getStringIdFromProperties(alteredSchema.properties());
          // Case 1: The schema is not created by Gravitino and this schema is never imported.
          SchemaEntity se = null;
          if (stringId == null) {
            se = getEntity(ident, SCHEMA, SchemaEntity.class);
            if (se == null) {
              return EntityCombinedSchema.of(alteredSchema)
                  .withHiddenProperties(
                      getHiddenPropertyNames(
                          catalogIdent,
                          HasPropertyMetadata::schemaPropertiesMetadata,
                          alteredSchema.properties()));
            }
          }

          long schemaId;
          if (stringId != null) {
            schemaId = stringId.id();
          } else {
            schemaId = se.id();
          }

          SchemaEntity updatedSchemaEntity =
              operateOnEntity(
                  ident,
                  id ->
                      store.update(
                          id,
                          SchemaEntity.class,
                          SCHEMA,
                          schemaEntity ->
                              SchemaEntity.builder()
                                  .withId(schemaEntity.id())
                                  .withName(schemaEntity.name())
                                  .withNamespace(ident.namespace())
                                  .withAuditInfo(
                                      AuditInfo.builder()
                                          .withCreator(schemaEntity.auditInfo().creator())
                                          .withCreateTime(schemaEntity.auditInfo().createTime())
                                          .withLastModifier(
                                              PrincipalUtils.getCurrentPrincipal().getName())
                                          .withLastModifiedTime(Instant.now())
                                          .build())
                                  .build()),
                  "UPDATE",
                  schemaId);

          return EntityCombinedSchema.of(alteredSchema, updatedSchemaEntity)
              .withHiddenProperties(
                  getHiddenPropertyNames(
                      catalogIdent,
                      HasPropertyMetadata::schemaPropertiesMetadata,
                      alteredSchema.properties()));
        });
  }