Frage

I have a document in my OrientDB database (version 1.0.1), with a structure largely like this:

{
    "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"
        }
    ]
}

How can I query across the entire list, eg. if I want to find all documents that contain a testcase with the type "ignore"?

I've attempted the following query

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

but this results in a NumberFormatException.

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

works, but obviously only looks at the first list element of each document.

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

Doesn't provide any results, but the query is accepted as valid.

Update: The following query works as intended, if the testcases are stored as separate documents instead of as an embedded list.

select from testresult where testcases contains (type = 'ignore')
War es hilfreich?

Lösung

I know it's an old question but I had the same problem and just stubled upon an answer here: https://www.mail-archive.com/orient-database@googlegroups.com/msg00662.html

The following should work. It does in my very similiar use case.

select from testresult where 'ignore' in testcases.type

Andere Tipps

I have similar problem and end up with :

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

this will give you all the testresult documents that contains at least one testcase which type is ignore. This query works on embedded lists. Take care that expand function is available in OrientDB >= 1.4.0.

The inner query :

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

select only the different testcases with a type = 'ignore'. The result are testcases. To have the whole document we match those testcases with the ones contained in each document (testcases in $tmp.value).

I don't know if there is a simpler way to query embedded list...

Try

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

Check the traverse operator ( https://groups.google.com/forum/?fromgroups#!topic/orient-database/zoBGmIg85o4 ) to know how to use the fetchplan or put any() instead of testcases just after "where".

For example we have a class called Country which has an embeddedlist property with some of its isoCodes. If we attempt the following query :

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

Orientdb Rest interface provides :

{
  "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"
      }]
    }
  ]
}

Hope it helps!!.

Regards.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top