Skip to main content

Create a view

Creates a new view for a datasource.

To verify that the Coordinator has propagated your view to all Brokers and that it is ready for querying, Inspect the view load status.

URL

POST /druid-ext/view-manager/v1/views/{view name}

Required resource

The create view API requires the following resource:

  • {view name}:The view name to create. View names follow the same restrictions as datasources and other Druid objects. View names are case-sensitive.

Payload

The create view takes a JSON payload with the following key:

  • "viewSql": String. The definition of the SQL view.

The following query features are not supported in view definitions:

  • Subqueries of any kind.
  • Joins of any kind.
  • UNION ALL.
  • Aggregations.
  • LIMIT, OFFSET, ORDER BY operations.
  • Queries on anything that is not a base datasource: lookups, INFORMATION_SCHEMA, sys.* tables, or other views.
  • Transforms on the projected columns. Note: transforms within filters are allowed.

Sample payload

{
"viewSql": "SELECT __time, added, channel, page FROM wikipedia WHERE channel = '#en.wikipedia'"
}

Success response

CodeExample Body
201 Creatednone

Selected error responses

CodeExample Body
400 Bad Request{ "error": "View english already exists" }
400 Bad Request{ "error": "error": "Invalid view definition: SELECT __tXme, added, channel, page FROM wikipedia WHERE channel = '#fr.wikipedia'"
400 Bad Request{"error": "Subqueries cannot be used in view definitions."}

Sample request

curl --location --request POST 'http://localhost:8081/druid-ext/view-manager/v1/views/english' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <encoded authorization string>' \
--data-raw '{
"viewSql": "SELECT __time, added, channel, page FROM druid.wikipedia WHERE channel = '\''#en.wikipedia'\''"
}'

Learn more

See the following topics for more information: