尝试在OrientDB中展开两个或多个阵列

尝试在OrientDB中展开两个或多个阵列,orientdb,Orientdb,我正在使用OrientDB的UI/Query工具来分析一些图形数据,我花了几天时间试图解开两个数组,但都没有成功 unwind子句对于一个数组来说效果很好,但在尝试解开两个数组时,我似乎无法获得所需的输出 以下是我的数据的简化示例: @class | amt | storeID | customerID transaction $4 1 1 transaction $2 1 1 transactio

我正在使用OrientDB的UI/Query工具来分析一些图形数据,我花了几天时间试图解开两个数组,但都没有成功

unwind子句对于一个数组来说效果很好,但在尝试解开两个数组时,我似乎无法获得所需的输出

以下是我的数据的简化示例:

@class       |  amt  | storeID  | customerID  
transaction     $4        1         1
transaction     $2        1         1
transaction     $6        1         4
transaction     $3        1         4
transaction     $2        2         1
transaction     $7        2         1
transaction     $8        2         2
transaction     $3        2         2
transaction     $4        2         3
transaction     $9        2         3
transaction     $10       3         4
transaction     $3        3         4
transaction     $4        3         5
transaction     $10       3         5
每个客户都是包含以下信息的文档:

@class   | customerID | State 
customer     1             NY  
customer     2             NJ  
customer     3             PA
customer     4             NY  
customer     5             NY
@class   | storeID | State |   Zip 
store         1         NY     1 
store         2         NJ     3    
store         3         NY     2    
每个门店都是包含以下信息的文档:

@class   | customerID | State 
customer     1             NY  
customer     2             NJ  
customer     3             PA
customer     4             NY  
customer     5             NY
@class   | storeID | State |   Zip 
store         1         NY     1 
store         2         NJ     3    
store         3         NY     2    
假设我没有storeID(也不想创建它),我想恢复一个具有以下不同值的扁平表:商店名称、城市、账号和花费的总金额

该查询有望生成类似下表的内容(对于给定的深度值)

我尝试了各种展开/展平/展开操作,但似乎无法使查询正常工作

以下是我的查询,它将State和Zip恢复为两个数组,并展平customerID:

SELECT  out().State as State, 
        out().Zip as Zip, 
        customerID 
    FROM ( SELECT EXPAND(IN()) 
            FROM (TRAVERSE * FROM 
                ( SELECT FROM transaction) 
        ) 
    ) ;
这就产生了

State            |   Zip     | customerID 
[NY, NY, NJ, NJ]   [1,1,2,2]       1   
[NY, NY, NJ, NJ]   [1,1,2,2]       1   
[NY, NY, PA, PA]   [1,1,3,3]       4
[NY, NY, PA, PA]   [1,1,3,3]       4
...                   ....      ....

这不是我要找的。有人能帮我把这两个阵列放平/放平吗

我用这种结构尝试了你的案例(基于你的例子):

