2

with one joinFieldName and lookup the Edge transformer works perfect. However, now two keys is required, i.e. compound index in the lookup. How can two joinFieldNames be specified?

This is the scripted(post processing) version: Create edge Expands from (select from MC where sample=1 and mkey=6) to (select from Event where sample=1 and mcl=6).

This works, but is not suitable for production.

Can anyone help?

1 Answers1

3

you can simply add 2 joinFieldName(s) like

{ "edge": { "class": "Conn",
                "joinFieldName": "b1",
                "lookup": "A.a1",
                "joinFieldName": "b2",
                "lookup": "A.a2",
                "direction": "out"
            }}

see below my test data:

json1.json

{
  "source": { "file": { "path": "/home/ivan/Scrivania/cose/etl/stak39517796/data1.csv" } },
  "extractor": { "csv": {} },
  "transformers": [
    { "vertex": { "class": "A" } }
  ],
  "loader": {
    "orientdb": {
       "dbURL": "plocal:/home/ivan/OrientDB/db_installati/enterprise/orientdb-enterprise-2.2.10/databases/stack39517796",
       "dbType": "graph",
       "dbAutoCreate": true,
       "classes": [
         {"name": "A", "extends": "V"},
         {"name": "B", "extends": "V"},
         {"name": "Conn", "extends": "E"}
       ]
    }
  }
}

json2.json

{
  "source": { "file": { "path": "/home/ivan/Scrivania/cose/etl/stak39517796/data2.csv" } },
  "extractor": { "csv": {} },
  "transformers": [
    { "vertex": { "class": "B" } },
    { "edge": { "class": "Conn",
                "joinFieldName": "b1",
                "lookup": "A.a1",
                "joinFieldName": "b2",
                "lookup": "A.a2",
                "direction": "out"
            }}
  ],
  "loader": {
    "orientdb": {
       "dbURL": "plocal:/home/ivan/OrientDB/db_installati/enterprise/orientdb-enterprise-2.2.10/databases/stack39517796",
       "dbType": "graph",
       "dbAutoCreate": true,
       "classes": [
         {"name": "A", "extends": "V"},
         {"name": "B", "extends": "V"},
         {"name": "Conn", "extends": "E"}
       ]
    }
  }
}

data1.csv

a1,a2
1,1
1,2
2,3

data2.csv

b1,b2
1,1
2,3
1,2

execution order:

  1. json1
  2. json2

and here is the final result:

orientdb {db=stack39517796}> select from v                                        

+----+-----+------+----+----+-------+----+----+--------+
|#   |@RID |@CLASS|a1  |a2  |in_Conn|b2  |b1  |out_Conn|
+----+-----+------+----+----+-------+----+----+--------+
|0   |#17:0|A     |1   |1   |[#25:0]|    |    |        |
|1   |#18:0|A     |1   |2   |[#27:0]|    |    |        |
|2   |#19:0|A     |2   |3   |[#26:0]|    |    |        |
|3   |#21:0|B     |    |    |       |1   |1   |[#25:0] |
|4   |#22:0|B     |    |    |       |3   |2   |[#26:0] |
|5   |#23:0|B     |    |    |       |2   |1   |[#27:0] |
+----+-----+------+----+----+-------+----+----+--------+
Ivan Mainetti
  • 1,982
  • 7
  • 13
  • Excellent help Ivan! Mille Grazie –  Sep 19 '16 at 13:51
  • @ivan-mainetti I'm not sure if that works... if you append `2,1` to data1.csv and to data2.csv, the result would generate extra edges from b(1,1) to a(1,1) and a(2,1). I think it's only matching on the last join field rather than performing an **AND** operation. – TxAG98 Apr 11 '17 at 19:25
  • @ivan-mainetti I looked into it a bit more, and I think this only works in your example because a2 and b2 are unique. The second "joinFieldName" entry in the json2.json will [smash the first one without causing an error...](http://stackoverflow.com/questions/5306741/do-json-keys-need-to-be-unique) If you run this with debug logging on you'll see that it's only matching a2 to b2. – TxAG98 Apr 11 '17 at 20:57