cube
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "cube":https://skillpi.com/zh/skills/deepskill-9d353a1427333ce3175d3b2d61dc4d90dfb02c652a8b63db433d3bbbb397964f。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
为 Cube 提供专家级指导。Cube 是一种无头商业智能(BI)和语义层,位于数据仓库与分析应用之间,帮助开发者定义数据模型、创建指标 API,并在应用中构建一致且受管控的分析功能。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: cube
description: Expert guidance for Cube, the headless BI and semantic layer that sits between your data warehouse and analytics applications. Helps developers define data models, create metrics APIs, and build analytics features in applications with consistent, governed access to business metrics.
license: Apache-2.0
compatibility: No special requirements
metadata:
author: terminal-skills
version: 1.0.0
category: data-ai
tags:
- semantic-layer
- analytics
- api
- sql
- metricsCube — Semantic Layer for Analytics
Overview
Cube, the headless BI and semantic layer that sits between your data warehouse and analytics applications. Helps developers define data models, create metrics APIs, and build analytics features in applications with consistent, governed access to business metrics.
Instructions
Data Modeling
Define your business metrics as code:
// model/cubes/Orders.js — Orders cube with measures and dimensions
cube(`Orders`, {
sql_table: `public.orders`,
// Pre-aggregations for performance (materialized rollups)
pre_aggregations: {
daily_revenue: {
measures: [revenue, count],
dimensions: [status, product_category],
time_dimension: created_at,
granularity: `day`,
refresh_key: {
every: `1 hour`, // Refresh hourly
},
},
},
joins: {
Users: {
relationship: `many_to_one`,
sql: `${CUBE}.user_id = ${Users}.id`,
},
Products: {
relationship: `many_to_one`,
sql: `${CUBE}.product_id = ${Products}.id`,
},
},
measures: {
count: {
type: `count`,
},
revenue: {
type: `sum`,
sql: `amount`,
format: `currency`,
},
avg_order_value: {
type: `avg`,
sql: `amount`,
format: `currency`,
},
// Derived measure: revenue per user
revenue_per_user: {
type: `number`,
sql: `${revenue} / NULLIF(${Users.count}, 0)`,
format: `currency`,
},
// Rolling window: 7-day moving average
revenue_7d_avg: {
type: `avg`,
sql: `amount`,
rolling_window: {
trailing: `7 day`,
},
},
},
dimensions: {
id: {
type: `number`,
sql: `id`,
primary_key: true,
},
status: {
type: `string`,
sql: `status`,
},
product_category: {
type: `string`,
sql: `${Products}.category`,
},
amount: {
type: `number`,
sql: `amount`,
},
created_at: {
type: `time`,
sql: `created_at`,
},
},
// Row-level security
segments: {
completed: {
sql: `${CUBE}.status = 'completed'`,
},
high_value: {
sql: `${CUBE}.amount > 100`,
},
},
});
// model/cubes/Users.js — Users cube
cube(`Users`, {
sql_table: `public.users`,
measures: {
count: {
type: `count`,
},
active_count: {
type: `count`,
filters: [{ sql: `${CUBE}.last_login_at > NOW() - INTERVAL '30 days'` }],
},
retention_rate: {
type: `number`,
sql: `${active_count}::float / NULLIF(${count}, 0) * 100`,
format: `percent`,
},
},
dimensions: {
id: {
type: `number`,
sql: `id`,
primary_key: true,
},
email: {
type: `string`,
sql: `email`,
},
plan: {
type: `string`,
sql: `plan`,
},
created_at: {
type: `time`,
sql: `created_at`,
},
country: {
type: `string`,
sql: `country`,
},
},
});
REST API
Query Cube's API from any application:
// src/analytics/cube-client.ts — Query the Cube REST API
const CUBE_API_URL = process.env.CUBE_API_URL!;
const CUBE_API_TOKEN = process.env.CUBE_API_TOKEN!;
interface CubeQuery {
measures?: string[];
dimensions?: string[];
timeDimensions?: {
dimension: string;
granularity?: string;
dateRange?: string | string[];
}[];
filters?: {
member: string;
operator: string;
values?: string[];
}[];
order?: Record<string, "asc" | "desc">;
limit?: number;
}
async function cubeQuery(query: CubeQuery) {
const response = await fetch(`${CUBE_API_URL}/v1/load`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${CUBE_API_TOKEN}`,
},
body: JSON.stringify({ query }),
});
const result = await response.json();
return result.data;
}
// Example: Get monthly revenue by product category
const monthlyRevenue = await cubeQuery({
measures: ["Orders.revenue", "Orders.count"],
dimensions: ["Orders.product_category"],
timeDimensions: [{
dimension: "Orders.created_at",
granularity: "month",
dateRange: "Last 6 months",
}],
order: { "Orders.revenue": "desc" },
limit: 100,
});
// Example: Retention by plan
const retention = await cubeQuery({
measures: ["Users.retention_rate", "Users.active_count"],
dimensions: ["Users.plan"],
filters: [
{ member: "Users.plan", operator: "equals", values: ["free", "pro", "enterprise"] },
],
});
JavaScript SDK (React)
Build analytics UIs with the Cube React SDK:
// src/components/RevenueChart.tsx — React component using Cube
import { useCubeQuery } from "@cubejs-client/react";
import { LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer } from "recharts";
export function RevenueChart({ dateRange = "Last 6 months" }) {
const { resultSet, isLoading, error } = useCubeQuery({
measures: ["Orders.revenue"],
timeDimensions: [{
dimension: "Orders.created_at",
granularity: "month",
dateRange,
}],
});
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
const data = resultSet?.chartPivot() ?? [];
return (
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data}>
<XAxis dataKey="x" />
<YAxis />
<Tooltip formatter={(value: number) => `$${value.toLocaleString()}`} />
<Line type="monotone" dataKey="Orders.revenue" stroke="#6366f1" strokeWidth={2} />
</LineChart>
</ResponsiveContainer>
);
}
Access Control
Define who can see what data:
// cube.js — Security context configuration
module.exports = {
contextToAppId: ({ securityContext }) => {
return `CUBE_APP_${securityContext.tenant_id}`;
},
// Query rewriting based on user context
queryRewrite: (query, { securityContext }) => {
// Multi-tenant: filter all queries by tenant
if (securityContext.tenant_id) {
query.filters.push({
member: "Orders.tenant_id",
operator: "equals",
values: [securityContext.tenant_id],
});
}
// Role-based: restrict measures for non-admin users
if (securityContext.role !== "admin") {
query.measures = query.measures?.filter(
(m) => !["Orders.revenue", "Orders.avg_order_value"].includes(m)
);
}
return query;
},
};
Installation
# Create a new Cube project
npx cubejs-cli create my-analytics -d postgres
# Or with Docker
docker run -d -p 4000:4000 \
-e CUBEJS_DB_TYPE=postgres \
-e CUBEJS_DB_HOST=localhost \
-e CUBEJS_DB_NAME=mydb \
cubejs/cube
# Development
npm run dev
# Cube Playground at http://localhost:4000
Examples
Example 1: Setting up an evaluation pipeline for a RAG application
User request:
I have a RAG chatbot that answers questions from our docs. Set up Cube to evaluate answer quality.
The agent creates an evaluation suite with appropriate metrics (faithfulness, relevance, answer correctness), configures test datasets from real user questions, runs baseline evaluations, and sets up CI integration so evaluations run on every prompt or retrieval change.
Example 2: Comparing model performance across prompts
User request:
We're testing GPT-4o vs Claude on our customer support prompts. Set up a comparison with Cube.
The agent creates a structured experiment with the existing prompt set, configures both model providers, defines scoring criteria specific to customer support (accuracy, tone, completeness), runs the comparison, and generates a summary report with statistical significance indicators.
Guidelines
- Semantic layer = single source of truth — Define metrics once in Cube; all apps query the same definitions
- Pre-aggregations for performance — Materialize common queries; Cube auto-selects the best pre-aggregation
- Use the Playground for exploration — Build queries visually in Cube Playground before coding them into your app
- Security context for multi-tenancy — Use
queryRewriteto automatically filter queries by tenant/user role - Measures over raw SQL — Define
revenue_per_useras a Cube measure, not as raw SQL in your app - Time dimensions for trends — Use
timeDimensionswithgranularityfor consistent time-series queries - Cache aggressively — Cube caches query results; configure
refresh_keybased on your data update frequency - Version your models — Cube models are code; store in Git, review changes, deploy via CI/CD
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Cube 语义层的专家级指导,解决指标一致性、性能优化、多租户安全等实际痛点
- 内容覆盖数据建模、API 集成、前端组件、权限控制等完整使用场景
亮点
- description 清晰完整,准确描述 Cube 作为无头 BI 和语义层的核心价值
- 触发边界清晰,不易与其他数据分析工具混淆
待提升项
-
缺少 When to Use 显式章节 原报告严重程度:轻微
虽有 Overview 章节但未明确命名为 When to Use,不利于用户快速理解适用场景
改进建议:建议在 Overview 后增加显式的 When to Use 章节,明确说明适用场景和用户群体
亮点
- 结构清晰完整:从概述到具体实现再到示例和最佳实践
- 提供丰富的端到端代码示例,涵盖 Cube 模型定义、API 调用、React 集成等
待提升项
-
API 错误处理可进一步完善 原报告严重程度:轻微
cubeQuery 函数未包含网络错误重试机制和超时处理
改进建议:建议添加 fetch 超时设置和错误重试逻辑,提升生产环境可靠性
亮点
- 使用官方 Cube.js 生态工具,参数和配置符合官方规范
- React 组件包含完整的 loading 和 error 状态处理
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 312 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- localhost
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。