Compute expressions
A tiny, safe query language. Models write it from a schema card; the SDK evaluates it with the same results in Python, TypeScript and Java.
Run one yourself
from jdogo import run_compute
run_compute('sum(qty) where city = "Cairo"', rows)
# {'ok': True, 'value': 11, 'error': None}import { runCompute } from "jdogo";
runCompute('sum(qty) where city = "Cairo"', rows);JDogoAI.runCompute("sum(qty) where city = \"Cairo\"", rows);jdogo eval 'sum(qty) where city = "Cairo"' rows.json
Every call returns ok, value and error. It never throws on a bad expression.
Aggregates
| Expression | Returns |
|---|---|
count | Number of matching rows |
count distinct(col) | Distinct non-null values |
sum(col) | Sum, skipping nulls; 0 when nothing matches |
avg(col) min(col) max(col) | Mean or extreme; null when nothing matches |
Filters
Add where and a condition to any aggregate.
count where status = "SHIPPED" avg(total) where region in ["EU", "UK"] and total >= 100 count where not (tier = "free" or email is null)
- Operators:
= != < <= > >=,in [..],is null,is not null - Logic:
notbinds tightest, thenand, thenor. Parentheses group. - Strings in double or single quotes. Comparisons are exact and case-sensitive.
Nested data
customer.address.city = "Berlin"follows nested objects.items.sku = "SKU-1"matches a row when any list item matches.items.sku = "X" and items.qty > 4must match the same item.items.length >= 3counts list items.
Missing values
A key missing from a row counts as null: is null is true, comparisons are false, and != is true. A column that appears in no row at all is an error, so a typo is never a silent zero.
Group-by and beyond
Implemented everywhere, off in ask() by default. See how to turn them on.
| Expression | Answers |
|---|---|
group by dept with count | The biggest department. A tie is an error. |
bottom group by cat with avg(price) | The cheapest category on average |
top 3 group by dept with sum(salary) | The three best groups, best first |
rank group by cat with sum(qty) | Every group, best first |
group by dept with count having > 10 | Groups that pass the test |
percent(count where active = true) | Share of rows, 0 to 100 |
percent(sum(total) where region = "EU", sum(total)) | Share of a total, 0 to 100. A sum or average needs the second argument; on its own it is an error |
ratio(sum(a) where s = "OK", sum(a)) | One aggregate divided by another |
median(total) | The middle value |
What it can't express
Arithmetic between columns (price * qty), comparisons with a computed value (amount > avg(amount)), and anything that returns rows. For those, the model replies NEED_ROWS and ask() sends the data.
Errors
- Unknown column or path
- Type mismatch: numeric comparison on text, or
sumof a text column - Syntax errors and trailing text
- Expressions over 2,000 characters or 32 levels deep