table Sizes[size] = with
[| as size, as Weight |]
[| "S", 0.5 |]
[| "M", 0.75 |]
[| "L", 1 |]
[| "XL", 0.75 |]
table Colors[color] = with
[| as color, as Weight |]
[| "white", 1 |]
[| "red", 2 |]
[| "green", 0.5 |]
[| "blue", 0.75 |]
[| "black", 1 |]
table Catalog = with
[| as Size, as Color, as AltColor, as Price |]
[| "S", "red", "blue", 9.99 |]
[| "M", "blue", "white", 10.99 |]
[| "XL", "black", "green", 15.49 |]
expect Catalog.size = Catalog.Size
expect Catalog.color = Catalog.Color
table Variant = cross(Sizes, Colors)
Variant.W = Sizes.Weight * Colors.Weight
// When both dimensions are provided (by name), behaves as a normal lookup.
WhiteLarge = Variant.Weight[size: "L", color: "white"]
Catalog.Alt = Variant.W[size: Catalog.size, color: Catalog.AltColor]
// If a single dimension is provided by name, behavior depends on whether key
// is a scalar or not.
// If scalar, the result is a vector in the other table of the cross-table:
Colors.Small = Variant.W[size: "S"]
Sizes.Blue = Variant.W[color: "blue"]
// If non-scalar, the lookup will automatically look for the other
// dimension in the key's table.
Catalog.Alt = Variant.W[color: Catalog.AltColor] // implicit 'size: Catalog.size'
// Note that if no label is provided, the rightmost dimension is assumed:
Catalog.Alt = Variant.W[Catalog.AltColor] // same as the abvoe
Error message:
Error on line 17, column 18: Catalog.Color
can only be assigned a value with dimension Color
.
Samely, the table in the section Filtered Aggregation
Pid Sold
apple 10
orange -3
banana -2
should have been
Pid Sold
apple 3
orange -2
banana -3
table Orders = with
[| as Pid, as OrderDate, as Quantity |]
[| "apple", date(2020, 4, 15), 3 |]
[| "apple", date(2020, 4, 16), 7 |]
[| "orange", date(2020, 4, 16), 2 |]
table Products = with
[| as Pid, as MyDefault |]
[| "apple", -1 |]
[| "orange", -2 |]
[| "banana", -3 |]
Products.Sold = sum(Orders.Quantity)
when (Orders.OrderDate < date(2020, 4, 16))
default Products.MyDefault
by Orders.Pid
at Products.Pid
show table "Products" with
Products.Pid
Products.Sold
The following code in the section Empty Group
is supposed to be
| Pid | Sold |
| :-------: | :---: |
| apple | 10 |
| orange | 2 |
| banana | -3 |
instead of
| Pid | Sold |
| :-------: | :---: |
| apple | 10 |
| orange | 2 |
| banana | -2 |
table Orders = with
[| as Pid, as OrderDate, as Quantity |]
[| "apple", date(2020, 4, 15), 3 |]
[| "apple", date(2020, 4, 16), 7 |]
[| "orange", date(2020, 4, 16), 2 |]
table Products = with
[| as Pid, as MyDefault |]
[| "apple", -1 |]
[| "orange", -2 |]
[| "banana", -3 |]
Products.Sold = sum(Orders.Quantity)
default Products.MyDefault
by Orders.Pid
at Products.Pid
show table "Products" with
Products.Pid
Products.Sold
The comment in the code
should be