【问题标题】:Sorting on _key and filter按 _key 排序并过滤
【发布时间】:2022-08-18 18:22:07
【问题描述】:

我有一个被卡住的要求。下面是需要做的几点。

1: I want to sort on _key field which is system generated (configured as auto increment) and filter them accordingly. Eg: 
SORT users._key DESC
FILTER TO_NUMBER(users._key) > 1999968
The problem here is _key is string and I have to convert _key TO_NUMBER which doesn\'t seems to be a good approach, is there are way to correct it.

FILTER users._key > \'1999968\' is not giving correct results.
2: How to use grouping with views I need to group few records but it shows be error everytime I place COLLECT keyword.
eg: 
for suser in sortedUsers <----- view
SEARCH suser ._to == user._id <------ some searching (not actual code)
SORT suser ._key DESC <----------- sorting
FILTER suser ._key > 1999968 <-------- filtering
COLLECT temp = suser.country <---------- this is sample command not actual
return temp

But my question is where does the collect command goes when we use views.Even DINSTINCT  will work but how to sync it with complex queries that return complex results.

    标签: arangodb arangojs pyarango arangodb-php


    【解决方案1】:

    我遇到了同样的问题。在 Javascript 中,我们看到相同的内容:

    "2" > "13" -> true
    "2" >  13  -> false
     2  > "13" -> false
    

    所以比较数字字符串值是行不通的(因为字符串不是数字)。要比较数字字符串,必须转换为数值。

    我不知道您问题的“答案”,因为它取决于 ArangoDB 所做的优化。但是您可以尝试不同的转换选项,并使用 Web 界面中的 Profile 和 Explain 函数对查询进行基准测试。结果可能会有所不同,具体取决于您执行的确切查询。

    例如:

    FOR d IN CollectionName
      FILTER d._key > 1999968 // implicit conversion to number
      RETURN d
    
    FOR d IN CollectionName
      FILTER d._key - 1999968 > 0 // another implicit conversion to number
      RETURN d
    
    FOR d IN CollectionName
      FILTER +d._key > 1999968 // explicit conversion of key to number
      RETURN d
    
    FOR d IN CollectionName
      FILTER TO_NUMBER(d._key) > 1999968 // use ArangoDB's conversion function
      RETURN d
    

    第一次隐式转换d._key &gt; 1999968 似乎对我很有效

    【讨论】:

      猜你喜欢
      • 2015-11-09
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 2021-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多