Requesting SQL
On this page
Metrics SQL
DJ can generate SQL for one or more metrics with a set of compatible filters and group by dimensions.
dj.sql(
metrics=[
"default.avg_repair_price",
"default.num_repair_orders",
],
dimensions=[
"default.hard_hat.city",
"default.hard_hat.state",
],
filters=[
"default.hard_hat.state = 'NY'"
],
)
curl -X 'GET' \
'http://localhost:8000/sql/?metrics=default.num_repair_orders&&metrics=default.avg_repair_price&dimensions=default.hard_hat.city&dimensions=default.hard_hat.state&filters=default.hard_hat.state%20%3D%20%27NY%27' \
-H 'accept: application/json'
dj.sql.get(
metrics=[
"default.num_repair_orders",
"default.avg_repair_price",
],
dimensions=[
"default.hard_hat.city",
"default.hard_hat.state",
],
filters=["default.hard_hat.state = 'NY'"]
).then(data => console.log(data))
You can optionally provide an
engine_name
and engine_version
. A typical DataJunction query service will include a default engine.Node SQL
DJ can generate SQL for a node with a compatible filters and dimensions.
dj.sql(
node_name=[
"default.repair_orders_fact",
],
dimensions=[
"default.hard_hat.city",
"default.hard_hat.state",
],
filters=[
"default.hard_hat.state = 'NY'"
],
)
curl -X 'GET' \
'http://localhost:8000/sql/default.repair_orders_fact?dimensions=default.hard_hat.city&dimensions=default.hard_hat.state&filters=default.hard_hat.state%20%3D%20%27NY%27' \
-H 'accept: application/json'
Measures SQL
DJ can also return the measures SQL for a set of metrics with group by dimensions and filters. This SQL can be used to produce an intermediate table with all the measures and dimensions needed for an analytics database (e.g., Druid).
dj.sql(
metrics=[
"default.avg_repair_price",
"default.num_repair_orders",
],
dimensions=[
"default.hard_hat.city",
"default.hard_hat.state",
],
filters=[
"default.hard_hat.state = 'NY'"
],
measures=True,
)
curl -X 'GET' \
'http://localhost:8000/sql/measures?metrics=default.num_repair_orders&&metrics=default.avg_repair_price&dimensions=default.hard_hat.city&dimensions=default.hard_hat.state&filters=default.hard_hat.state%20%3D%20%27NY%27' \
-H 'accept: application/json'