Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

16.5 KB
Raw Blame
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

---

paths:

  /metalakes/{metalake}/catalogs/{catalog}/schemas:
    parameters:
      - $ref: "./openapi.yaml#/components/parameters/metalake"
      - $ref: "./openapi.yaml#/components/parameters/catalog"

    get:
      tags:
        - schema
      summary: List schemas
      operationId: listSchemas
      parameters:
        - $ref: "#/components/parameters/parentSchema"
      responses:
        "200":
          $ref: "./openapi.yaml#/components/responses/EntityListResponse"
        "400":
          $ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
        "403":
          $ref: "./openapi.yaml#/components/responses/ForbiddenErrorResponse"
        "409":
          description: Conflict - The catalog is disabled (CatalogNotInUseException).
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                CatalogNotInUseException:
                  value:
                    code: 1009
                    type: CatalogNotInUseException
                    message: >-
                      Failed to operate schema(s) operation [LIST] under catalog [my_catalog],
                      reason [The catalog my_catalog is not in use]
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

    post:
      tags:
        - schema
      summary: Create schema
      operationId: createSchema
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SchemaCreateRequest"
            examples:
              SchemaCreate:
                $ref: "#/components/examples/SchemaCreate"

      responses:
        "200":
          $ref: "#/components/responses/SchemaResponse"
        "403":
          $ref: "./openapi.yaml#/components/responses/ForbiddenErrorResponse"
        "409":
          description: >-
            Conflict - The target schema already exists, or the catalog is disabled
            (CatalogNotInUseException).
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                SchemaAlreadyExistsErrorResponse:
                  $ref: "#/components/examples/SchemaAlreadyExistsException"
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

  /metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}:
    parameters:
      - $ref: "./openapi.yaml#/components/parameters/metalake"
      - $ref: "./openapi.yaml#/components/parameters/catalog"
      - $ref: "./openapi.yaml#/components/parameters/schema"

    get:
      tags:
        - schema
      summary: Get schema
      operationId: loadSchema
      description: Returns the specified schema in the specified catalog and metalake.
      responses:
        "200":
          $ref: "#/components/responses/SchemaResponse"
        "403":
          $ref: "./openapi.yaml#/components/responses/ForbiddenErrorResponse"
        "404":
          description: >-
            Not Found - The schema or one of its parent resources does not exist. When
            authorization is enabled, a missing metalake returns 403.
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                NoSuchMetalakeException:
                  $ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
                NoSuchCatalogException:
                  $ref: "./catalogs.yaml#/components/examples/NoSuchCatalogException"
                NoSuchSchemaException:
                  $ref: "#/components/examples/NoSuchSchemaException"
        "409":
          description: >
            Conflict - An external schema carries an identifier owned by another existing schema.
            Remove the copied source marker before importing an independent copy. A disabled catalog
            also returns 409 (CatalogNotInUseException).
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

    put:
      tags:
        - schema
      summary: Update schema
      operationId: alterSchema
      description: Updates the specified schema in the specified catalog and metalake
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SchemaUpdatesRequest"
      responses:
        "200":
          $ref: "#/components/responses/SchemaResponse"
        "403":
          $ref: "./openapi.yaml#/components/responses/ForbiddenErrorResponse"
        "404":
          description: >-
            Not Found - The schema or one of its parent resources does not exist. When
            authorization is enabled, a missing metalake returns 403.
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                NoSuchMetalakeException:
                  $ref: "./metalakes.yaml#/components/examples/NoSuchMetalakeException"
                NoSuchCatalogException:
                  $ref: "./catalogs.yaml#/components/examples/NoSuchCatalogException"
                NoSuchSchemaException:
                  $ref: "#/components/examples/NoSuchSchemaException"
        "409":
          description: >-
            Conflict - The target schema already exists, or the catalog is disabled
            (CatalogNotInUseException).
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
              examples:
                SchemaAlreadyExistsExistsException:
                  $ref: "#/components/examples/SchemaAlreadyExistsException"
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

    delete:
      tags:
        - schema
      summary: Drop schema
      operationId: dropSchema
      responses:
        "200":
          $ref: "./openapi.yaml#/components/responses/DropResponse"
        "400":
          $ref: "./openapi.yaml#/components/responses/BadRequestErrorResponse"
        "403":
          $ref: "./openapi.yaml#/components/responses/ForbiddenErrorResponse"
        "409":
          description: >
            Conflict - The schema is not empty, or the catalog cannot safely support the requested
            cascading deletion. PostgreSQL rejects non-empty schema deletion even with cascade.
            A disabled catalog also returns 409 (CatalogNotInUseException).
          content:
            application/json:
              schema:
                $ref: "./openapi.yaml#/components/schemas/ErrorModel"
        "5xx":
          $ref: "./openapi.yaml#/components/responses/ServerErrorResponse"

