Back to Cube

Playground

docs/content/product/exploration/playground.mdx

1.6.438.5 KB
Original Source

Playground

Playground is a web-based tool that helps validate the data model by executing queries and previewing their results. It is supposed to be used by data engineers and developers while building the data model. If you'd like to let end users query the data, connect a BI tool or use the JavaScript SDKs to build your own query builder.

<InfoBox>

We recommend to migrate over to Explore and Workbooks for data analysis in exploration in Cube cloud platform.

Playground is available in Cube Core at localhost:4000 when it's run in the development mode.

</InfoBox>

You can view the data model entities or search for them, compose a query from scratch or paste an exsiting query, view results, check a generated query, or copy equivalent queries for data APIs.

Viewing the data model

You can see a list of all cubes or views in the sidebar on the left. Choose either <Btn>Cubes</Btn> or <Btn>Views</Btn> to switch between cubes and views and click on a cube or a view to view a list of its members.

<Screenshot highlight="inset(7.5% 74% 1% 4% round 10px)" src="https://ucarecdn.com/08d5cc69-431d-43d9-8da4-804029adf1fa/" />

Members of cubes and views (i.e., measures, dimensions, hierarchies, folders, etc.) are shown using distinct colors and icons. If a member has a title or a description set in the data model, they will be shown in a tooltip. If a member is not public, you will see a lock sign next to it.

<InfoBox>

Even if a cube, a view, or their member is not public, Playground would still allow you to query and validate it.

</InfoBox>

Switching the security context

You can click on the <Btn>Security Context</Btn> button in the top right corner to change the security context. Changing the security context can affect the contents of the sidebar that you see:

<Screenshot src="https://ucarecdn.com/1a0721e8-8f7c-44ce-ad02-d688721a73f1/" />

Searching the data model

You can search for cubes, views, and their members using the search bar in the sidebar on the left. Click on the element in the search results to add it to a new or existing query.

<Screenshot highlight="inset(7.5% 74% 1% 4% round 10px)" src="https://ucarecdn.com/c9e3a8e5-d9f5-4a15-82c1-859bbebd8493/" />

Composing queries

You can compose a new query by selecting desired measures, dimensions, and segments in the sidebar on the left. Click on the funnel icon next to any member to add a filter for it to the query or use the <Btn>Filters</Btn> pane to add filters, including filters with advanced boolean logic.

Click <Btn>All members</Btn> or <Btn>Used members</Btn> to show only members of the query or all available members. Click <Btn>Reset</Btn> to remove all members from the query.

<Screenshot highlight="inset(7.5% 74% 1% 4% round 10px)" src="https://ucarecdn.com/1f052da4-1e7d-46c0-98b5-616eabbaa128/" />

Use the <Btn>Order</Btn> drop-down on the right to specify how the results shall be sorted.

<Screenshot highlight="inset(35% 9% 15% 64% round 10px)" src="https://ucarecdn.com/82719c33-8881-42c6-9353-acd2e678014b/" />

Use the <Btn>Options</Btn> drop-down on the right to specify if the query shall be ungrouped, to set a time zone, or to set a row limit and an offset. You can also request the count of all rows in the result set as if there's no limit present.

<Screenshot highlight="inset(35% 0 15% 80% round 10px)" src="https://ucarecdn.com/92dac6aa-f260-4ee3-9065-f1b29fe0d99f/" />

Pasting a query

You can also compose a new query by clicking on the pencil button in the sidebar on the left and pasting a REST API query or a GraphQL API query from the clipboard and clicking <Btn>Apply</Btn>.

<Screenshot src="https://ucarecdn.com/d34949a1-40a7-4cb5-b180-efa63f94b201/" />

Pasting a SQL API query is not supported.

Using query tabs

You can use query tabs to keep results of previous queries while still being able to make new queries. Previous queries are kept in the local storage in your browser and will be restored when you open Playground once again.

You can also double-click on a query tab to give it a meaningful name.

Saving a report

You can save a query to a view by clicking <Btn>Save Report</Btn> in the top right corner.

<Screenshot src="https://ucarecdn.com/c4865552-59ab-4d20-bd7d-5310be07e16c/" highlight="inset(6% 0 88% 91% round 10px)" />

You can manage saved reports in the <Btn>Saved Reports</Btn> page.

Viewing results

Click <Btn>Run Query</Btn> on the top to run (or re-run) the query and check the querying time in the top right corner. Click on the querying time to create a pre-aggregation to accelerate the query.

View query results on the <Btn>Results</Btn> tab. Check the number of rows in the result set on the bottom and use the pagination control in the bottom right corner, if needed.

<Screenshot highlight="inset(7.5% 0 0 26% round 10px)" src="https://ucarecdn.com/399016dc-06de-4652-a86f-ca98f944725e/" />

Expand the <Btn>Chart</Btn> pane to visualize the results. Choose one of visualization types and pivot data via the <Btn>Pivot</Btn> drop-down, if needed. Click <Btn>Code</Btn> to generate front-end code in Chart Prototyping.

<Screenshot highlight="inset(7.5% 0 0 26% round 10px)" src="https://ucarecdn.com/368ceb39-c3b9-45c4-8a7a-873cee571d69/" />

Viewing a generated query

View the SQL query that Cube did (or will) run against the data source to get the results on the <Btn>Generated SQL</Btn> tab. Click <Btn>Copy</Btn> to put it into your clipboard.

<Screenshot highlight="inset(7.5% 0 0 26% round 10px)" src="https://ucarecdn.com/d2b6e514-9219-49ea-bae6-bcd0f1936542/" />

<InfoBox>

Note that a generated query can contain placeholders, e.g., ? or $1, for parameters that Cube passes to an underlying data source driver later when executing the query.

</InfoBox>

Copying API queries

View the queries for respective data APIs on the <Btn>SQL API</Btn>, <Btn>REST API</Btn>, and <Btn>GraphQL API</Btn> tabs. Click <Btn>Copy</Btn> to put one of them into your clipboard.

<Screenshot highlight="inset(7.5% 0 0 26% round 10px)" src="https://ucarecdn.com/1b32fe0d-9a2a-4251-a650-6226a3006e86/" />

{/*

You can use this Playground to view and generate data model files.

<WarningBox>

Data model generator currently has the following limitations:

  • Even if multiple data sources are configured, it will only show the tables from in default data source. As a workaround, you can configure the second data source as default, generate data model files for it, then change the default data source back.
  • With each generation, files in the data model folder will be rewritten. If you'd like to combine files from multiple generations, please back them up manually.
</WarningBox>

*/}