2017-05-26 46 views
0

試圖加載一個簡單的JSON數據文件分成OrientDB。無法使用oetl.sh實用程序JSON加載到OrientDB類

這裏是我的輸入數據文件(/tmp/databases/test_data1/database.json)。

[ 
{ 
    "id": 1, 
    "name" : "xyz" 
}, 
{ 
    "id": 2, 
    "name" : "pqr" 
}, 
{ 
    "id": 3, 
    "name" : "abc" 
} 
] 

這是我的配置json文件(/tmp/json_import_config.json)。

{ 
    "config": { 
    "log": "debug" 
}, 
"source" : { 
"file": { "path": "/tmp/databases/test_data1/database.json" } 
}, 
"extractor" : { 
"json": {} 
}, 
"transformers": [ 
    { 
     "log": {} 
    } 
], 
"loader" : { 
    "orientdb": { 
     "dbURL": "plocal:/opt/orientdb/databases/example3", 
     "dbUser": "admin", 
     "dbPassword": "admin", 
     "dbAutoDropIfExists": true, 
     "dbAutoCreate": true, 
     "standardElementConstraints": false, 
     "tx": false, 
     "wal": false, 
     "batchCommit": 1000, 
     "dbType": "document", 
     "classes": [{"name": "Account"}] 
    } 
}, 
"end": [] 
} 

這裏是我正在使用的命令。

./oetl.sh /tmp/json_import_config.json 

這裏是輸出....

OrientDB etl v.2.2.20 (build 76ab59e72943d0ba196188ed100c882be4315139) https://www.orientdb.com 
[file] INFO Load from file /tmp/databases/test_data1/database.json 
[orientdb] INFO Dropping existent database 'plocal:/opt/orientdb/databases/example3'... 
BEGIN ETL PROCESSOR 
[file] INFO Reading from file /tmp/databases/test_data1/database.json with encoding UTF-8 
Started execution with 1 worker threads 
+ extracted 0 entries (0 entries/sec) - 0 entries -> loaded 0 documents (0 documents/sec) Total time: 1000ms [0 warnings, 0 errors] 
[orientdb] DEBUG - OrientDBLoader: created class 'Account' 
[orientdb] DEBUG orientdb: found 0 documents in class 'null' 
Start extracting 
[0:log] DEBUG Transformer input: {id:1,name:xyz} 
Extraction completed 
[0:log] INFO {id:1,name:xyz} 
[0:log] DEBUG Transformer output: {id:1,name:xyz} 
Pipeline execution halted 

2018-12-06 13:47:41:386 SEVER {db=example3} ETL process halted: com.orientechnologies.orient.etl.OETLProcessHaltedException: Cannot insert new document {id:1,name:xyz} because it has not class [OETLProcessor$OETLPipelineWorker][orientdb] INFO committing 
Pipeline worker done without errors: false 
END ETL PROCESSOR 
+ extracted 3 entries (15 entries/sec) - 3 entries -> loaded 0 documents (0 documents/sec) Total time: 1190ms [0 warnings, 1 errors] 

在解決這個問題上需要幫助。也想知道OrientDB是否僅僅作爲文檔存儲使用它的好選擇,因爲沒有找到許多用例。大多數用例都是w.r.t.圖形。

回答

1

你配置它幾乎正確的,你需要的類分配給由管道正在處理的每個文檔。添加一個設置類名稱的字段變壓器:

"transformers": [ 
{ 
    "log": {} 
}, 
{ 
    "field": { 
    "fieldName": "@class", 
    "value": "Account" 
    } 
}], 

我本地測試,這是從控制檯輸出:

orientdb {db=docDb}> select from Account 

+----+-----+-------+----+----+ 
|# |@RID |@CLASS |id |name| 
+----+-----+-------+----+----+ 
|0 |#25:0|Account|1 |xyz | 
|1 |#26:0|Account|2 |pqr | 
|2 |#27:0|Account|3 |abc | 
+----+-----+-------+----+----+ 

3 item(s) found. Query executed in 0.006 sec(s). 
+0

感謝羅伯特的回答。在進行建議的更改後,它仍然無法正常工作。我得到以下錯誤。 「java.lang.ClassCastException:java.lang.String不能轉換爲com.orientechnologies.orient.core.record.impl.Offocument」。是否有可能分享有效的確切配置? – TechEnthusiast

+0

我剛剛添加了我的代碼片段中顯示的變壓器。沒有其他的。 –

+0

感謝羅伯託它的工作。試圖編輯你的響應,並將方括號放入代碼片段中,但由於需要編輯6個字符,所以未能這樣做。 – TechEnthusiast

相關問題