orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

New EXPAND operator to extract Master/Details info [moved]

Open lvca opened this issue 13 years ago • 4 comments

This is Issue 551 moved from a Google Code project. Added by 2011-09-30T11:53:44.000Z by [email protected]. Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium, v2.0.0

Original description

When we have two classes linked togheter in a "master / detail" relationship it would be useful to have a new operator to extract Mater/Details info.

For example, having:

> load record #6:1
--------------------------------------------------
ODocument - Class: LemmaStem   id: #6:1   v.2
--------------------------------------------------
                stem : mangi            
               lemma : Lemma#5:1{normalForm:mangiare,lexSymbol:mangiare_v,lexCat:V,lexFeatures:[2]} v0
        flexSuffixes : [#7:1, #7:2]        


> load record #7:1
--------------------------------------------------
ODocument - Class: FlexSuffix   id: #7:1   v.0
--------------------------------------------------
              suffix : a                   
          morphFeats : [INDIC, PRES, THIRD, SING]


> load record #7:2
--------------------------------------------------
ODocument - Class: FlexSuffix   id: #7:2   v.1
--------------------------------------------------
              suffix : amo                 
          morphFeats : [INDIC, CONGIUNT, PRES, FIRST, PLU]


we would like to get a result similar to a master/detail JOIN in a RDBMS:
*stem*         *normalForm*          *suffix*         *flexForm*
mangi           mangiare                a               mangia
mangi           mangiare                amo             mangiamo


The proposal is to have a new EXPAND operator to achieve this result.

Something like:
SELECT stem, lemma.normalForm AS normalForm, EXPAND( flexSuffixes.suffix ) AS suffix, stem.append(suffix) AS flexForm FROM LemmaStem

lvca avatar Dec 10 '12 15:12 lvca

Hi Luca,

You mentioned [see https://code.google.com/p/orient/issues/detail?id=551] that the functionality mentioned above it could be achieved with multiple SELECT, LET statements. Could you drop a few lines as an example to start?

Regards, Dan.

dm-ordb avatar Mar 06 '13 16:03 dm-ordb

Can you describe your domain in short and what you want?

lvca avatar Mar 06 '13 16:03 lvca

OK, here is the example:

I have run the following script create class master create class detail

insert into master set data = { "id" : 1, "detailID": [1,2], "masterdata": "m1" } insert into master set data = { "id" : 2, "detailID": [3,4], "masterdata": "m2" }

insert into detail set data = { "id" : 1, "detaildata": "d11" } insert into detail set data = { "id" : 2, "detaildata": "d12" } insert into detail set data = { "id" : 3, "detaildata": "d21" }
insert into detail set data = { "id" : 4, "detaildata": "d22" }

And I got the correct database content. Then I run master-detail query (to combine master-detail info together) like this:

select data.id as masterID, data.masterdata as masterdata, $detailID.asString() as detailDataStr, $detailID.data.id as detailID, $detailID.data.detaildata as detaildata from master let $detailID = (select data from detail where data.id in $parent.$current.data.detailID) where $detailID.data.detaildata contains "d12"

I works fine and results in: masterID masterdata detailID detaildata 1 m1 1,2 d12,d11

Question: Is there a way to produce the following results set? masterID masterdata detailID detaildata 1 m1 1 d11 1 m1 2 d12

You mentioned that it could be possible with multiple/nested SELECT, LET statements [see https://code.google.com/p/orient/issues/detail?id=551] and EXPAND operator is not needed to achieve that. Could you drop a line how to modify the query to achieve that?

Regards, Daniel

dm-ordb avatar Mar 06 '13 17:03 dm-ordb

implemented UNWIND operator, see http://orientdb.com/docs/last/SQL-Query.html#unwind

luigidellaquila avatar May 29 '15 12:05 luigidellaquila