components:

  parameters:
    parentSchema:
      name: parentSchema
      in: query
      description: >
        The parent schema whose direct child schemas are listed. Only meaningful for catalogs that
        support hierarchical (multi-level) schemas, such as an Iceberg catalog accessed through the
        Gravitino REST server with a configured schema separator (`gravitino.schema.separator`,
        default `:`). For example, when the schemas `a`, `a:b` and `a:b:c` exist, listing with
        `parentSchema=a:b` returns `[a:b:c]`. When omitted, only the top-level schemas under the
        catalog are returned (the direct children of the catalog root, e.g. `a`), not the nested
        ones.
      required: false
      schema:
        type: string

  schemas:

    SchemaCreateRequest:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: >
            The name of the schema. For catalogs that support hierarchical (multi-level) schemas,
            the name may encode a nested path joined by the configured schema separator
            (`gravitino.schema.separator`, default `:`), e.g. `a:b:c` creates schema `c` under the
            existing parent schema `a:b`.
        comment:
          type: string
          description: A comment describing the schema
          nullable: true
        properties:
          type: object
          description: A map of properties for the schema
          nullable: true
          default: { }
          additionalProperties:
            type: string
        secretBindings:
          type: object
          description: >
            Optional map of property key to write-through binding. Persisted value
            becomes a URN.
          nullable: true
          additionalProperties:
            $ref: "./secrets.yaml#/components/schemas/SecretBinding"
        secretReferences:
          type: object
          description: >
            Optional map of property key to secret locator. Server builds and
            persists the URN. Must not overlap with secretBindings.
          nullable: true
          additionalProperties:
            $ref: "./secrets.yaml#/components/schemas/SecretReference"

    Schema:
      type: object
      description: A schema
      required:
        - name
        - audit
      properties:
        name:
          type: string
          description: The name of the schema
        comment:
          type: string
          description: A comment describing the schema
          nullable: true
        audit:
          $ref: "./openapi.yaml#/components/schemas/Audit"
        properties:
          type: object
          description: A map of properties for the schema
          nullable: true
          default: { }
          additionalProperties:
            type: string

    SchemaUpdatesRequest:
      type: object
      required:
        - updates
      properties:
        updates:
          type: array
          items:
            $ref: "#/components/schemas/SchemaUpdateRequest"

    SchemaUpdateRequest:
      oneOf:
        - $ref: "#/components/schemas/SetSchemaPropertyRequest"
        - $ref: "#/components/schemas/RemoveSchemaPropertyRequest"
        - $ref: "#/components/schemas/SetSchemaSecretBindingRequest"
        - $ref: "#/components/schemas/SetSchemaSecretReferenceRequest"
      discriminator:
        propertyName: "@type"
        mapping:
          setProperty: "#/components/schemas/SetSchemaPropertyRequest"
          removeProperty: "#/components/schemas/RemoveSchemaPropertyRequest"
          setSecretBinding: "#/components/schemas/SetSchemaSecretBindingRequest"
          setSecretReference: "#/components/schemas/SetSchemaSecretReferenceRequest"

    SetSchemaPropertyRequest:
      type: object
      required:
        - "@type"
        - property
        - value
      properties:
        "@type":
          type: string
          enum:
            - setProperty
        property:
          type: string
          description: The name of the property to set
        value:
          type: string
          description: >
            The value of the property to set. If the property holds a write-through secret URN of
            this schema, the value is written as a new version of that secret. If it holds another
            secret URN, the value is written through that secret's provider right away, and a failed
            alter does not undo it.
      example:
        "@type": "setProperty"
        property: "key1"
        value: "value1_new"

    RemoveSchemaPropertyRequest:
      type: object
      required:
        - "@type"
        - property
      properties:
        "@type":
          type: string
          enum:
            - removeProperty
        property:
          type: string
          description: The name of the property to remove
      example: {
        "@type": "removeProperty",
        "property": "key2"
      }

    SetSchemaSecretBindingRequest:
      type: object
      required:
        - "@type"
        - property
        - provider
        - plaintext
      properties:
        "@type":
          type: string
          enum:
            - setSecretBinding
        property:
          type: string
          description: The property to bind
        provider:
          type: string
          description: Registered secrets-provider instance name
        plaintext:
          type: string
          description: Plaintext secret to write through
          format: password
      example: {
        "@type": "setSecretBinding",
        "property": "password",
        "provider": "env",
        "plaintext": "secret-value"
      }

    SetSchemaSecretReferenceRequest:
      type: object
      required:
        - "@type"
        - property
        - provider
      properties:
        "@type":
          type: string
          enum:
            - setSecretReference
        property:
          type: string
          description: The property to bind
        provider:
          type: string
          description: Registered secrets-provider instance name
        attributes:
          type: object
          description: Provider-specific locator keys (empty object if none)
          additionalProperties:
            type: string
          default: {}
      example: {
        "@type": "setSecretReference",
        "property": "password",
        "provider": "vault",
        "attributes": {
          "path": "secret/data/my-password"
        }
      }

  responses:
    SchemaResponse:
      description: Returns include the schema object
      content:
        application/vnd.gravitino.v1+json:
          schema:
            type: object
            properties:
              code:
                type: integer
                format: int32
                description: Status code of the response
                enum:
                  - 0
              schema:
                $ref: "#/components/schemas/Schema"
          examples:
            SchemaResponse:
              $ref: "#/components/examples/SchemaResponse"


  examples:
    SchemaListResponse:
      value: {
        "code": 0,
        "identifiers": [
          {
            "namespace": [
              "my_metalake",
              "my_hive_catalog"
            ],
            "name": "my_hive_schema"
          }
        ]
      }

    SchemaCreate:
      value: {
        "name": "my_hive_schema",
        "comment": "This is my Hive schema",
        "properties": {
          "location": "/user/hive/warehouse",
          "key1": "value1",
          "key2": "value2"
        }
      }

    SchemaResponse:
      value: {
        "code": 0,
        "schema": {
          "name": "my_hive_schema",
          "comment": "This is my Hive schema",
          "properties": {
            "key1": "value1",
            "key2": "value2",
            "location": "hdfs://0.0.0.0:9000/user/hive/warehouse"
          },
          "audit": {
            "creator": "gravitino",
            "createTime": "2023-12-08T08:37:43.531Z"
          }
        }
      }

    SchemaAlreadyExistsException:
      value: {
        "code": 1004,
        "type": "SchemaAlreadyExistsException",
        "message": "Failed to operate schema(s) [my_hive_schema] operation [CREATE] under catalog [my_hive_catalog], reason [SchemaAlreadyExistsException]",
        "stack": [
          "org.apache.gravitino.exceptions.SchemaAlreadyExistsException: Hive schema (database) 'my_hive_schema' already exists in Hive Metastore",
          "..."
        ]
      }

    NoSuchSchemaException:
      value: {
        "code": 1003,
        "type": "NoSuchSchemaException",
        "message": "Failed to operate schema(s) [my_hive_schema1] operation [LOAD] under catalog [my_hive_catalog], reason [NoSuchSchemaException]",
        "stack": [
          "org.apache.gravitino.exceptions.NoSuchSchemaException: Hive schema (database) does not exist: my_hive_schema1 in Hive Metastore",
          "..."
        ]
      }