Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 5 additions & 78 deletions docs-mintlify/docs/data-modeling/view-groups.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ view_group(`sales`, {

## Assigning views to a group

There are two ways to assign a view to a group, and both can be combined.
Pick whichever keeps group membership co-located with the entity you'd
rather edit — the group definition for a curated catalog, or the view
definition for ad-hoc additions.

### From the group side

List views on the group via the [`views`][ref-view-group-views] parameter.
This keeps the full membership in one place, which is convenient when you
want to review a group at a glance.
To assign a view to a group, list its name on the group via the
[`views`][ref-view-group-views] parameter. This keeps the full
membership in one place, which makes it easy to review a group at a glance.

<CodeGroup>

Expand All @@ -73,72 +66,8 @@ view_group(`sales`, {

</CodeGroup>

### From the view side

Set [`view_group`][ref-view-view-group] on the view itself. The view
declares which group it belongs to, without touching the group definition.

<CodeGroup>

```yaml title="YAML"
views:
- name: revenue
view_group: sales
cubes:
- join_path: order_items
includes:
- total_sale_price
- created_at
```

```javascript title="JavaScript"
view(`revenue`, {
view_group: sales,
cubes: [
{
join_path: order_items,
includes: [`total_sale_price`, `created_at`]
}
]
})
```

</CodeGroup>

### Belonging to multiple groups

A view can belong to more than one group. Use
[`view_groups`][ref-view-view-groups] (plural) on the view to list every
group it should appear in.

<CodeGroup>

```yaml title="YAML"
views:
- name: revenue
view_groups:
- sales
- finance
cubes:
- join_path: order_items
includes:
- total_sale_price
- created_at
```

```javascript title="JavaScript"
view(`revenue`, {
view_groups: [sales, finance],
cubes: [
{
join_path: order_items,
includes: [`total_sale_price`, `created_at`]
}
]
})
```

</CodeGroup>
A view can belong to more than one group — list it under the `views`
parameter of every group it should appear in.

## Where view groups live in the model

Expand All @@ -160,6 +89,4 @@ entity and can be split across multiple files as your model grows.
[ref-ai-context]: /docs/data-modeling/ai-context
[ref-view-group-ref]: /reference/data-modeling/view-group
[ref-view-group-views]: /reference/data-modeling/view-group#views
[ref-view-view-group]: /reference/data-modeling/view#view_group
[ref-view-view-groups]: /reference/data-modeling/view#view_groups
[ref-meta-endpoint]: /reference/core-data-apis/rest-api/reference
32 changes: 7 additions & 25 deletions docs-mintlify/reference/data-modeling/view-group.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ view_group(`sales`, {

### `views`

A list of view names that belong to this group. Views listed here are
merged with any views that reference this group via their own
[`view_group`][ref-view-view-group] or
[`view_groups`][ref-view-view-groups] parameter.
A list of view names that belong to this group.

<CodeGroup>

Expand All @@ -108,22 +105,14 @@ view_group(`sales`, {

## Assigning views to groups

There are two complementary ways to associate a view with a view group:

1. **On the view group** — list view names in the [`views`](#views) parameter.
2. **On the view** — set [`view_group`][ref-view-view-group] (singular) or
[`view_groups`][ref-view-view-groups] (plural) on the view itself.

Both approaches can be combined. Cube merges the membership from all
sources, so a view listed under a group's `views` *and* referencing that
group via `view_group` will appear only once.
To associate a view with a view group, list its name in the
[`views`](#views) parameter on the view group.

### Example

The following model defines two view groups. The `sales` group lists
`orders_overview` in its `views` parameter; `revenue` joins the same
group via its own `view_group` property. The `customers_view` belongs to
`people` through the group-level `views` list.
`orders_overview` and `revenue` in its `views` parameter, while the
`people` group lists `customers_view`.

<CodeGroup>

Expand Down Expand Up @@ -182,7 +171,6 @@ views:
- created_at

- name: revenue
view_group: sales
cubes:
- join_path: order_items
includes:
Expand All @@ -200,6 +188,7 @@ view_groups:
description: Revenue and order views for the sales team
views:
- orders_overview
- revenue

- name: people
title: People
Expand Down Expand Up @@ -280,7 +269,6 @@ view(`orders_overview`, {
})

view(`revenue`, {
view_group: sales,
cubes: [
{
join_path: order_items,
Expand All @@ -304,7 +292,7 @@ view(`customers_view`, {
view_group(`sales`, {
title: `Sales`,
description: `Revenue and order views for the sales team`,
views: [`orders_overview`]
views: [`orders_overview`, `revenue`]
})

view_group(`people`, {
Expand Down Expand Up @@ -337,12 +325,6 @@ With this model, the `/v1/meta` response includes a `viewGroups` array:
}
```

Notice that `revenue` appears in the `sales` group even though it was not
listed in the group's `views` — it was added because the view itself set
`view_group: sales`.

[ref-views]: /docs/data-modeling/views
[ref-naming]: /docs/data-modeling/concepts/syntax#naming
[ref-meta-endpoint]: /reference/core-data-apis/rest-api/reference
[ref-view-view-group]: /reference/data-modeling/view#view_group
[ref-view-view-groups]: /reference/data-modeling/view#view_groups
69 changes: 1 addition & 68 deletions docs-mintlify/reference/data-modeling/view.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -230,72 +230,6 @@ view(`active_users`, {

</CodeGroup>

### `view_group`

Assigns this view to a single [view group][ref-ref-view-group]. The referenced
view group must be defined with `view_group()` elsewhere in the data model.

<CodeGroup>

```yaml title="YAML"
views:
- name: revenue
view_group: sales
cubes:
- join_path: order_items
includes: "*"
```

```javascript title="JavaScript"
view(`revenue`, {
view_group: sales,
cubes: [
{
join_path: order_items,
includes: `*`
}
]
})
```

</CodeGroup>

### `view_groups`

Assigns this view to multiple [view groups][ref-ref-view-group] at once.
Each referenced view group must be defined with `view_group()` elsewhere
in the data model.

<CodeGroup>

```yaml title="YAML"
views:
- name: revenue
view_groups:
- sales
- finance
cubes:
- join_path: order_items
includes: "*"
```

```javascript title="JavaScript"
view(`revenue`, {
view_groups: [`sales`, `finance`],
cubes: [
{
join_path: order_items,
includes: `*`
}
]
})
```

</CodeGroup>

You can use both `view_group` and `view_groups` on the same view. Cube
merges them and removes duplicates.

### `cubes`

Use `cubes` parameter in view to include exposed cubes in bulk. You can build
Expand Down Expand Up @@ -731,5 +665,4 @@ The `access_policy` parameter is used to configure [access policies][ref-ref-dap
[ref-dim-title]: /reference/data-modeling/dimensions#title
[ref-dim-description]: /reference/data-modeling/dimensions#description
[ref-dim-format]: /reference/data-modeling/dimensions#format
[ref-dim-meta]: /reference/data-modeling/dimensions#meta
[ref-ref-view-group]: /reference/data-modeling/view-group
[ref-dim-meta]: /reference/data-modeling/dimensions#meta
5 changes: 0 additions & 5 deletions packages/cubejs-api-gateway/src/types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export type DBResponsePrimitive =
number |
string;

export type DBResponseValue =
Date |
DBResponsePrimitive |
{ value: DBResponsePrimitive };

export type TransformDataResponse = {
members: string[],
dataset: DBResponsePrimitive[][]
Expand Down
5 changes: 2 additions & 3 deletions packages/cubejs-backend-native/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::node_obj_deserializer::JsValueDeserializer;
use crate::transport::MapCubeErrExt;
use cubeorchestrator::query_message_parser::QueryResult;
use cubeorchestrator::query_result_transform::{
DBResponsePrimitive, DBResponseValue, RequestResultData, RequestResultDataMulti,
TransformedData,
DBResponsePrimitive, RequestResultData, RequestResultDataMulti, TransformedData,
};
use cubeorchestrator::transport::{JsRawColumnarData, TransformDataRequest};
use cubesql::compile::engine::df::scan::{ColumnarValueObject, FieldValue, ValueObject};
Expand Down Expand Up @@ -339,7 +338,7 @@ pub fn get_cubestore_result(mut cx: FunctionContext) -> JsResult<JsValue> {
for (key, value) in result.members.iter().zip(row.iter()) {
let js_key = cx.string(key);
let js_value: Handle<'_, JsValue> = match value {
DBResponseValue::Primitive(DBResponsePrimitive::Null) => cx.null().upcast(),
DBResponsePrimitive::Null => cx.null().upcast(),
// For compatibility, we convert all primitives to strings
other => cx.string(other.to_string()).upcast(),
};
Expand Down
17 changes: 6 additions & 11 deletions rust/cube/cubeorchestrator/src/query_message_parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
query_result_transform::{DBResponsePrimitive, DBResponseValue},
transport::JsRawColumnarData,
};
use crate::{query_result_transform::DBResponsePrimitive, transport::JsRawColumnarData};
use cubeshared::codegen::{root_as_http_message_with_opts, HttpCommand};
use cubeshared::flatbuffers::VerifierOptions;
use indexmap::IndexMap;
Expand Down Expand Up @@ -35,7 +32,7 @@ impl std::error::Error for ParseError {}
#[derive(Debug, Clone)]
pub struct QueryResult {
pub members: Vec<String>,
pub rows: Vec<Vec<DBResponseValue>>,
pub rows: Vec<Vec<DBResponsePrimitive>>,
pub columns_pos: IndexMap<String, usize>,
}

Expand Down Expand Up @@ -96,10 +93,8 @@ impl QueryResult {
let row_obj: Vec<_> = values
.iter()
.map(|val| match val.string_value() {
Some(s) => DBResponseValue::Primitive(DBResponsePrimitive::String(
s.to_owned(),
)),
None => DBResponseValue::Primitive(DBResponsePrimitive::Null),
Some(s) => DBResponsePrimitive::String(s.to_owned()),
None => DBResponsePrimitive::Null,
})
.collect();

Expand Down Expand Up @@ -134,14 +129,14 @@ impl QueryResult {
// Transpose column-major input into the row-major shape `QueryResult`
// expects. Rows are pre-allocated, then we drain each column into the
// matching slot to avoid per-cell clones.
let mut rows: Vec<Vec<DBResponseValue>> = (0..row_count)
let mut rows: Vec<Vec<DBResponsePrimitive>> = (0..row_count)
.map(|_| Vec::with_capacity(members.len()))
.collect();

for column in columns.into_iter() {
for (row_idx, value) in column.into_iter().enumerate() {
if let Some(row) = rows.get_mut(row_idx) {
row.push(DBResponseValue::Primitive(value));
row.push(value);
}
}
}
Expand Down
Loading
Loading