Aggregate volume with irregular product hierarchy in arangodb AQL
up vote
0
down vote
favorite
I would like to aggregate invoice volume up the product hierarchy. However, the hierarchy does not have the same number of levels for all products. For example the following are the hierarchies of two products:
Prod1 (SKU) <- Hierarchy Level (HL) 5 <- HL 4 <- HL 3 <- HL 2 <- HL 1
Prod2 (SKU) <- HL 3 <- HL 2 <- HL 1
All products have level 3 and above, but may have multiple levels between level 3 and sku (Hierarchy can have up to 8 levels total including sku).
The current DB model for the invoices looks like this:
Customer <-IsBilled-- Invoice --containsProd-> product <- IsParentOf-- product
The following query does the aggregation nicely, but it relies in a fixed number of edge hops
for v,e,p in 1..4 INBOUND 'customer/A'
IsBilled, OUTBOUND containsProd, isParentOf
filter p.edges[0]._from == 'invoice/541280' //limit data to a single invoice
collect vname = p.vertices[4].name, vlevel = p.vertices[4].hierarchyLevel
AGGREGATE qtySum = sum( p.edges[1].quantity ) //aggregates two levels up in the product hierarchy (hops 1 and 2 get from customer to invoice to product)
filter vname != null. //remove vertices that are not products
return Product: vname, hierarchyLevel: vlevel, qty:qtySum
The statement above gets data like:
Product hierarchyLevel qty
PrdA HL 4 20
PrdB HL 2 30
Is it possible instead to get the data at level 3 for all products (since that is a common level)? I am guessing there would need to be a change to the aggregation logic, but not sure how.
arangodb aql
add a comment |
up vote
0
down vote
favorite
I would like to aggregate invoice volume up the product hierarchy. However, the hierarchy does not have the same number of levels for all products. For example the following are the hierarchies of two products:
Prod1 (SKU) <- Hierarchy Level (HL) 5 <- HL 4 <- HL 3 <- HL 2 <- HL 1
Prod2 (SKU) <- HL 3 <- HL 2 <- HL 1
All products have level 3 and above, but may have multiple levels between level 3 and sku (Hierarchy can have up to 8 levels total including sku).
The current DB model for the invoices looks like this:
Customer <-IsBilled-- Invoice --containsProd-> product <- IsParentOf-- product
The following query does the aggregation nicely, but it relies in a fixed number of edge hops
for v,e,p in 1..4 INBOUND 'customer/A'
IsBilled, OUTBOUND containsProd, isParentOf
filter p.edges[0]._from == 'invoice/541280' //limit data to a single invoice
collect vname = p.vertices[4].name, vlevel = p.vertices[4].hierarchyLevel
AGGREGATE qtySum = sum( p.edges[1].quantity ) //aggregates two levels up in the product hierarchy (hops 1 and 2 get from customer to invoice to product)
filter vname != null. //remove vertices that are not products
return Product: vname, hierarchyLevel: vlevel, qty:qtySum
The statement above gets data like:
Product hierarchyLevel qty
PrdA HL 4 20
PrdB HL 2 30
Is it possible instead to get the data at level 3 for all products (since that is a common level)? I am guessing there would need to be a change to the aggregation logic, but not sure how.
arangodb aql
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I would like to aggregate invoice volume up the product hierarchy. However, the hierarchy does not have the same number of levels for all products. For example the following are the hierarchies of two products:
Prod1 (SKU) <- Hierarchy Level (HL) 5 <- HL 4 <- HL 3 <- HL 2 <- HL 1
Prod2 (SKU) <- HL 3 <- HL 2 <- HL 1
All products have level 3 and above, but may have multiple levels between level 3 and sku (Hierarchy can have up to 8 levels total including sku).
The current DB model for the invoices looks like this:
Customer <-IsBilled-- Invoice --containsProd-> product <- IsParentOf-- product
The following query does the aggregation nicely, but it relies in a fixed number of edge hops
for v,e,p in 1..4 INBOUND 'customer/A'
IsBilled, OUTBOUND containsProd, isParentOf
filter p.edges[0]._from == 'invoice/541280' //limit data to a single invoice
collect vname = p.vertices[4].name, vlevel = p.vertices[4].hierarchyLevel
AGGREGATE qtySum = sum( p.edges[1].quantity ) //aggregates two levels up in the product hierarchy (hops 1 and 2 get from customer to invoice to product)
filter vname != null. //remove vertices that are not products
return Product: vname, hierarchyLevel: vlevel, qty:qtySum
The statement above gets data like:
Product hierarchyLevel qty
PrdA HL 4 20
PrdB HL 2 30
Is it possible instead to get the data at level 3 for all products (since that is a common level)? I am guessing there would need to be a change to the aggregation logic, but not sure how.
arangodb aql
I would like to aggregate invoice volume up the product hierarchy. However, the hierarchy does not have the same number of levels for all products. For example the following are the hierarchies of two products:
Prod1 (SKU) <- Hierarchy Level (HL) 5 <- HL 4 <- HL 3 <- HL 2 <- HL 1
Prod2 (SKU) <- HL 3 <- HL 2 <- HL 1
All products have level 3 and above, but may have multiple levels between level 3 and sku (Hierarchy can have up to 8 levels total including sku).
The current DB model for the invoices looks like this:
Customer <-IsBilled-- Invoice --containsProd-> product <- IsParentOf-- product
The following query does the aggregation nicely, but it relies in a fixed number of edge hops
for v,e,p in 1..4 INBOUND 'customer/A'
IsBilled, OUTBOUND containsProd, isParentOf
filter p.edges[0]._from == 'invoice/541280' //limit data to a single invoice
collect vname = p.vertices[4].name, vlevel = p.vertices[4].hierarchyLevel
AGGREGATE qtySum = sum( p.edges[1].quantity ) //aggregates two levels up in the product hierarchy (hops 1 and 2 get from customer to invoice to product)
filter vname != null. //remove vertices that are not products
return Product: vname, hierarchyLevel: vlevel, qty:qtySum
The statement above gets data like:
Product hierarchyLevel qty
PrdA HL 4 20
PrdB HL 2 30
Is it possible instead to get the data at level 3 for all products (since that is a common level)? I am guessing there would need to be a change to the aggregation logic, but not sure how.
arangodb aql
arangodb aql
asked Nov 8 at 22:47
camba1
1296
1296
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217304%2faggregate-volume-with-irregular-product-hierarchy-in-arangodb-aql%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown