|
# Create View Worker
|
|
|
|
Processes view creation jobs to create database views from queries.
|
|
|
|
## Overview
|
|
|
|
The create view worker creates database views based on SQL queries, allowing dynamic datasets that update when source data changes.
|
|
|
|
## Job Type
|
|
|
|
`create_view`
|
|
|
|
## Input Parameters
|
|
|
|
```json
|
|
{
|
|
"source_dataset_id": 123,
|
|
"query": "SELECT * FROM spatial_data_123 WHERE properties->>'category' = 'A'",
|
|
"output_dataset_id": 124
|
|
}
|
|
```
|
|
|
|
### Parameters
|
|
|
|
- `source_dataset_id` (required): Source dataset ID
|
|
- `query` (required): SQL query to create view from
|
|
- `output_dataset_id` (required): Output dataset ID
|
|
|
|
## Output
|
|
|
|
Creates a new dataset backed by a database view:
|
|
|
|
- View created in `spatial_data` schema
|
|
- Dataset metadata in `spatial_files` table
|
|
- View updates automatically when source data changes
|
|
|
|
## Use Cases
|
|
|
|
- Filtered datasets
|
|
- Joined datasets
|
|
- Aggregated datasets
|
|
- Computed datasets
|
|
|
|
## Example
|
|
|
|
```bash
|
|
# Enqueue a create view job via API
|
|
curl -X POST "https://example.com/api/create_view_run.php" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"source_dataset_id": 123,
|
|
"query": "SELECT * FROM spatial_data_123 WHERE properties->>'\''category'\'' = '\''A'\''",
|
|
"output_dataset_id": 124
|
|
}'
|
|
```
|
|
|
|
## Background Jobs
|
|
|
|
This analysis runs as a background job. The worker:
|
|
|
|
1. Fetches queued `create_view` jobs
|
|
2. Validates input parameters
|
|
3. Validates SQL query
|
|
4. Creates database view
|
|
5. Creates dataset metadata
|
|
6. Marks job as completed
|
|
|
|
## Performance Considerations
|
|
|
|
- Views don't store data, so creation is fast
|
|
- Query performance depends on underlying data
|
|
- Complex queries may slow view access
|
|
- Consider materialized views for expensive queries
|
|
|
|
## Related Documentation
|
|
|
|
- [Analysis API](../api/analysis.md)
|
|
- [Workers Overview](index.md)
|
|
|