2012-07-06 99 views
9

我在我的OrientDB數據庫中的文檔(1.0.1版本),在很大程度上與這樣的結構:查詢嵌入列表OrientDB

{ 
    "timestamp": "...", 
    "duration": 665, 
    "testcases": [ 
     { 
      "testName": "test01", 
      "type": "ignore", 
      "filename": "tests/test1.js" 
     }, 
     { 
      "iterations": 1, 
      "runningTime": 45, 
      "testName": "test02", 
      "type": "pass", 
      "filename": "tests/test1.js" 
     }, 
     ... 
     { 
      "testName": "test05", 
      "type": "ignore", 
      "filename": "tests/test1.js" 
     } 
    ] 
} 

我如何可以查詢整個列表,例如。如果我想查找包含類型爲「忽略」的測試用例的所有文檔?

我已經嘗試下面的查詢

select from testresult where testcases['type'] = 'ignore' 

但這導致NumberFormatException

select from testresult where testcases[0]['type'] = 'ignore' 

的作品,但顯然只看每個文件的第一個列表元素。

select from testresult where testcases contains(type = 'ignore') 

不提供任何結果,但查詢被接受爲有效。

更新: 如果測試用例存儲爲單獨的文檔而不是嵌入式列表,則以下查詢按預期工作。

select from testresult where testcases contains (type = 'ignore') 
+0

我遇到了同樣的問題。您可以在問題中發佈更新並接受它。那正是我正在尋找的。 – 2014-11-05 15:08:04

+0

@DavidLaberge:謝謝你的建議。這個問題太古老了,我坦率地沒有完全記住它的背景,所以我會對這個操作感到有些不安。至少根據OrientDB的文檔,我還有一種感覺,即我的初始方法應該起作用,所以鼓勵人們像上面那樣重新調整數據庫會是一種錯誤。 – Henrik 2014-11-05 18:12:25

回答

0

嘗試

select from testresult where testcases traverse (type = 'ignore') 

檢查導線運營商(https://groups.google.com/forum/?fromgroups#!topic/orient-database/zoBGmIg85o4)知道如何使用fetchplan或只是 「在哪裏」 後提出的任何(),而不是測試用例的。

例如,我們有一個名爲Country的類,它具有一些isoCode的嵌入式列表屬性。如果我們嘗試以下查詢:

select name,description,isoCodes,status from Country where isoCodes traverse (value = 'GB' OR value = 'IT') 

Orientdb REST接口提供:

{ 
    "result": [{ 
     "@type": "d", "@version": 0, 
"name": "Italy", 
    "isoCodes": [ 
    { 
     "@type": "d", "@version": 0, 
    "code": "iso3166-A2", 
    "value": "IT" 
     }, 
    { 
     "@type": "d", "@version": 0, 
    "code": "iso3166-A3", 
    "value": "ITA" 
     }], 
    "status": [ 
    { 
     "@type": "d", "@version": 0, 
    "status": "1", 
    "startingDate": "2012-04-24" 
     }] 
    }, { 
     "@type": "d", "@version": 0, 
"name": "United Kingdom", 
    "isoCodes": [ 
    { 
     "@type": "d", "@version": 0, 
    "code": "iso3166-A2", 
    "value": "GB" 
     }, 
    { 
     "@type": "d", "@version": 0, 
    "code": "iso3166-A3", 
    "value": "GBR" 
     }], 
    "status": [ 
    { 
     "@type": "d", "@version": 0, 
    "status": "1", 
    "startingDate": "2012-04-24" 
     }] 
    } 
    ] 
} 

希望它可以幫助!。

問候。

+1

感謝您的回覆。這不幸並沒有改善我的情況。只要嵌入式列表包含指向其他文檔的鏈接,建議的查詢就可以完美工作,但當列表中的對象只是值時,即不提供結果。當我更新我的問題時,我遇到過同樣的情況。你是否死了 - 確定你的IsoCodes屬性不是數據庫中的單獨文檔? – Henrik 2012-07-12 14:17:50

1

我有類似的問題,結束了:

select * from testresult 
    let $tmp = (select from 
    (select expand(testcases) from testresult) 
    where 
    value.type = 'ignore') 
where 
    testcases in $tmp.value 

這會給你所有包含至少一個測試用例哪種類型忽略的TestResult文件。此查詢適用於嵌入式列表。請注意,OrientDB> = 1.4.0中提供了擴展功能。

內查詢:

select from (select expand(testcases) from testresult) where value.type='ignore' 

僅選擇不同測試用例與類型= '忽略'。結果是測試用例。爲了讓整個文檔與那些包含在每個文檔中的測試用例($ tmp.value中的測試用例)匹配。

我不知道是否有更簡單的方法來查詢嵌入式列表...