### Example Skill Invocation Source: https://docs.cube.dev/docs/explore-analyze/skills This example shows how to invoke a skill with additional context. Type the skill name after a slash, followed by any specific parameters or filters. ```text /weekly-revenue-report for EMEA, last 6 weeks ``` -------------------------------- ### Example Folder Structure Source: https://docs.cube.dev/docs/data-modeling/concepts Illustrates the recommended folder structure for organizing data model files within the 'model' directory. ```tree model ├── cubes │ ├── orders.yml │ ├── products.yml │ └── users.yml └── views ├── revenue.yml └── view_groups.yml ``` -------------------------------- ### Example Query Source: https://docs.cube.dev/docs/data-modeling/access-control/context An example of an incoming query that can be amended with filters. ```json { "measures": [ "orders_view.count" ], "dimensions": [ "orders_view.status" ] } ``` -------------------------------- ### Define Measure with Description and AI Context in JavaScript Source: https://docs.cube.dev/docs/data-modeling/ai-context This JavaScript example demonstrates how to provide both a user-facing 'description' and AI-specific 'meta.ai_context' for a measure, guiding the AI on its usage and importance. ```javascript cube(`order_items`, { sql_table: `ECOMMERCE.ORDER_ITEMS`, description: `Line items for all orders`, measures: { total_sale_price: { sql: `sale_price`, type: `sum`, format: `currency`, description: `Total revenue across all line items`, meta: { ai_context: `This is the primary revenue metric. Always use this instead of summing the sale_price column directly. When users ask about "sales", they mean this measure.` } } } }) ``` -------------------------------- ### YAML SQL Expressions Example Source: https://docs.cube.dev/docs/data-modeling/concepts/syntax Demonstrates using YAML to define measures and dimensions with SQL expressions, including string aggregation and transformation. ```yaml cubes: - name: orders sql_table: orders measures: - name: statuses sql: "STRING_AGG(status)" type: string dimensions: - name: status sql: "UPPER(status)" type: string ``` -------------------------------- ### Time Partitioning by Month (JavaScript) Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations Configure time-based partitioning for a pre-aggregation using `partition_granularity: 'month'`. This example also sets up daily incremental refreshes for the last 3 months. ```javascript cube(`orders`, { // ... preAggregations: { category_and_date: { measures: [count, revenue], dimensions: [category], time_dimension: created_at, granularity: `day`, partition_granularity: `month`, refresh_key: { every: `1 day`, incremental: true, update_window: `3 months` } } } }) ``` -------------------------------- ### Run Cube Store with Docker Source: https://docs.cube.dev/docs/pre-aggregations/running-in-production Starts a Cube Store instance using the official Docker image. Ensure Cube Store is running as a separate process in production. ```bash docker run -p 3030:3030 cubejs/cubestore ``` -------------------------------- ### Folder Permission Inheritance Example Source: https://docs.cube.dev/docs/organize-content/sharing Illustrates how permissions are inherited down the folder hierarchy. Content within a shared folder inherits its access level. ```text Marketing (Full access for Marketing team) ├── Q1 Campaign Dashboard ← inherits Full access ├── Revenue Workbook ← inherits Full access └── Weekly Reports ← inherits Full access └── Week 1 Exploration ← inherits Full access ``` -------------------------------- ### Define Measures with Formatting Source: https://docs.cube.dev/docs/data-modeling/measures Use the 'format' parameter to specify how measures like currency or percentages should be displayed. This example shows currency and percentage formats. ```yaml measures: - name: total_revenue sql: revenue type: sum format: currency - name: conversion_rate sql: "1.0 * {completed_count} / NULLIF({count}, 0)" type: number format: percent ``` -------------------------------- ### Configure Superset Sync in JavaScript Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync Example of configuring a single disabled Superset sync using JavaScript. The 'semanticLayerSync' function should be exported. ```JavaScript module.exports = { semanticLayerSync: ({ securityContext }) => { return [ { type: "superset", name: "Superset Sync", active: false, config: { user: "mail@example.com", password: "4dceae-606a03-93ae6dc7", url: "superset.example.com", database: "Cube Cloud: staging-deployment" } } ] } } ``` -------------------------------- ### JavaScript SQL Expressions Example Source: https://docs.cube.dev/docs/data-modeling/concepts/syntax Demonstrates using JavaScript to define measures and dimensions with SQL expressions, including string aggregation and transformation. ```javascript cube(`orders`, { sql_table: `orders`, measures: { statuses: { sql: `STRING_AGG(status)`, type: `string` } }, dimensions: { status: { sql: `UPPER(status)`, type: `string` } } }) ``` -------------------------------- ### Time Partitioning by Month (YAML) Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations Configure time-based partitioning for a pre-aggregation by setting `partition_granularity` to 'month'. This example also specifies daily incremental refreshes for the last 3 months. ```yaml cubes: - name: orders # ... pre_aggregations: - name: category_and_date measures: - count - revenue dimensions: - category time_dimension: created_at granularity: day partition_granularity: month refresh_key: every: 1 day incremental: true update_window: 3 months ``` -------------------------------- ### Example Query Using Pre-aggregations Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations An example JSON query that utilizes pre-aggregations for 'orders.rollup' and 'users.rollup'. This query will avoid a direct database request by leveraging pre-computed data. ```json { "dimensions": ["users.name"], "timeDimensions": [ { "dimension": "orders.created_at", "dateRange": "This month" } ], "order": { "orders.count": "desc" }, "measures": ["orders.count"] } ``` -------------------------------- ### Cube Measures Transpilation Example Source: https://docs.cube.dev/docs/data-modeling/dynamic/schema-execution-environment Shows how Cube's transpiler converts a measure definition with a SQL reference into a function with resolved arguments. ```javascript cube(`users`, { // ... measures: { count: { type: `count` }, ratio: { sql: `SUM(${CUBE}.amount) / ${count}`, type: `number` } } }) ``` ```javascript cube(`users`, { // ... measures: { count: { type: `count` }, ratio: { sql: (CUBE, count) => `SUM(${CUBE}.amount) / ${count}`, type: `number` } } }) ``` -------------------------------- ### YAML Cube Definition Source: https://docs.cube.dev/docs/data-modeling/concepts A basic example of defining a cube using YAML syntax, including a SQL query for data selection. ```yaml cubes: - name: orders sql: | SELECT * FROM orders, line_items WHERE orders.id = line_items.order_id ``` -------------------------------- ### Example Query for {CUBE} Variable Source: https://docs.cube.dev/docs/data-modeling/concepts An example JSON query structure that utilizes a dimension defined using the {CUBE} variable. This shows how a reference to 'users.name' can be made. ```json { "dimensions": ["users.name"] } ``` -------------------------------- ### Configure Superset Sync in Python Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync Example of configuring a single disabled Superset sync using Python. Ensure the 'semantic_layer_sync' decorator is used. ```Python from cube import config @config('semantic_layer_sync') def semantic_layer_sync(ctx: dict) -> list[dict]: return [ { 'type': 'superset', 'name': 'Superset Sync', 'active': False, 'config': { 'user': 'mail@example.com', 'password': '4dceae-606a03-93ae6dc7', 'url': 'superset.example.com', 'database': 'Cube Cloud: staging-deployment' } } ] ``` -------------------------------- ### YAML Example for Cube Descriptions Source: https://docs.cube.dev/docs/data-modeling/ai-context Provides human-readable context for cubes, measures, and dimensions in YAML format. Useful for clarifying data meaning for both end-users and AI agents. ```yaml cubes: - name: orders sql_table: orders description: All orders including pending, shipped, and completed measures: - name: total_revenue sql: amount type: sum description: Total revenue from completed orders only filters: - sql: "{CUBE}.status = 'completed'" dimensions: - name: status sql: status type: string description: "Current order status: pending, shipped, or completed" ``` -------------------------------- ### JavaScript Example for Cube Descriptions Source: https://docs.cube.dev/docs/data-modeling/ai-context Provides human-readable context for cubes, measures, and dimensions in JavaScript format. Useful for clarifying data meaning for both end-users and AI agents. ```javascript cube(`orders`, { sql_table: `orders`, description: `All orders including pending, shipped, and completed`, measures: { total_revenue: { sql: `amount`, type: `sum`, description: `Total revenue from completed orders only`, filters: [{ sql: `${CUBE}.status = 'completed'` }] } }, dimensions: { status: { sql: `status`, type: `string`, description: `Current order status: pending, shipped, or completed` } } }) ``` -------------------------------- ### Define a Calendar Cube in YAML Source: https://docs.cube.dev/docs/data-modeling/concepts/calendar-cubes Configure a cube as a calendar cube by setting `calendar: true`. This example shows how to define dimensions for time shifts and granularities. ```yaml cubes: - name: fiscal_calendar calendar: true sql: > SELECT date_key, calendar_date, start_of_week, start_of_month, start_of_year, week_ago, month_ago, year_ago FROM calendar_table dimensions: - name: date_key sql: date type: time primary_key: true - name: date sql: date type: time time_shift: - type: prior interval: 1 week sql: "{CUBE}.week_ago" - type: prior interval: 1 month sql: "{CUBE}.month_ago" - type: prior interval: 1 year sql: "{CUBE}.year_ago" granularities: - name: week sql: "{CUBE}.start_of_week" - name: month sql: "{CUBE}.start_of_month" - name: year sql: "{CUBE}.start_of_year" ``` -------------------------------- ### Member-level AI Context for Measures in JavaScript Source: https://docs.cube.dev/docs/data-modeling/ai-context Provide specific instructions for a measure using JavaScript. Use this to guide AI on how to interpret and use the measure. ```javascript total_sale_price: { sql: `sale_price`, type: `sum`, format: `currency`, meta: { ai_context: `Use this measure for any revenue-related questions. It includes all line items regardless of order status.` } } ``` -------------------------------- ### Define Measure with Description and AI Context in YAML Source: https://docs.cube.dev/docs/data-modeling/ai-context Use 'description' for user-facing explanations and 'meta.ai_context' for AI-specific guidance on measures. This example shows how to define a primary revenue metric in YAML. ```yaml cubes: - name: order_items sql_table: ECOMMERCE.ORDER_ITEMS description: Line items for all orders measures: - name: total_sale_price sql: sale_price type: sum format: currency description: Total revenue across all line items meta: ai_context: > This is the primary revenue metric. Always use this instead of summing the sale_price column directly. When users ask about "sales", they mean this measure. ``` -------------------------------- ### Define a Calendar Cube in JavaScript Source: https://docs.cube.dev/docs/data-modeling/concepts/calendar-cubes Configure a cube as a calendar cube using JavaScript by setting `calendar: true`. This example demonstrates defining time shifts and granularities. ```javascript cube('fiscal_calendar', { calendar: true, sql: ` SELECT date_key, calendar_date, start_of_week, start_of_month, start_of_year, week_ago, month_ago, year_ago FROM calendar_table `, dimensions: { date_key: { sql: 'date_key', type: 'time', primary_key: true }, date: { sql: 'calendar_date', type: 'time', time_shift: [ { type: 'prior', interval: '1 week', sql: '{CUBE}.week_ago' }, { type: 'prior', interval: '1 month', sql: '{CUBE}.month_ago' }, { type: 'prior', interval: '1 year', sql: '{CUBE}.year_ago' } ], granularities: [ { name: 'week', sql: '{CUBE}.start_of_week' }, { name: 'month', sql: '{CUBE}.start_of_month' }, { name: 'year', sql: '{CUBE}.start_of_year' } ] } } }) ``` -------------------------------- ### Python Configuration for Superset Sync Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync/superset Use this Python snippet to configure Semantic Layer Sync for Apache Superset. Ensure you have the 'cube' library installed. Replace placeholder values with your Superset credentials and URL. ```python from cube import config @config('semantic_layer_sync') def semantic_layer_sync(ctx: dict) -> list[dict]: return [ { 'type': 'superset', 'name': 'Superset Sync', 'config': { 'user': 'mail@example.com', 'password': '4dceae-606a03-93ae6dc7', 'url': 'superset.example.com', 'database': 'Cube Cloud: production-deployment' } } ] ``` -------------------------------- ### Cube Store File System Error for Creation Time Source: https://docs.cube.dev/docs/pre-aggregations/running-in-production Example error message logged by Cube Store when the underlying file system does not support reporting file creation times, which is required for garbage collection. ```text ERROR [cubestore::remotefs::cleanup] error while getting created time for file ".chunk.parquet": creation time is not available for the filesystem ``` -------------------------------- ### Example JWT Payload Source: https://docs.cube.dev/docs/data-modeling/access-control/context An example JWT payload containing user information that will be injected into the security context. ```json { "sub": "1234567890", "iat": 1516239022, "user_id": 42 } ``` -------------------------------- ### Deploy Local Cube Project using CLI Source: https://docs.cube.dev/docs/getting-started/migrate-from-core/upload-with-cli Run this command from your Cube project directory to upload your project to Cube Cloud. Ensure you replace with your actual deployment token. ```bash npx cubejs-cli deploy --token ``` -------------------------------- ### Run Cube with Docker and Connect to Cube Store Source: https://docs.cube.dev/docs/pre-aggregations/running-in-production Starts a Cube instance using Docker, connecting it to a running Cube Store on localhost:3030. The CUBEJS_CUBESTORE_HOST environment variable is used to specify the Cube Store location. ```bash docker run -p 4000:4000 \ -e CUBEJS_CUBESTORE_HOST=localhost \ -v ${PWD}:/cube/conf \ cubejs/cube ``` -------------------------------- ### Microsoft Entra ID SCIM Expression Mapping Example Source: https://docs.cube.dev/docs/integrations/power-bi/kerberos Provides an example of using an Expression mapping in Microsoft Entra ID SCIM to construct a principal name from parts, such as joining samAccountName with a realm. This is useful when the source attribute does not directly contain the full Kerberos principal name. ```json { "Mapping type": "Expression", "Expression": "Join(\"@\", [samAccountName], \"INTERNAL.REALM\")", "Target attribute": "urn:cube:params:1.0:UserAliases:alternateUserName", "Apply this mapping": "Always" } ``` -------------------------------- ### Generated SQL with Filter Source: https://docs.cube.dev/docs/data-modeling/access-control/context Example SQL generated by Cube after applying the query_rewrite filter based on user ID. ```sql SELECT "orders".STATUS "orders_view__status", count("orders".ID) "orders_view__count" FROM ECOM.ORDERS AS "orders" LEFT JOIN ECOM.USERS AS "users" ON "orders".USER_ID = "users".ID WHERE ("users".ID = 42) GROUP BY 1 ORDER BY 2 DESC LIMIT 5000 ``` -------------------------------- ### Importing from Parent Directories Source: https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import Demonstrates importing a helper function from a shared utility file located in a parent directory, respecting Cube's flattened directory structure. ```javascript // in model/sales/orders.js import { capitalize } from "./shared_utils/utils" ``` -------------------------------- ### Shared Utility Function Source: https://docs.cube.dev/docs/data-modeling/dynamic/code-reusability-export-and-import An example of a shared utility function, `capitalize`, exported from a `utils.js` file for use in other modules. ```javascript // in model/shared_utils/utils.js export const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1) ``` -------------------------------- ### Connect to Cube Store using MySQL CLI Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations Connect to Cube Store using the MySQL CLI client. Ensure you replace with your Cube Store IP address. ```bash mysql -h --user=cubestore -pcubestore --protocol=TCP ``` -------------------------------- ### Python API Token Generation Source: https://docs.cube.dev/docs/data-modeling/access-control/context Generate a JWT token in Python for testing access control. Requires PyJWT installation. ```python # Install the PyJWT with pip install PyJWT import jwt import datetime # Secret key to sign the token CUBE_API_SECRET = 'secret' # Create the token token_payload = { 'user_id': 42 } # Generate the JWT token token = jwt.encode(token_payload, CUBE_API_SECRET, algorithm='HS256') ``` -------------------------------- ### Dynamically Generating Cubes from API Data Source: https://docs.cube.dev/docs/data-modeling/dynamic/javascript This example demonstrates fetching dynamic cube definitions from an API, transforming their properties using utility functions, and then registering them using the cube() global function within an asyncModule(). ```javascript // model/cubes/DynamicDataModel.js const fetch = require("node-fetch"); import { convertStringPropToFunction, transformDimensions, transformMeasures, } from "./utils"; asyncModule(async () => { const dynamicCubes = await ( await fetch("http://your-api-endpoint/dynamicCubes") ).json(); console.log(dynamicCubes); // [ // { // name: 'dynamic_cube_model', // sql_table: 'my_table', // // measures: { // price: { // sql: `price`, // type: `number`, // } // }, // // dimensions: { // color: { // sql: `color`, // type: `string`, // }, // }, // }, // ] dynamicCubes.forEach((dynamicCube) => { const dimensions = transformDimensions(dynamicCube.dimensions); const measures = transformMeasures(dynamicCube.measures); cube(dynamicCube.name, { sql: dynamicCube.sql, dimensions, measures, pre_aggregations: { main: { // ... }, }, }); }); }); ``` -------------------------------- ### Show Logical Plan with EXPLAIN Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations Use EXPLAIN to view the logical execution plan of a query in Cube Store. This helps in understanding the high-level query processing steps. ```sql EXPLAIN SELECT orders__platform, orders__gender, sum(orders__count) FROM dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r GROUP BY orders__gender, orders__platform; +-------------------------------------------------------------------------------------------------------------------------------------+ | logical plan | +--------------------------------------------------------------------------------------------------------------------------------------+ | Projection, [dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r.orders__platform, dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r.orders__gender, SUM(dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r.orders__count)] Aggregate ClusterSend, indices: [[96]] Scan dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r, source: CubeTable(index: orders_general_plat_gender_o32v4dvq_vbyemtl2_1h5hs8r:96:[123, 126]), fields: [orders__gender, orders__platform, orders__count] | +-------------------------------------------------------------------------------------------------------------------------------------+ ``` -------------------------------- ### Member-level AI Context for Dimensions in YAML Source: https://docs.cube.dev/docs/data-modeling/ai-context Provide specific instructions for a dimension. Use this to guide AI on the meaning and usage of the dimension. ```yaml dimensions: - name: created_at sql: created_at type: time meta: ai_context: > This is the order creation timestamp in UTC. For delivery analysis, use delivered_at instead. ``` -------------------------------- ### Member-level AI Context for Measures in YAML Source: https://docs.cube.dev/docs/data-modeling/ai-context Provide specific instructions for a measure. Use this to guide AI on how to interpret and use the measure. ```yaml cubes: - name: order_items sql_table: ECOMMERCE.ORDER_ITEMS measures: - name: total_sale_price sql: sale_price type: sum format: currency meta: ai_context: > Use this measure for any revenue-related questions. It includes all line items regardless of order status. ``` -------------------------------- ### Define Orders Cube in YAML Source: https://docs.cube.dev/docs/pre-aggregations/getting-started-pre-aggregations Defines the 'orders' cube with basic measures and dimensions in YAML format. This serves as the base for pre-aggregation examples. ```yaml cubes: - name: orders sql_table: orders measures: - name: count type: count dimensions: - name: id sql: id type: number primary_key: true - name: status sql: status type: string - name: completed_at sql: completed_at type: time ``` -------------------------------- ### Configure Pre-aggregations for Cube Data (JavaScript) Source: https://docs.cube.dev/docs/data-modeling/cubes Set up pre-aggregations to materialize summaries of cube data for faster query execution in JavaScript. Cube automatically matches queries to the best available pre-aggregation. ```javascript cube(`orders`, { // ... pre_aggregations: { main: { measures: [count, total_amount], dimensions: [status], time_dimension: created_at, granularity: `day` } } }) ``` -------------------------------- ### Organizing View Members with Folders (YAML) Source: https://docs.cube.dev/docs/data-modeling/views Demonstrates how to use folders to group fields within a view definition in YAML format. This helps in organizing complex views by creating logical sections for fields. ```yaml views: - name: customers cubes: - join_path: users includes: "*" - join_path: users.orders prefix: true includes: - status - price - count folders: - name: Personal Details includes: - name - gender - created_at - name: Order Analytics includes: - orders_status - orders_price - orders_count ``` -------------------------------- ### Create a View (YAML) Source: https://docs.cube.dev/docs/data-modeling/overview Views provide a facade over cubes, useful for defining metrics and managing data model exposure. Use 'includes: "*"' to include all members from the joined cube. ```yaml views: - name: users_view cubes: - join_path: users includes: - "*" ``` -------------------------------- ### Define a Sales Overview View in YAML Source: https://docs.cube.dev/docs/data-modeling/views This YAML snippet defines a 'sales_overview' view, including its description, AI context, and the cubes and fields to be included. It also demonstrates organizing fields into folders for better usability. ```yaml views: - name: sales_overview description: > Revenue and order metrics for the sales team. Includes order status, product details, and customer segments. meta: ai_context: > Use this view for questions about sales performance, revenue trends, and order analysis. The total_revenue measure includes only completed orders. cubes: - join_path: orders includes: - status - total_revenue - count - created_date - join_path: orders.customers prefix: true includes: - segment - region folders: - name: Order Metrics includes: - total_revenue - count - status - name: Customer Info includes: - customers_segment - customers_region ``` -------------------------------- ### Show Physical Plan with EXPLAIN ANALYZE Source: https://docs.cube.dev/docs/pre-aggregations/using-pre-aggregations Use EXPLAIN ANALYZE to inspect the physical execution plan, including router and worker node details. This is useful for deep performance debugging. ```sql EXPLAIN ANALYZE SELECT orders__platform, orders__gender, sum(orders__count) FROM dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r GROUP BY orders__gender, orders__platform +-----------+-----------------+--------------------------------------------------------------------------------------------------------------------------+ | node type | node name | physical plan | +-----------+-----------------+--------------------------------------------------------------------------------------------------------------------------+ | router | | Projection, [orders__platform, orders__gender, SUM(dev_pre_aggregations.orders_general_o32v4dvq_vbyemtl2_1h5hs8r.orders__count)@2:SUM(orders__count)] FinalInplaceAggregate ClusterSend, partitions: [[123, 126]] | | worker | 127.001:10001 | PartialInplaceAggregate Merge Scan, index: orders_general_plat_gender_o32v4dvq_vbyemtl2_1h5hs8r:96:[123, 126], fields: [orders__gender, orders__platform, orders__count] Projection, [orders__gender, orders__platform, orders__count] ParquetScan, files: /.cubestore/data/126-0qtyakym.parquet | +-----------+-----------------+--------------------------------------------------------------------------------------------------------------------------+ ``` -------------------------------- ### Defining Blended Measures in Cube Schema Source: https://docs.cube.dev/docs/data-modeling/concepts/data-blending Example of defining blended measures within a Cube schema, including filters and calculated measures. ```javascript filters: [{ sql: `${CUBE}.row_type = 'retail'` }] }, online_revenue_percentage: { sql: ` ${online_revenue} / NULLIF(${online_revenue} + ${offline_revenue}, 0) `, type: `number`, format: `percent` } }, dimensions: { created_at: { sql: `created_at`, type: `time` }, revenue_type: { sql: `row_type`, type: `string` } } }) ``` -------------------------------- ### Create a View (JavaScript) Source: https://docs.cube.dev/docs/data-modeling/overview Views provide a facade over cubes, useful for defining metrics and managing data model exposure. Use 'includes: "*"' to include all members from the joined cube. ```javascript view(`users_view`, { cubes: [ { join_path: users, includes: `*` } ] }) ``` -------------------------------- ### Curl Request with Authorization Header Source: https://docs.cube.dev/docs/data-modeling/access-control/context Example curl command to authorize a request to the Cube API using a generated JWT token in the Authorization header. ```bash curl \ -H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1Ijp7ImlkIjo0Mn0sImlhdCI6MTU1NjAyNTM1MiwiZXhwIjoxNTU4NjE3MzUyfQ._8QBL6nip6SkIrFzZzGq2nSF8URhl5BSSSGZYp7IJZ4" \ -G \ --data-urlencode 'query={"measures":["orders.count"]}' \ http://localhost:4000/cubejs-api/v1/load ``` -------------------------------- ### Python Multitenancy Sync Configuration Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync Synchronizes data models to a dedicated database per department using Superset. Requires the 'semantic_layer_sync' configuration. ```python from cube import config @config('semantic_layer_sync') def semantic_layer_sync(ctx: dict) -> list[dict]: department = ctx['securityContext']['department'] return [ { 'type': 'superset', 'name': f"Superset Sync for {department}", 'config': { 'user': 'mail@example.com', 'password': '4dceae-606a03-93ae6dc7', 'url': 'superset.example.com', 'database': f"Cube Cloud: {department}", } } ] ``` -------------------------------- ### Member-level AI Context for Dimensions in JavaScript Source: https://docs.cube.dev/docs/data-modeling/ai-context Provide specific instructions for a dimension using JavaScript. Use this to guide AI on the meaning and usage of the dimension. ```javascript created_at: { sql: `created_at`, type: `time`, meta: { ai_context: `This is the order creation timestamp in UTC. For delivery analysis, use delivered_at instead.` } } ``` -------------------------------- ### YAML Cube Definition with SQL Expressions Source: https://docs.cube.dev/docs/data-modeling/concepts Demonstrates defining a cube with SQL expressions for measures and dimensions, including string aggregation and case conversion. ```yaml cubes: - name: orders sql_table: orders measures: - name: statuses sql: "STRING_AGG(status)" type: string dimensions: - name: status sql: "UPPER(status)" type: string ``` -------------------------------- ### JavaScript Configuration for Superset Sync Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync/superset This JavaScript snippet demonstrates how to set up Semantic Layer Sync for Apache Superset. It requires Node.js and the 'cube' package. Update the configuration with your Superset details. ```javascript module.exports = { semanticLayerSync: ({ securityContext }) => { return [ { type: "superset", name: "Superset Sync", config: { user: "mail@example.com", password: "4dceae-606a03-93ae6dc7", url: "superset.example.com", database: "Cube Cloud: production-deployment" } } ] } } ``` -------------------------------- ### YAML Dimension Definition with Bare Column Name Source: https://docs.cube.dev/docs/data-modeling/concepts An example of defining a dimension using a bare column name, referencing the 'name' column from the 'users' table. ```yaml cubes: - name: users sql_table: users dimensions: - name: name sql: name type: string ``` -------------------------------- ### Period-to-Date Measures (Sum) Source: https://docs.cube.dev/docs/data-modeling/measures Calculates sum measures from the start of a period (year, quarter) to the current date using `rolling_window` with `type: to_date` and a specified `granularity`. ```yaml measures: - name: revenue_ytd sql: revenue type: sum rolling_window: type: to_date granularity: year - name: revenue_qtd sql: revenue type: sum rolling_window: type: to_date granularity: quarter ``` -------------------------------- ### Run Power BI Desktop with a specific report as a user Source: https://docs.cube.dev/docs/integrations/power-bi/ntlm Launch Power BI Desktop with a specific report file while running as a designated user. This is intended for testing NTLM authentication flows. ```bash # Run a specific report in Power BI Desktop as the `cube` user runas /netonly /user:cube "C:\Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe \"C:\Users\Administrator\Desktop\Dashboard.pbix\"" ``` -------------------------------- ### Define Pre-aggregation in JavaScript Source: https://docs.cube.dev/docs/pre-aggregations Example of defining a pre-aggregation named 'amount_by_created' for the 'orders' cube in JavaScript format. This pre-aggregation aggregates the 'total_amount' measure by 'created_at' at a monthly granularity. ```javascript cube(`orders`, { sql_table: `orders`, measures: { total_amount: { sql: `amount`, type: `sum` } }, dimensions: { created_at: { sql: `created_at`, type: `time` } }, pre_aggregations: { amount_by_created: { measures: [total_amount], time_dimension: created_at, granularity: `month` } } }) ``` -------------------------------- ### Define Pre-aggregation in YAML Source: https://docs.cube.dev/docs/pre-aggregations Example of defining a pre-aggregation named 'amount_by_created' for the 'orders' cube in YAML format. This pre-aggregation aggregates the 'total_amount' measure by 'created_at' at a monthly granularity. ```yaml cubes: - name: orders sql_table: orders measures: - name: total_amount sql: amount type: sum dimensions: - name: created_at sql: created_at type: time pre_aggregations: - name: amount_by_created measures: - total_amount time_dimension: created_at granularity: month ``` -------------------------------- ### Define Join Path in JavaScript Source: https://docs.cube.dev/docs/data-modeling/joins Example of defining dimensions with join paths in JavaScript for calculated members. It demonstrates referencing a country from related 'customers' and 'shipping_addresses' cubes. ```javascript cube(`orders`, { // ... dimensions: { customer_country: { sql: `${customers.country}`, type: `string` }, shipping_country: { sql: `${shipping_addresses.country}`, type: `string` } } }) ``` -------------------------------- ### JavaScript Multitenancy Sync Configuration Source: https://docs.cube.dev/docs/integrations/semantic-layer-sync Synchronizes data models to a dedicated database per department using Superset. Requires the 'semanticLayerSync' configuration. ```javascript module.exports = { semanticLayerSync: ({ securityContext }) => { const department = securityContext.department return [ { type: "superset", name: `Superset Sync for ${department}`, config: { user: "mail@example.com", password: "4dceae-606a03-93ae6dc7", url: "superset.example.com", database: `Cube Cloud: ${department}` } } ] } } ``` -------------------------------- ### Define Many-to-One Relationship in JavaScript Source: https://docs.cube.dev/docs/data-modeling/joins Example of defining a many-to-one join between 'orders' and 'customers' cubes using the Cube.js JavaScript API. This sets up the relationship for data modeling. ```javascript cube(`orders`, { sql_table: `orders`, joins: { customers: { relationship: `many_to_one`, sql: `${CUBE}.customer_id = ${customers.id}` } }, dimensions: { id: { sql: `id`, type: `number`, primary_key: true }, status: { sql: `status`, type: `string` } }, measures: { count: { type: `count` } } }) cube(`customers`, { sql_table: `customers`, dimensions: { id: { sql: `id`, type: `number`, primary_key: true }, company: { sql: `company`, type: `string` } } }) ``` -------------------------------- ### Example Security Context Object Source: https://docs.cube.dev/docs/data-modeling/access-control/context This JSON object represents a typical security context structure. It includes user identification and location details, which can be used for access control. ```json { "sub": "1234567890", "iat": 1516239022, "user_name": "John Doe", "user_id": 42, "location": { "city": "San Francisco", "state": "CA" } } ```