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
Code | Example Body |
---|---|
201 Created | none |
Selected error responses
Code | Example 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:
- View Manager APIs for a full list of View Manager APIs and links to examples.
- Row and column level security to learn how to use views to secure data.
- View Manager for a description of the Imply View Manager.