Skip to main content
The database provides a REST API for managing semantic views using a human-readable YAML format. This API is an alternative to writing CREATE SEMANTIC VIEW DDL statements directly.

Endpoints

Create/replace (POST /semantic_views) and drop (DELETE /semantic_views/{view}) requests sent to a non-leader FE return HTTP 307 Temporary Redirect. The Location header points to the leader and preserves the escaped request path and query parameters. Native HTTPS requests redirect to HTTPS on https_port, which must be the same on all FEs; enable HTTPS on each FE. Follow the redirect with the same HTTP method and request body, and authenticate to the leader, or send the request directly to the leader. Read endpoints keep their existing routing.

Path parameters

Query parameters

Authentication

All endpoints use HTTP Basic authentication:

Temporary semantic views

temporary is a persistent staging flag, not a session lifetime. Collection GET accepts scope=published|temporary|all: omitted means published (non-temporary only), temporary returns staging views only, and all returns both. Invalid or empty scope returns HTTP 400. Every list entry and named type=summary response includes the boolean temporary. A staging view remains accessible by name with the existing GET, HEAD, columns and DELETE APIs, and can be queried or expanded through /inline under ordinary authorization. /validate and /merge_substrate accept temporary definitions without creating them; the merge substrate also includes the submitted temporary flag. For SQL POST, put TEMPORARY in CREATE [OR REPLACE] TEMPORARY SEMANTIC VIEW. SR YAML POST accepts a top-level temporary: true|false; omission means false. SR GET always exports the current flag. For OSI YAML, the existing model-level custom_extensions entry with vendor_name: STARROCKS carries a JSON string in data:
OSI export writes the current true/false value and import restores it. An absent extension or the legacy data: starrocks means false; other vendors do not control this flag. The JSON temporary value must be a boolean. Exporting and importing either YAML format preserves staging. With replace=true, the submitted definition determines the resulting state; an omitted flag publishes the replacement. No ALTER endpoint is added.

Get semantic-view columns

GET /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/{view}/{kind} Returns the complete metadata for one kind of semantic-view column. Set kind to facts, metrics, or dimensions to return only that kind. Set it to columns to return their union, ordered as facts, metrics, and then dimensions. Every result object uses a common schema: type, name, table, expression, access, filter, synonyms, comment, sampleValues, usingRelationships, nonAdditiveBy, window, searchService, and searchColumn. Fields that do not apply to a particular kind are empty, false, or an empty array.

Create a semantic view

POST /api/v2/catalogs/{catalog}/databases/{db}/semantic_views Creates a new semantic view from a request body. Omit type or set type=sql to submit a single CREATE SEMANTIC VIEW DDL statement. Set type=sr or type=osi to submit YAML, which is converted to a CREATE SEMANTIC VIEW statement internally. Creating a view whose name already exists returns an error; pass replace=true to overwrite it (CREATE OR REPLACE SEMANTIC VIEW).

Request body

The request body is SQL DDL by default. For type=sr, the body is a YAML document describing the semantic view. Content-Type should be text/plain. YAML schema:

Response

Success response body:
Error response body:

Example

List semantic views

GET /api/v2/catalogs/{catalog}/databases/{db}/semantic_views Returns summaries in the specified database according to scope; the default includes only published views.

Response

Success response body:

Example

Get a semantic view

GET /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/{view} Returns the definition of a specific semantic view, either as DDL SQL (default) or as YAML.

Response

Default (DDL SQL)

Returns the CREATE OR REPLACE SEMANTIC VIEW DDL statement as a JSON string:

The database YAML format (?type=sr)

Returns the view definition as plain YAML text (Content-Type: text/plain):

OSI format (?type=osi)

Returns the view definition as an OSI Core Metadata Specification (v0.1.1) YAML document (Content-Type: text/plain):

Examples

Get as DDL:
Or explicitly:
Get as the database YAML:
Get as OSI YAML:

Get a semantic view summary

GET /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/{view}?type=summary Returns the single-view summary as JSON — the REST counterpart of SHOW SEMANTIC VIEW {name}. The fields mirror a row of SHOW SEMANTIC VIEWS. Returns 404 if the view does not exist.

Check whether a semantic view exists

HEAD /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/{view} A lightweight existence check that returns 200 if the view exists and 404 otherwise, with no response body. Use curl -I (HEAD) rather than curl -X HEAD.

Drop a semantic view

DELETE /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/{view} Drops the specified semantic view. This operation uses IF EXISTS semantics and succeeds even if the view does not exist.

Response

Success response body:

Example

Inline a query

POST /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/inline Returns the inline SQL of a query — the equivalent query where every semantic-view reference has been expanded into its underlying base-table SQL (joins + aggregation). The request body is the raw query. The catalog/db path segments provide the default namespace for resolving unqualified view names. The returned SQL is legal and directly executable (all identifiers are quoted). This is the REST counterpart of EXPLAIN INLINE. If the query references no semantic view, inlineSql equals the original query and referencesSemanticView is false.

Response

Example

Export a merge substrate

POST /api/v2/catalogs/{catalog}/databases/{db}/semantic_views/merge_substrate Returns the merge substrate of a semantic view: everything an external tool needs in order to decide whether two semantic views can be combined into one, and to write out the combined definition. Nothing is created and no metadata is written — the semantic view is read from the statement text, so it may be one that has never been created. The request body is a single SQL script containing exactly one CREATE SEMANTIC VIEW and, in any order, the CREATE VIEW statements it stands on. Statements are separated by semicolons. Only the physical tables read by those views have to exist.

What the substrate contains

A logical view supplied in the script may read physical tables and views that already exist in the catalog. It may not read another logical view supplied in the same script: names inside a view are resolved against the catalog rather than against the script, so the two would not be the same definition. That case is rejected, naming both views. When the script supplies a view whose name the catalog already holds, the script’s definition is the one exported, and shadows_catalog marks it so that whoever runs the combined script knows the name is taken.

Example

Create a semantic view using OSI format

To create a semantic view from an OSI YAML body, add ?type=osi to the POST request:
The OSI YAML is converted to a CREATE OR REPLACE SEMANTIC VIEW DDL statement internally before the view is created.

The database native YAML format reference

The following table maps the database native YAML fields to the corresponding CREATE SEMANTIC VIEW DDL clauses:

OSI format reference

The following table maps OSI Core Metadata Specification (v0.1.1) fields to the database concepts: