> ## Documentation Index
> Fetch the complete documentation index at: https://docs.narrative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Parse an NQL statement

> The same check as `POST /nql/validate`, open to any token and to callers with no token at all, so a
query editor can report problems as the user types. The response and error shapes are those of
`/nql/validate`.

With a bearer token the statement is checked against the datasets, access rules and views of the
token's company, exactly as `/nql/validate` does, and the token needs no particular permission.

Without a token there is no company context. The statement is still parsed with the dialect of the
given data plane and type-checked, but it can only resolve tables that need no company, such as
`narrative.rosetta_stone`, and statements that write data (`CREATE MATERIALIZED VIEW`, `INSERT`,
`UPDATE`, `DELETE`, `MERGE`) are rejected with a 400 titled
`Cannot validate certain queries when unauthentified`.



## OpenAPI

````yaml https://docs-cdn.narrative.io/api-reference/main/openapi.json post /nql/parse
openapi: 3.1.1
info:
  contact:
    email: support@narrative.io
    name: Narrative Support
    url: https://www.narrative.io
  termsOfService: https://www.narrative.io/legal/terms-of-service
  x-logo:
    url: >-
      https://cdn.narrative.io/images/company-logos/prod/narrative-logo-text-white.svg
    backgroundColor: rgb(9, 34, 166)
    altText: Narrative Logo
  description: >-
    The [Narrative Data Collaboration Platform](https://app.narrative.io) API is
    organized around REST. Our API has predictable resource-oriented URLs,
    accepts form-encoded request bodies, returns JSON-encoded responses, and
    uses standard HTTP response codes, authentication, and verbs.



    The current version is a pre-release beta.  It may result in unexpected
    behavior and there may be breaking changes in future releases up to the 1.0
    release.
  title: Narrative Data Collaboration Platform API
  version: 2.4.x
servers:
  - url: https://api-dev.narrative.io
  - url: https://api.narrative.io
security: []
tags:
  - name: Access Rules
    description: >-
      Access rules let data providers control who can purchase their data and
      the terms of purchase.


      The `access-rules` API allows you to manage access rules for your
      datasets.


      Related guides:
        - [What is an access rule?](https://kb.narrative.io/access-rules)
  - name: Agent Conversations
    description: >-
      Build LLM-driven workflows that can call MCP tools, ask the caller for
      input, and return structured answers.


      A conversation pins a model, a system prompt, and a tool catalog. Each run
      sends the model a user message (or

      a batch of tool outputs from a previously-paused run); the model decides
      whether to answer directly, call a

      server-side tool (resolved by the platform via Model Context Protocol), or
      call a client-side tool (which pauses

      the run with `requires_action` and waits for the caller to reply).


      Related guides:
        - [Agent Conversations Reference](https://docs.narrative.io/reference/architecture/agent-conversations)
        - [Error catalog](https://docs.narrative.io/reference/architecture/agent-conversations/errors/conversation-not-found)
  - name: MCP Connections
    description: >-
      Connect external (non-Narrative) MCP servers so agent runs can call their
      tools with the

      calling user's own OAuth authorization.


      A connection is created interactively: `POST /mcp-connections` runs OAuth
      discovery and

      Dynamic Client Registration against the server and returns a consent URL;
      the user authorizes

      in a browser; the authorization server redirects to `GET
      /mcp-connections/callback`, which

      stores the authorization code and sends the browser on to the Narrative
      app; the app calls

      `POST /mcp-connections/complete` with the user's own bearer token, which
      exchanges the code and

      marks the connection `connected`.


      That last step is authenticated on purpose. The callback is public — it's
      a cross-site browser

      redirect, so no bearer reaches it — so it is not allowed to complete
      anything. Only the user

      who started the flow can turn the stored code into a token.


      Tokens are stored encrypted and used server-side — they are never returned
      by the API. Once

      connected, reference the connection by id from an agent run's
      `mcp_servers[].connection_id`.
  - name: App Invites
    description: >-
      App invites allow applications to create one-time, shareable links on
      behalf of their users. These links

      enable users to invite third parties who do not have a Narrative account
      to perform actions within the

      application.


      For example, a Narrative user can send an invite link to a third party who
      then completes a Pinterest

      OAuth flow and creates a connector profile in the inviter's account,
      allowing the inviter to deliver

      audience data to the third party's Pinterest account without the third
      party needing a Narrative account.


      This API is intended to be used by applications (via app client
      credentials) to create and manage invites

      on behalf of their users, which can then be shared with invitees.
  - name: Apps
    description: >-
      Apps are applications bundled with a UI that can perform various actions
      on behalf of a user utilizing the Narrative API.

      Related guides:
        - [Building a Narrative Native App](https://www.narrative.io/knowledge-base/how-to-guides/building-a-narrative-native-app)
  - name: Access Tokens
    description: >-
      System Access Tokens are long-lived bearer credentials for calling the API
      without a user present.


      A token belongs to a company, carries an explicit list of permissions, and
      expires on a date you choose — at

      least a day out and at most a year. `admin` access cannot be granted to
      one.


      `POST /access-tokens/tokens` is the only endpoint that returns the
      credential. Everything after that works in

      terms of the token's id: the list, get and update responses describe a
      token without ever repeating its

      `access_token`. If you lose it, delete the token and create another.


      Related guides:
        - [How to Create an API Token](https://www.narrative.io/knowledge-base/how-to-guides/understanding-narratives-apis/create-an-api-token)
  - name: Attributes
    description: >-
      An attribute models a standardized data point available for sale on the
      Narrative marketplace.


      Narrative automatically turns data points from provider datasets into
      attributes so that buyers can purchase well-formed, standardized data from
      any supplier on the marketplace.
  - name: Auth
    description: >-
      API token is a crucial step for developers to securely authenticate
      requests to the Narrative API

      Related guides:
        - [How to Create an API Token](https://www.narrative.io/knowledge-base/how-to-guides/understanding-narratives-apis/create-an-api-token)
  - name: Authentication
    description: User login and registration
  - name: Billings
    description: Used by Narrative internally to bill customers
  - name: Companies
    description: A collection of employees
  - name: Company Marketing Information
    description: Useful information related to companies
  - name: Compute Pools
    description: >-
      Compute pools represent compute resources (e.g. Snowflake warehouses)
      provisioned within a data plane.

      Companies can manage and share compute pools, assign them to jobs, and set
      a default compute pool on data planes.
  - name: Connections
    description: Associations between connectors and datasets
  - name: Data Shops
    description: |-
      Self-hosted website to sell your data
      Related guides:
        - [Setting up your datashop](https://www.narrative.io/knowledge-base/how-to-guides/shop-builder/settting-up-your-data-shop)
  - name: Data Streams
    description: >-
      The `data-stream` API endpoints allows one to create and update
      data-streams. Additionally the endpoints allow

      finding data-streams using free text search. A few of the endpoints are
      behind authorization.


      Update endpoint allows a client to post an edited data-stream document as
      is, without having to change its shape.

      The API ensures that only certain fields are allowed to be modified.
      Attempts to modify fields not up for client

      modifications are ignored.


      Related guides:
        - [What is a data stream?](https://kb.narrative.io/what-is-a-data-stream)
  - name: Contracts
    description: Contracts related APIs
  - name: Datasets
    description: >-
      Any kind of data, in any schema, can be pushed into the Narrative Data
      Collaboration Platform as a dataset exactly as it is stored in your own
      system.


      The `datasets` API allows you to manage your datasets.
  - name: Derivations
    description: >-
      Derivation rules describe how the value of one Rosetta Stone attribute can
      be computed from another — for

      example, hashing a raw email into a SHA-256 hashed email. Each rule
      carries a transformation expression that

      reads the source attribute's value through `$source`.


      The `derivations` API allows you to browse the rules your company can use
      — the ones it owns plus the ones

      shared with it through collaborators. Creating and changing them requires
      an `admin` grant on

      `attribute_derivations`, and a rule can only be changed by the company
      that owns it.
  - name: Destinations
    description: >-
      Destinations associate a subscription to a profile. Optionally, ad-hoc
      quick settings can be configured to a destination.

      Those quick settings have to match the format defined on the app manifest.
  - name: Installations
    description: Installations of Applications for a profile
  - name: Jobs
    description: >-
      Jobs represent an operation done on a given data plane. All jobs today are
      tied to a query that represents a forecast or a materialized view.


      The jobs API provides an interface for interacting with the jobs table,
      which stores various operations involving reading or writing data. This
      API allows users to retrieve detailed information about specific jobs,
      including NQL forecasts and materialized views.
  - name: Mappings
    description: >-
      A mapping is a transformation from a dataset to an attribute. Defining a
      mapping between a dataset and an attribute makes the dataset eligible to
      participate in subscriptions where a buyer is purchasing the target
      attribute.
  - name: Model Inference
    description: Model Inference
  - name: Model Training
    description: >-
      Train machine learning models on datasets, e.g. text classifiers used to
      power attribute mappings.
  - name: Models
    description: >-
      Machine learning models for training and inference.


      Models can be stored in HuggingFace or Narrative repositories and have
      configurable

      collaborator permissions for training and inference access.


      The `models` API allows you to list, retrieve, and update models
      accessible to your company.
  - name: NQL
    description: >-
      Narrative Query Language (NQL) is a specialized, SQL-inspired language
      designed to query and manipulate data within the Narrative platform. While
      it looks and feels much like standard SQL, it offers extended
      functionality and syntax that let you leverage platform-specific
      features—such as referencing datasets by their IDs, creating materialized
      views, or generating forecasts—without having to manage the complexities
      of different query engines behind the scenes. NQL queries can ultimately
      compile down to multiple underlying engines (e.g., Snowflake, Spark) to
      execute your requests efficiently in the Narrative ecosystem.
  - name: Payment Methods
    description: Payment methods used to purchase data
  - name: Products
    description: Internal routes used to offer datastream as products
  - name: Profiles
    description: >-
      App profiles are associated with an installation. They represent a
      reference to a configuration that the app can use to save confidential
      information outside of Narrative's control.

      Profiles are currently used to configure settings for connector apps.
  - name: Resources
    description: >-
      Narrative gives you access to managed resources, like your own AWS S3
      bucket, so that you can effortlessly buy and sell data on the platform.


      The `resources` API allows you to manage your resources.
  - name: Schema Inference
    description: >-
      The `schema-inference` API analyzes submitted files to automatically infer
      and return their structure as a dataset schema.
  - name: Schema Presets
    description: >-
      The `schema-presets` API allows you to list the available schema presets,
      get detailed information about a specific one and manage its life cycle.


      You can create a schema preset from scratch or create one based on an
      existing one, administrators can create platform wide available (public)
      schema preset.
  - name: Subscriptions
    description: >-
      In the Narrative Data Collaboration Platform a subscription represents a
      set of rules dictating the commercial terms related to the licensing of
      data.


      The `subscriptions` API allows you to set and get information about
      `subscription` objects owned by the authenticated account.
  - name: Uploads
    description: >-
      The `uploads` API allows you to send files to Narrative and use them to
      perform tasks like creating a list or adding data to a dataset.
  - name: Usage
    description: >-
      The `usage` API enables the recording of usage events associated with a
      product.
  - name: Webhooks
    description: >-
      Webhooks push events to a URL you control instead of making you poll for
      them.


      You create a subscription with the endpoint you want events sent to and a
      filter describing which events you

      want. Two kinds of subscription exist: job subscriptions follow the
      lifecycle of Narrative jobs, and app

      subscriptions follow the events a Narrative app reports through `POST
      /apps/events`.


      Creating a subscription returns a `secret`. Narrative sends it back in the
      `X-Narrative-Secret` header on

      every delivery, and comparing the two is how you tell a real callback from
      a forged one — so store it and do

      not share it.


      Deliveries are described under the "Event delivery" webhook below. Return
      any 2xx; anything else is retried

      with exponential backoff, and because a retry reuses the envelope's `id`,
      handlers should be idempotent

      on it.
  - name: Workflows
    description: >-
      The `workflows` API allows you to create, schedule, trigger, and archive
      workflows.

      Workflows are defined using a serverlessworkflow YAML specification.
paths:
  /nql/parse:
    post:
      tags:
        - NQL
      summary: Parse an NQL statement
      description: >-
        The same check as `POST /nql/validate`, open to any token and to callers
        with no token at all, so a

        query editor can report problems as the user types. The response and
        error shapes are those of

        `/nql/validate`.


        With a bearer token the statement is checked against the datasets,
        access rules and views of the

        token's company, exactly as `/nql/validate` does, and the token needs no
        particular permission.


        Without a token there is no company context. The statement is still
        parsed with the dialect of the

        given data plane and type-checked, but it can only resolve tables that
        need no company, such as

        `narrative.rosetta_stone`, and statements that write data (`CREATE
        MATERIALIZED VIEW`, `INSERT`,

        `UPDATE`, `DELETE`, `MERGE`) are rejected with a 400 titled

        `Cannot validate certain queries when unauthentified`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateRequest'
            example:
              nql: >-
                EXPLAIN SELECT "company_data"."1".s, "company_data"."1".arr FROM
                "company_data"."1" WHERE "company_data"."1".x > -10.0
      responses:
        '200':
          description: >-
            The statement is valid. The body is its AST, or an empty object for
            a `MERGE` statement, which has

            no AST representation. See `POST /nql/validate` for worked examples.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidateResponse'
        '400':
          description: >-
            The statement did not parse, references a table or column the caller
            cannot see, needs a company

            but no token was sent, or the request body did not decode. A body
            that does not decode returns

            the `error` / `error_description` shape with `error` set to
            `bad_payload`; everything else is the

            RFC 7807 problem shape.

            visit https://docs.narrative.io/guides/nql/troubleshooting for more
            details
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Response'
                  - $ref: '#/components/schemas/Error'
              examples:
                unauthenticated_write:
                  summary: a write statement sent without a token
                  value:
                    type: null
                    title: Cannot validate certain queries when unauthentified
                    status: 400
                    detail: cannot create a materialized view if not authenticated
                    instance: /nql/parse
                    log_id: c06fea02-0950-45c6-aaff-07ab07c0d04c
                    debug: null
        '403':
          description: >-
            The statement is a `CREATE MATERIALIZED VIEW` whose name is already
            taken by a table or materialized

            view of the token's company.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'
        '422':
          description: >-
            Unprocessable Entity — the query parsed but is semantically invalid,
            for example a materialized

            view output column whose type is not supported (such as DECIMAL), or
            a query that produces no

            output columns.

            visit https://docs.narrative.io/guides/nql/troubleshooting for more
            details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Response'
      security:
        - {}
        - BearerAuth: []
components:
  schemas:
    ValidateRequest:
      type: object
      required:
        - nql
      properties:
        nql:
          $ref: '#/components/schemas/NQL'
        data_plane_id:
          oneOf:
            - $ref: '#/components/schemas/DataPlaneId'
            - type: 'null'
    ValidateResponse:
      description: >-
        The parsed statement as an AST. A `MERGE` statement has no AST
        representation and returns an empty

        object instead, as does a statement whose AST could not be serialized.
      oneOf:
        - $ref: '#/components/schemas/Ast'
        - $ref: '#/components/schemas/EmptyAst'
    Response:
      type: object
      description: >-
        An RFC 7807 problem. `title` names the kind of error and `detail`
        explains this occurrence;

        https://docs.narrative.io/guides/nql/troubleshooting walks through the
        NQL titles.
      required:
        - title
        - status
        - detail
        - instance
        - log_id
      properties:
        type:
          description: A URL naming the class of error.
          type:
            - string
            - 'null'
          format: uri
        title:
          type: string
          description: a summary of the error
        status:
          type: integer
          description: http status code
        detail:
          type: string
          description: a longer description of the error
        instance:
          type: string
          description: path of the query
        log_id:
          type: string
          format: uuid
          description: an internal logging id, Narrative can use to help debug a problem.
        debug:
          description: >-
            Extra detail shaped by the error, for example the column and type
            name of an unsupported-type

            error. Null when the error has nothing to add. Most errors only
            include it for admin tokens.
          type:
            - object
            - 'null'
          additionalProperties: true
      example:
        type: null
        title: Failed to Parse Query
        status: 400
        detail: Invalid query format.
        instance: /nql/validate
        log_id: c06fea02-0950-45c6-aaff-07ab07c0d04c
        debug: null
    Error:
      type: object
      required:
        - error
        - error_description
      properties:
        error:
          type: string
          example: Unauthorized
        error_description:
          type: string
          example: You are not authorized to use this endpoint.
    NQL:
      type: string
      description: A NQL query.
    DataPlaneId:
      type: string
      format: uuid
      description: >-
        A dataplane represent where you would run the query. Your query get
        compiled

        to the SQL dialect that your data engine understands. If you leave it
        blank,

        your query will target Narrative's dataplane on AWS using Apache Spark.
        We

        currently support Snowflake and we plan to support other dataplanes in
        the

        future. See https://next.narrative.io/products/narrative-anywhere for
        more

        details.
    Ast:
      description: >-
        One node of the parsed query. Object nodes are told apart by `type`. A
        JSON array is a list of nodes,

        which is how the right-hand side of `IN (...)` is represented.
      oneOf:
        - $ref: '#/components/schemas/AggFunction'
        - $ref: '#/components/schemas/AstList'
        - $ref: '#/components/schemas/BinaryOp'
        - $ref: '#/components/schemas/Case'
        - $ref: '#/components/schemas/CreateMaterializedView'
        - $ref: '#/components/schemas/Explain'
        - $ref: '#/components/schemas/Function'
        - $ref: '#/components/schemas/Lit'
        - $ref: '#/components/schemas/IdentAmbiguous'
        - $ref: '#/components/schemas/IdentColumn'
        - $ref: '#/components/schemas/IdentTable'
        - $ref: '#/components/schemas/IdentLambdaParamRef'
        - $ref: '#/components/schemas/Join'
        - $ref: '#/components/schemas/Lambda'
        - $ref: '#/components/schemas/LambdaParam'
        - $ref: '#/components/schemas/Select'
        - $ref: '#/components/schemas/Op'
        - $ref: '#/components/schemas/TypeSpec'
        - $ref: '#/components/schemas/Window'
        - $ref: '#/components/schemas/Unknown'
    EmptyAst:
      title: no ast
      type: object
      description: Returned when the statement is valid but has no AST to show.
      additionalProperties: false
    AggFunction:
      title: aggregate function
      type: object
      required:
        - type
        - nql
        - args
        - name
      properties:
        type:
          type: string
          const: agg_function
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        args:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        name:
          type: string
          description: The function name as written, for example `SUM` or `COUNT`.
        quantifier:
          description: The `ALL` or `DISTINCT` quantifier, or null when none was written.
          type:
            - string
            - 'null'
          enum:
            - all
            - distinct
            - null
    AstList:
      title: list
      type: array
      description: A list of nodes, for example the values of an `IN (...)` clause.
      items:
        $ref: '#/components/schemas/Ast'
    BinaryOp:
      title: binary operator
      type: object
      required:
        - type
        - nql
        - name
        - left
        - right
      properties:
        type:
          type: string
          const: binary_op
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        name:
          type: string
          description: The operator as written, for example `+`, `=`, `AND` or `IN`.
        left:
          $ref: '#/components/schemas/Ast'
        right:
          $ref: '#/components/schemas/Ast'
    Case:
      title: case
      type: object
      required:
        - type
        - nql
        - args
      properties:
        type:
          type: string
          const: case
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        args:
          description: >-
            The `WHEN ... THEN ...` branches in order, followed by the `ELSE`
            branch if there is one.
          type: array
          items:
            $ref: '#/components/schemas/CaseArg'
    CreateMaterializedView:
      title: create materialized view
      type: object
      required:
        - type
        - nql
        - name
        - select
      properties:
        type:
          type: string
          const: create_materialized_view
        nql:
          $ref: '#/components/schemas/Nql'
        name:
          type: string
          description: The name of the materialized view being created.
        select:
          $ref: '#/components/schemas/Select'
    Explain:
      title: explain
      type: object
      required:
        - type
        - nql
        - query
      properties:
        type:
          type: string
          const: explain
        nql:
          $ref: '#/components/schemas/Nql'
        query:
          $ref: '#/components/schemas/Ast'
    Function:
      title: function
      type: object
      required:
        - type
        - nql
        - args
        - name
      properties:
        type:
          type: string
          const: function
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        args:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        name:
          type: string
          description: The function name as written, for example `ARRAY` or `NAMED_STRUCT`.
    Lit:
      title: literal
      type: object
      required:
        - type
        - nql
        - value_type
      properties:
        type:
          type: string
          const: literal
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        value_type:
          $ref: '#/components/schemas/SimpleType'
        value:
          description: The literal's value as text, or null when it has no textual form.
          type:
            - string
            - 'null'
    IdentAmbiguous:
      title: ambiguous
      type: object
      description: A dotted name that could not be resolved to a table or column.
      required:
        - type
        - nql
        - parts
      properties:
        type:
          type: string
          const: ambiguous
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        parts:
          description: The name split on its dots.
          type: array
          minItems: 1
          items:
            type: string
    IdentColumn:
      title: column
      type: object
      required:
        - type
        - nql
        - table
        - column
        - metadata
      properties:
        type:
          type: string
          const: column
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        db:
          type:
            - string
            - 'null'
        schema:
          description: >-
            The schema part of the name, for example `company_data`, or null
            when it was not written.
          type:
            - string
            - 'null'
        table:
          type: string
        column:
          type: string
        metadata:
          $ref: '#/components/schemas/ColumnMetadata'
    IdentTable:
      title: table
      type: object
      required:
        - type
        - nql
        - table
        - metadata
      properties:
        type:
          type: string
          const: table
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        db:
          type:
            - string
            - 'null'
        schema:
          description: >-
            The schema part of the name, for example `company_data`, or null
            when it was not written.
          type:
            - string
            - 'null'
        table:
          type: string
        metadata:
          $ref: '#/components/schemas/TableMetadata'
    IdentLambdaParamRef:
      title: lambda parameter reference
      type: object
      description: >-
        A reference to a parameter of an enclosing lambda, for example
        `metadata.company_id`.
      required:
        - type
        - nql
        - parts
      properties:
        type:
          type: string
          const: lambda_param_ref
        nql:
          $ref: '#/components/schemas/Nql'
        parts:
          description: The name split on its dots.
          type: array
          minItems: 1
          items:
            type: string
    Join:
      title: join
      type: object
      description: >-
        A join between two FROM items. Unlike other nodes it carries no `nql`
        unless it is aliased.
      required:
        - type
        - condition_type
        - left
        - join_type
        - right
      properties:
        type:
          type: string
          const: join
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        condition:
          description: The `ON` or `USING` condition, or null when the join has none.
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        condition_type:
          type: string
          enum:
            - none
            - 'on'
            - using
        left:
          $ref: '#/components/schemas/Ast'
        join_type:
          type: string
          enum:
            - as_of
            - comma
            - cross
            - full
            - inner
            - left
            - left_as_of
            - left_anti
            - left_semi
            - right
        right:
          $ref: '#/components/schemas/Ast'
    Lambda:
      title: lambda
      type: object
      description: A lambda expression such as `(metadata) -> metadata.company_id = 10`.
      required:
        - type
        - nql
        - parameters
      properties:
        type:
          type: string
          const: lambda
        nql:
          $ref: '#/components/schemas/Nql'
        parameters:
          type: array
          items:
            $ref: '#/components/schemas/LambdaParam'
        expression:
          description: The lambda body, or null when it could not be resolved.
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
    LambdaParam:
      title: lambda parameter
      type: object
      required:
        - type
        - nql
        - name
        - type_spec
      properties:
        type:
          type: string
          const: lambda_param
        nql:
          $ref: '#/components/schemas/Nql'
        name:
          type: string
        type_spec:
          $ref: '#/components/schemas/TypeSpec'
    Select:
      title: select
      type: object
      required:
        - type
        - nql
        - columns
        - group_by
        - is_distinct
        - order_by
        - windows
        - with
      properties:
        type:
          type: string
          const: select
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        columns:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        from:
          description: The FROM item, or null for a select with no FROM clause.
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        group_by:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        having:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        is_distinct:
          type: boolean
        limit:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        order_by:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        qualify:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        where:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        windows:
          description: Named windows declared in a `WINDOW` clause.
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        with:
          description: >-
            The common table expressions of a `WITH` clause. Each is a `select`
            node whose `as` is the CTE name.
          type: array
          items:
            $ref: '#/components/schemas/Ast'
    Op:
      title: operator
      type: object
      description: >-
        An operator that is neither binary nor an aggregate, for example a unary
        `NOT` or a table function call.
      required:
        - type
        - nql
        - args
        - name
      properties:
        type:
          type: string
          const: operator
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        args:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        name:
          type: string
    TypeSpec:
      title: type specification
      type: object
      description: >-
        A type written in the query, for example the target of a `CAST` or a
        lambda parameter's row type.
      required:
        - type
        - nql
        - value
      properties:
        type:
          type: string
          const: type_spec
        nql:
          $ref: '#/components/schemas/Nql'
        value:
          type: string
          description: The type in lower case, as the parser normalised it.
    Window:
      title: window
      type: object
      required:
        - type
        - nql
        - order_by
        - partitions
      properties:
        type:
          type: string
          const: window
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
        lower_bound:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
        name:
          description: >-
            The name of a window declared in a `WINDOW` clause, or null for an
            inline window.
          oneOf:
            - $ref: '#/components/schemas/Ident'
            - type: 'null'
        order_by:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        partitions:
          type: array
          items:
            $ref: '#/components/schemas/Ast'
        upper_bound:
          oneOf:
            - $ref: '#/components/schemas/Ast'
            - type: 'null'
    Unknown:
      title: unknown
      type: object
      description: >-
        A fragment the serializer has no representation for. Only `nql` is
        available.
      required:
        - type
        - nql
      properties:
        type:
          type: string
          const: unknown
        nql:
          $ref: '#/components/schemas/Nql'
        as:
          $ref: '#/components/schemas/Alias'
    Nql:
      type: string
      description: The text of the query fragment this node was parsed from.
    Alias:
      type: string
      description: >-
        The alias given with `AS`. Only present on aliased nodes: select-list
        expressions, FROM items and

        common table expressions. When it is present the node's `nql` is the
        full `<expression> AS <alias>` text.
    CaseArg:
      oneOf:
        - $ref: '#/components/schemas/CaseArgWhen'
        - $ref: '#/components/schemas/CaseArgElse'
    SimpleType:
      title: a simple type
      type: object
      description: The type of a literal as the parser inferred it. Told apart by `type`.
      oneOf:
        - $ref: '#/components/schemas/NqlArrayType'
        - $ref: '#/components/schemas/NqlBinaryType'
        - $ref: '#/components/schemas/NqlBooleanType'
        - $ref: '#/components/schemas/NqlDoubleType'
        - $ref: '#/components/schemas/NqlLongType'
        - $ref: '#/components/schemas/NqlIntervalType'
        - $ref: '#/components/schemas/NqlObjectType'
        - $ref: '#/components/schemas/OtherType'
        - $ref: '#/components/schemas/NqlStringType'
        - $ref: '#/components/schemas/TimestampType'
    ColumnMetadata:
      description: What the column resolved to. Told apart by `column_type`.
      oneOf:
        - $ref: '#/components/schemas/RegularColumn'
        - $ref: '#/components/schemas/AttributeColumn'
        - $ref: '#/components/schemas/ReferenceColumn'
    TableMetadata:
      description: What the table resolved to. Told apart by `table_type`.
      oneOf:
        - $ref: '#/components/schemas/DatasetTable'
        - $ref: '#/components/schemas/AccessRulesTable'
        - $ref: '#/components/schemas/MaterializedViewTable'
        - $ref: '#/components/schemas/RosettaStoneTable'
        - $ref: '#/components/schemas/ReferenceTable'
        - $ref: '#/components/schemas/ViewTable'
    Ident:
      description: >-
        A reference to a table, a column or a lambda parameter. Told apart by
        `type`.
      oneOf:
        - $ref: '#/components/schemas/IdentAmbiguous'
        - $ref: '#/components/schemas/IdentColumn'
        - $ref: '#/components/schemas/IdentTable'
        - $ref: '#/components/schemas/IdentLambdaParamRef'
    CaseArgWhen:
      title: when
      type: object
      required:
        - type
        - nql
        - condition
        - value
      properties:
        type:
          type: string
          const: when
        nql:
          $ref: '#/components/schemas/Nql'
        condition:
          $ref: '#/components/schemas/Ast'
        value:
          $ref: '#/components/schemas/Ast'
    CaseArgElse:
      title: else
      type: object
      required:
        - type
        - nql
        - value
      properties:
        type:
          type: string
          const: else
        nql:
          $ref: '#/components/schemas/Nql'
        value:
          $ref: '#/components/schemas/Ast'
    NqlArrayType:
      title: array
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: array
        items:
          description: The element type, or null when it could not be inferred.
          oneOf:
            - $ref: '#/components/schemas/SimpleType'
            - type: 'null'
    NqlBinaryType:
      title: binary
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: binary
    NqlBooleanType:
      title: boolean
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: bool
    NqlDoubleType:
      title: double
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: double
    NqlLongType:
      title: long
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: long
    NqlIntervalType:
      title: interval
      type: object
      required:
        - type
        - period
      properties:
        type:
          type: string
          const: interval
        period:
          type: string
          enum:
            - day
            - day_hour
            - day_minute
            - day_second
            - hour
            - hour_minute
            - hour_second
            - minute
            - minute_second
            - month
            - second
            - year
            - year_month
    NqlObjectType:
      title: object
      type: object
      required:
        - type
        - properties
      properties:
        type:
          type: string
          const: object
        properties:
          description: The types of the object's fields, in order.
          type: array
          items:
            $ref: '#/components/schemas/SimpleType'
    OtherType:
      title: other
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: other
    NqlStringType:
      title: string
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: string
    TimestampType:
      title: timestamp
      type: object
      required:
        - type
      properties:
        type:
          type: string
          const: timestamp
    RegularColumn:
      title: column
      type: object
      description: A column of a dataset, materialized view or view.
      required:
        - column_type
      properties:
        column_type:
          type: string
          const: column
    AttributeColumn:
      title: attribute
      type: object
      description: A column that resolved to an attribute.
      required:
        - column_type
        - id
        - name
      properties:
        column_type:
          type: string
          const: attribute
        id:
          type: integer
          description: The attribute's id.
        name:
          type: string
          description: The attribute's name.
    ReferenceColumn:
      title: reference
      type: object
      description: A column of a `rosetta_stone` or `reference` table.
      required:
        - column_type
      properties:
        column_type:
          type: string
          const: reference
    DatasetTable:
      title: dataset
      type: object
      required:
        - table_type
        - id
        - name
      properties:
        table_type:
          type: string
          const: dataset
        id:
          $ref: '#/components/schemas/DatasetId'
        name:
          $ref: '#/components/schemas/DatasetName'
    AccessRulesTable:
      title: access_rule
      type: object
      required:
        - table_type
        - id
      properties:
        table_type:
          type: string
          const: access_rule
        id:
          $ref: '#/components/schemas/AccessRuleId'
        name:
          oneOf:
            - $ref: '#/components/schemas/AccessRuleName'
            - type: 'null'
    MaterializedViewTable:
      title: materialized_view
      type: object
      required:
        - table_type
        - id
        - name
      properties:
        table_type:
          type: string
          const: materialized_view
        id:
          $ref: '#/components/schemas/DatasetId'
        name:
          $ref: '#/components/schemas/DatasetName'
    RosettaStoneTable:
      title: rosetta_stone
      type: object
      description: The `narrative.rosetta_stone` table.
      required:
        - table_type
      properties:
        table_type:
          type: string
          const: rosetta_stone
    ReferenceTable:
      title: reference
      type: object
      required:
        - table_type
      properties:
        table_type:
          type: string
          const: reference
    ViewTable:
      title: view
      type: object
      required:
        - table_type
        - id
        - name
      properties:
        table_type:
          type: string
          const: view
        id:
          $ref: '#/components/schemas/ViewId'
        name:
          $ref: '#/components/schemas/ViewName'
    DatasetId:
      type: integer
      description: Unique identifier for the dataset.
    DatasetName:
      type: string
      description: >-
        The Dataset's name. Should be unique, contain only alpanum chars and
        underscores. Max length is 256.
    AccessRuleId:
      type: integer
      description: Unique identifier for the access rule.
    AccessRuleName:
      type: string
      description: >-
        It should be unique.

        Also should not intersect with Dataset names.

        Must be <= 256 characters and consist of only alphanumeric characters
        and underscores.
    ViewId:
      type: string
      format: uuid
    ViewName:
      type: string
      description: >-
        It should be unique.

        Must be <= 256 characters and consist of only alphanumeric characters
        and underscores.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````