Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First let's fix the model a bit. In your schema you have more attributes per dimension: id and name, you might end up having more details in the future. You can add them by specifying attributes as a list: <code>"attriubtes": ["id", "name"]</code>. Note also that the dimension is named as entity <code>product</code> not as a key <code>id_product</code>. The key <code>id_product</code> is just an attribute of the <code>product</code> dimension, as is <code>name</code> or in the future maybe <code>category</code>. Dimension reflects analysts point of view.</p> <p>For the time being, we ignore the fact that date should be a special dimension and consider date as single-value key, for example a year, not to make things complicated here.</p> <pre class="lang-js prettyprint-override"><code>"dimensions": [ {"name": "user", "attributes": ["id", "name"]}, {"name": "product", "attributes": ["id", "name"]}, {"name": "date"} ], </code></pre> <p>Because we changed names of the dimensions, we have to change them in the cube's dimension list:</p> <pre class="lang-js prettyprint-override"><code>"cubes": [ { "name": "purchases", "dimensions": ["user", "product", "date"], ... </code></pre> <p>Your schema reflects classic transactional schema, not traditional data warehouse schema. In this case, you have to be explicit, as you were, and mention all necessary mappings. The rule is: if the attribute belongs to a fact table (logical view), then the key is just <code>attribute</code>, such as <code>price</code>, no table specification. If the attribute belongs to a dimension, such as <code>product.id</code>, then the syntax is <code>dimension.attribute</code>. The value of the mappings dictionary is physical table and physical column. See <a href="http://packages.python.org/cubes/mapping.html#mapping">more information about mappings</a>. Mappings for your schema look like:</p> <pre class="lang-js prettyprint-override"><code>"mappings": { "price": "products.price", "product.id": "products.id", "product.name": "products.name", "user.id": "users.id", "user.name": "users.name" } </code></pre> <p>You would not have to write mappings if your schema was:</p> <pre><code>fact purchases id | date | user_id | product_id | amount dimension product id | name | price dimension user id | name </code></pre> <p>In this case you will need only joins, because all dimension attributes are in their respective dimension tables. Note the <code>amount</code> in the fact table, which in your case, as you do not have <code>count</code> of purchased products per purchase, would be the same as <code>price</code> in <code>product</code>.</p> <p>Here is the updated model for your model:</p> <pre class="lang-js prettyprint-override"><code>{ "dimensions": [ {"name": "user", "attributes": ["id", "name"]}, {"name": "product", "attributes": ["id", "name"]}, {"name": "date"} ], "cubes": [ { "name": "purchases", "dimensions": ["user", "product", "date"], "measures": ["price"], "mappings": { "price": "products.price", "product.id": "products.id", "product.name": "products.name", "user.id": "users.id", "user.name": "users.name" }, "joins": [ { "master": "purchases.user_id", "detail": "users.id" }, { "master": "purchases.product_id", "detail": "products.id" } ] } ] } </code></pre> <p>You can try the model without writing any Python code, just by using the <a href="http://packages.python.org/cubes/slicer.html"><code>slicer</code></a> command. For that you will need <code>slicer.ini</code> <a href="http://packages.python.org/cubes/server.html#configuration">configuration file</a>:</p> <pre><code>[server] backend: sql port: 5000 log_level: info prettyprint: yes [workspace] url: sqlite:///data.sqlite [model] path: model.json </code></pre> <p>Change <code>url</code> in <code>[workspace]</code> to point to your database and change <code>path</code> in <code>[model]</code> to point to your model file. Now you can try:</p> <pre><code>curl "http://localhost:5000/aggregate" </code></pre> <p>Also try to drill-down:</p> <pre><code>curl "http://localhost:5000/aggregate?drilldown=product" </code></pre> <p>If you need any further help, just let me know, I'm the Cubes author.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload