Skip to content

Commit 12f3880

Browse files
author
Andy Hattemer
committed
update readme
1 parent c911d15 commit 12f3880

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ You'll need to have [docker and docker-compose installed](https://materialize.co
3737
```shell session
3838
psql -h localhost -p 6875 -U materialize -f materialize/create.sql
3939
```
40+
41+
5. There is a basic cube schema already drafted for a "Vendors" aggregation in `cube/schema/Vendors.js`
42+
a. Test out building a query with it in the Cube.JS Dev Playground at `localhost:4000`
43+
44+
b. Test curling the query to see how the REST API works
45+
46+
c. You can test the GraphQL API using the dev playground
47+
48+
d. Test adding Auth to limit what data each vendor can read.
49+
50+
e. Try adding a pre-aggregation with a `1 second` cache expiration. This effectively tells Cube Store to cache the view on every query, if Materialize goes down it will continue to serve the last state of the view!

cube/schema/Vendors.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ cube(`Vendors`, {
22
refreshKey: {
33
every: `1 second`
44
},
5-
65
sql: `SELECT * FROM public.agg_vendors_minute`,
76
measures: {
87
count: {
@@ -30,7 +29,7 @@ cube(`Vendors`, {
3029
type: `number`,
3130
sql: `SUM(orders)/SUM(pageviews)+1`,
3231
format: `percent`
33-
},
32+
}
3433
},
3534
dimensions: {
3635
id: {
@@ -47,4 +46,13 @@ cube(`Vendors`, {
4746
}
4847
},
4948
dataSource: `default`,
50-
});
49+
preAggregations: {
50+
main: {
51+
measures: [Vendors.totalRevenue, Vendors.totalOrders, Vendors.totalPageviews, Vendors.totalItemsSold],
52+
dimensions: [Vendors.name, Vendors.id, Vendors.receivedAtMinute],
53+
refreshKey: {
54+
every: `1 day`,
55+
}
56+
}
57+
}
58+
});

materialize/create.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CREATE MATERIALIZED VIEW agg_vendors_minute AS
5353
SELECT
5454
vendors.id as vendor_id,
5555
vendors.name as vendor_name,
56-
minute_series.m,
56+
minute_series.m::timestamp,
5757
SUM(purchases.quantity) as items_sold,
5858
COUNT(purchases.id) as orders,
5959
SUM(purchases.purchase_price) as revenue,

materialize/drop.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
DROP SOURCE purchases CASCADE;
22
DROP SOURCE items CASCADE;
33
DROP SOURCE users CASCADE;
4+
DROP SOURCE vendors CASCADE;
45
DROP SOURCE json_pageviews CASCADE;

0 commit comments

Comments
 (0)