我使用此查询检索State、Zip和customerID(不是数组):

  • 查询1

    SELECT State, Zip, in('transaction').customerID AS customerID FROM Store 
    ORDER BY Zip UNWIND customerID
    
    ----+------+-----+----+----------
    #   |@CLASS|State|Zip |customerID
    ----+------+-----+----+----------
    0   |null  |NY   |1   |1
    1   |null  |NY   |1   |1
    2   |null  |NY   |1   |4
    3   |null  |NY   |1   |4
    4   |null  |NY   |2   |4
    5   |null  |NY   |2   |4
    6   |null  |NY   |2   |5
    7   |null  |NY   |2   |5
    8   |null  |NJ   |3   |1
    9   |null  |NJ   |3   |1
    10  |null  |NJ   |3   |2
    11  |null  |NJ   |3   |2
    12  |null  |NJ   |3   |3
    13  |null  |NJ   |3   |3
    ----+------+-----+----+----------
    
    SELECT inV('transaction').State AS State, inV('transaction').Zip AS Zip, 
    outV('transaction').customerID AS customerID FROM transaction ORDER BY Zip
    
    ----+------+-----+----+----------
    #   |@CLASS|State|Zip |customerID
    ----+------+-----+----+----------
    0   |null  |NY   |1   |1
    1   |null  |NY   |1   |1
    2   |null  |NY   |1   |4
    3   |null  |NY   |1   |4
    4   |null  |NY   |2   |4
    5   |null  |NY   |2   |4
    6   |null  |NY   |2   |5
    7   |null  |NY   |2   |5
    8   |null  |NJ   |3   |1
    9   |null  |NJ   |3   |1
    10  |null  |NJ   |3   |2
    11  |null  |NJ   |3   |2
    12  |null  |NJ   |3   |3
    13  |null  |NJ   |3   |3
    ----+------+-----+----+----------
    
  • 查询2

    SELECT State, Zip, in('transaction').customerID AS customerID FROM Store 
    ORDER BY Zip UNWIND customerID
    
    ----+------+-----+----+----------
    #   |@CLASS|State|Zip |customerID
    ----+------+-----+----+----------
    0   |null  |NY   |1   |1
    1   |null  |NY   |1   |1
    2   |null  |NY   |1   |4
    3   |null  |NY   |1   |4
    4   |null  |NY   |2   |4
    5   |null  |NY   |2   |4
    6   |null  |NY   |2   |5
    7   |null  |NY   |2   |5
    8   |null  |NJ   |3   |1
    9   |null  |NJ   |3   |1
    10  |null  |NJ   |3   |2
    11  |null  |NJ   |3   |2
    12  |null  |NJ   |3   |3
    13  |null  |NJ   |3   |3
    ----+------+-----+----+----------
    
    SELECT inV('transaction').State AS State, inV('transaction').Zip AS Zip, 
    outV('transaction').customerID AS customerID FROM transaction ORDER BY Zip
    
    ----+------+-----+----+----------
    #   |@CLASS|State|Zip |customerID
    ----+------+-----+----+----------
    0   |null  |NY   |1   |1
    1   |null  |NY   |1   |1
    2   |null  |NY   |1   |4
    3   |null  |NY   |1   |4
    4   |null  |NY   |2   |4
    5   |null  |NY   |2   |4
    6   |null  |NY   |2   |5
    7   |null  |NY   |2   |5
    8   |null  |NJ   |3   |1
    9   |null  |NJ   |3   |1
    10  |null  |NJ   |3   |2
    11  |null  |NJ   |3   |2
    12  |null  |NJ   |3   |3
    13  |null  |NJ   |3   |3
    ----+------+-----+----+----------
    
  • 已编辑

    在以下示例中,通过查询,您将能够检索每个
    storeID
    (基于每个
    customerID
    )的平均花费和总花费:


    希望它能有所帮助

    很抱歉,我不理解您的用例:您使用诸如
    in()
    out()
    之类的函数,但我看不到图形类型的用法(顶点和边)。对我来说,您像文档数据库一样使用。如果你能分享你的数据库的一个小出口,我就可以测试它了。Thx@IvanMainetti事务是客户节点和商店节点之间的边缘。这更清楚吗?你好,Francisco,您的图表应该具有类似于此的结构<代码>客户--<代码>交易--><代码>状态对吗
    amt
    是指定交易值的edge属性吗?嗨,Francisco,关于您要查找的查询,哪些是您要检索的对应字段?差不多<代码>门店名称-->门店ID,城市-->字段?(可能是Store.State?)从哪个表?、账号-->字段?、花费总额-->每个商店或每个客户的总和?@LucaS是的,完全正确。我只想检索State、Zip和CustomerID(我可以使用),但我真正想做的是解开State和Zip,但我不知道如何在不将CustomerID变成数组的情况下实现……我可以得到State和Zip,但CustomerID变成数组,或者我可以得到CustomerID,然后State和Zip变成数组。不知道怎样才能让这两个都解开/展平。你是个英雄!!非常感谢。你好,弗朗西斯科,谢谢你。答案正确吗?查询正确吗?这太完美了!正是我要找的!作为后续,如果我想遍历它的深度大于零(因为我知道这个查询只返回相邻的节点),我能使用inV()和outV()吗?我现在正在测试,但没有成功。我希望能够返回展开/展开的数据,同时提取更深的客户群(即深度为1或2)。这就是我以前在案例中使用遍历查询的原因…我可以使用这两个查询中的一个吗?你好,Francisco,您可以使用此查询尝试
    遍历
    最大深度
    :例如,检索连接到
    存储ID
    =2-->
    选择customerID作为customerID的所有
    customerID(在('transaction')FROM(从storeID=2的存储中选择)MAXDEPTH 2)WHERE@class'store'
    ---->
    customerIDs=1,2,3