Quick Start
DUQL (Dangerously Usable Query Language) is a powerful, YAML-based query language designed for data transformation and analysis. DUQL is a variant of PRQL with additional usability improvements, focusing primary on readability and the creation of UI-based query experiences. This guide will help you understand the basics of DUQL and get you started with writing your own queries.
1. Basic Query Structure
A DUQL query typically consists of the following components:
dataset
: Required. Specifies the main data source for your query.steps
: Optional, but typically used. Defines the sequence of operations to perform on your data.
2. Simple Operators and Expressions
DUQL supports various operators for constructing expressions:
Arithmetic:
+
,-
,*
,/
,%
(modulo),**
(exponentiation)Comparison:
==
,!=
,>
,<
,>=
,<=
Logical:
&&
(AND),||
(OR),!
(NOT)String:
+
(concatenation),~=
(regex match)
Example:
3. Basic Functions
DUQL includes many built-in functions for data manipulation:
Aggregate functions (These return a scalar when used within
summarize
, or a column when used anywhere else.:min
max
sum
average
stddev
all
any
concat_array
count
String functions:
lower
upper
trim
length
contains
ends_with
extract
ltrim
rtrim
replace
starts_with
extract
Date functions:
to_text
Mathematical functions:
abs
acos
asin
atan
ceil
cos
degrees
exp
floor
ln
log
log10
pi
pow
radians
round
sin
sqrt
tan
Window functions
lag
lead
first
last
rank
rank_dense
row_number
Example:
4. Common Transformation Steps
Here are some frequently used transformation steps:
Filter
Selects rows based on a condition:
Generate
Creates new columns or modifies existing ones:
Group
Aggregates data based on specified columns:
Sort
Orders the results:
Take
Limits the number of rows returned:
5. Putting It All Together
Here's an example that combines multiple steps to analyze sales data:
This query:
Filters for orders from 2023 onwards
Calculates the total amount for each order and extracts the year
Groups the data by category and year, summarizing total sales and order count
Filters for categories with over $10,000 in sales
Sorts the results by year (descending) and total sales (descending)
Takes the top 5 results
Stores the result in a dataset named
top_selling_categories
Next Steps
As you become more comfortable with DUQL, you can explore more advanced features such as:
Joining multiple datasets
Window functions for complex analytics
Declaring reusable variables and functions
Using subqueries and complex expressions
Remember, DUQL is designed to be intuitive and expressive. Don't hesitate to experiment with different combinations of steps and functions to achieve your data analysis goals!
Last updated
Was this helpful?