cube-run-query
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRun a query against Cube
对Cube运行查询
This is the one skill that steps outside the CLI. is bound to
Cube's console API and cannot reach a deployment's query endpoint, so
querying is two CLI calls to get a URL and a token, then a direct request to
the deployment.
cube api这是唯一一个跳出CLI的技能。绑定到Cube的控制台API,无法访问部署的查询端点,因此查询需要两步CLI调用:获取URL和令牌,然后直接向部署发起请求。
cube apiPreflight
预检
bash
command -v cube >/dev/null || echo "Cube CLI not installed: curl -fsSL https://raw.githubusercontent.com/cube-js/cube/master/install-cli.sh | sh"
cube whoami || echo "Not authenticated. Interactive: cube login. Headless: set CUBE_API_URL + CUBE_API_KEY."
cube context listjqcurlbash
command -v cube >/dev/null || echo "Cube CLI not installed: curl -fsSL https://raw.githubusercontent.com/cube-js/cube/master/install-cli.sh | sh"
cube whoami || echo "Not authenticated. Interactive: cube login. Headless: set CUBE_API_URL + CUBE_API_KEY."
cube context list与本插件中的其他技能不同,这里还需要和。请检查是否已安装,若缺失请告知用户。
jqcurlGet the endpoint and a token
获取端点和令牌
bash
DEPLOYMENT=<id>
URL=$(cube deployments get "$DEPLOYMENT" --json | jq -r .deploymentUrl)
TOKEN=$(cube deployments token "$DEPLOYMENT")cube deployments token--jsonbash
DEPLOYMENT=<id>
URL=$(cube deployments get "$DEPLOYMENT" --json | jq -r .deploymentUrl)
TOKEN=$(cube deployments token "$DEPLOYMENT")cube deployments token--jsonKnow what you can query first
先了解可查询内容
Do not guess member names. Ask the compiled model:
bash
cube meta --selectors '[{"type":"cube","deploymentId":'"$DEPLOYMENT"',"environment":"production"}]'Members are or . A dimension that exists on a cube
but is not exposed in a view is not queryable through that view —
is what tells you which is which.
Cube.memberView.membercube meta不要猜测成员名称。请查询编译后的模型:
bash
cube meta --selectors '[{"type":"cube","deploymentId":'"$DEPLOYMENT"',"environment":"production"}]'成员格式为或。Cube上存在但未在视图中暴露的维度无法通过该视图查询——会告诉你哪些是可查询的。
Cube.memberView.membercube metaRun it
运行查询
bash
curl -s "$URL/cubejs-api/v1/load" \
-H "Authorization: $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"query":{
"measures":["Orders.count","Orders.totalRevenue"],
"dimensions":["Orders.status"],
"timeDimensions":[{"dimension":"Orders.createdAt","granularity":"month","dateRange":"Last 6 months"}],
"limit":100
}}' | jqQuery shape, in the order you usually need it:
- — the numbers. Always fully qualified.
measures - — what to break down by.
dimensions - —
timeDimensionsplusdimension(granularity/day/week/…) andmonth, which accepts natural ranges likedateRangeor an explicit"Last 30 days".["2026-01-01","2026-06-30"] - —
filters.[{"member":"Orders.status","operator":"equals","values":["paid"]}] - ,
order.limit
The response carries plus , which holds the human titles
and formats for each member. Use when presenting results — it is
where a measure's display name and unit live.
dataannotationannotationbash
curl -s "$URL/cubejs-api/v1/load" \
-H "Authorization: $TOKEN" \
-H 'Content-Type: application/json' \
-d '{"query":{
"measures":["Orders.count","Orders.totalRevenue"],
"dimensions":["Orders.status"],
"timeDimensions":[{"dimension":"Orders.createdAt","granularity":"month","dateRange":"Last 6 months"}],
"limit":100
}}' | jq查询结构(通常所需的顺序):
- ——数值指标,必须完全限定。
measures - ——用于分组的维度。
dimensions - ——包含
timeDimensions、dimension(granularity/day/week/…)和month,其中dateRange接受自然语言范围(如dateRange)或明确的日期数组(如"Last 30 days")。["2026-01-01","2026-06-30"] - ——格式示例:
filters。[{"member":"Orders.status","operator":"equals","values":["paid"]}] - 、
order。limit
响应包含和,其中存储每个成员的可读标题和格式。展示结果时请使用——度量值的显示名称和单位都在这里。
dataannotationannotationannotationInterpreting results
结果解读
- Report the number, then how it was derived. Which measure, which range, which filters. A number without its query is not checkable.
- An empty array is a result, not an error. Say the query succeeded and returned no rows; do not retry with a different query and present that instead without saying you changed it.
data - Never fill in a value you did not receive. If the query failed, report the error.
- 先报告数值,再说明推导方式:包括使用的度量值、时间范围、筛选条件。没有查询上下文的数值无法被验证。
- 空的数组是有效结果,而非错误:请说明查询成功但未返回任何行;不要擅自改用其他查询并展示结果却不告知用户。
data - 切勿填充未获取到的值:如果查询失败,请报告错误信息。
Verifying a model change
验证模型变更
The common case after : query the new measure on the dev
branch before merging. Point the environment at the branch when getting meta,
and query the deployment the same way — the token and URL are per-deployment,
not per-branch.
cube-build-modelcube-build-modelWhen something fails
故障排查
| Symptom | Cause |
|---|---|
| The deployment has never finished a build; check |
| 401 from the load endpoint | Token expired — they are short-lived, just mint another |
| Wrong name or not exposed in that view — re-check |
| Query hangs | A large uncached query; report it rather than silently retrying |
| 症状 | 原因 |
|---|---|
| 部署从未完成构建;请检查 |
| 加载端点返回401 | 令牌过期——令牌有效期很短,重新生成一个即可 |
| 名称错误或未在该视图中暴露——重新检查 |
| 查询挂起 | 未缓存的大型查询;请报告此情况,不要静默重试 |