摘要:本文由社區用戶 xrfinbj 貢獻,主要介紹 Exchange 工具從 Hive 數倉導入數據到 Nebula Graph 的流程及相關的注意事項。java
公司內部有使用圖數據庫的場景,內部經過技術選型肯定了 Nebula Graph 圖數據庫,還須要驗證 Nebula Graph 數據庫在實際業務場景下的查詢性能。因此急迫的須要導入數據到 Nebula Graph 並驗證。在這個過程當中發現經過 Exchange 工具從 hive 數倉導入數據到 Nebula Graph 文檔不是很全,因此把這個流程中踩到的坑記錄下來,回饋社區,避免後人走彎路。git
本文主要基於我以前發在論壇的 2 篇帖子:github
編譯後生成 jar 包sql
CREATE SPACE test_hive(partition_num=10, replica_factor=1); --建立圖空間,本示例中假設只須要一個副本 USE test_hive; --選擇圖空間 test CREATE TAG tagA(idInt int, idString string, tboolean bool, tdouble double); -- 建立標籤 tagA CREATE TAG tagB(idInt int, idString string, tboolean bool, tdouble double); -- 建立標籤 tagB CREATE EDGE edgeAB(idInt int, idString string, tboolean bool, tdouble double); -- 建立邊類型 edgeAB
CREATE TABLE `tagA`( `id` bigint, `idInt` int, `idString` string, `tboolean` boolean, `tdouble` double) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LINES TERMINATED BY '\n'; insert into tagA select 1,1,'str1',true,11.11; insert into tagA select 2,2,"str2",false,22.22; CREATE TABLE `tagB`( `id` bigint, `idInt` int, `idString` string, `tboolean` boolean, `tdouble` double) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LINES TERMINATED BY '\n'; insert into tagB select 3,3,"str 3",true,33.33; insert into tagB select 4,4,"str 4",false,44.44; CREATE TABLE `edgeAB`( `id_source` bigint, `id_dst` bigint, `idInt` int, `idString` string, `tboolean` boolean, `tdouble` double) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001' LINES TERMINATED BY '\n'; insert into edgeAB select 1,3,5,"edge 1",true,55.55; insert into edgeAB select 2,4,6,"edge 2",false,66.66;
注意看exec、fields、nebula.fields、vertex、source、target字段映射數據庫
{ # Spark relation config spark: { app: { name: Spark Writer } driver: { cores: 1 maxResultSize: 1G } cores { max: 4 } } # Nebula Graph relation config nebula: { address:{ graph: ["192.168.1.110:3699"] meta: ["192.168.1.110:45500"] } user: user pswd: password space: test_hive connection { timeout: 3000 retry: 3 } execution { retry: 3 } error: { max: 32 output: /tmp/error } rate: { limit: 1024 timeout: 1000 } } # Processing tags tags: [ # Loading from Hive { name: tagA type: { source: hive sink: client } exec: "select id,idint,idstring,tboolean,tdouble from nebula.taga" fields: [id,idstring,tboolean,tdouble] nebula.fields: [idInt,idString,tboolean,tdouble] vertex: id batch: 256 partition: 10 } { name: tagB type: { source: hive sink: client } exec: "select id,idint,idstring,tboolean,tdouble from nebula.tagb" fields: [id,idstring,tboolean,tdouble] nebula.fields: [idInt,idString,tboolean,tdouble] vertex: id batch: 256 partition: 10 } ] # Processing edges edges: [ # Loading from Hive { name: edgeAB type: { source: hive sink: client } exec: "select id_source,id_dst,idint,idstring,tboolean,tdouble from nebula.edgeab" fields: [id_source,idstring,tboolean,tdouble] nebula.fields: [idInt,idString,tboolean,tdouble] source: id_source target: id_dst batch: 256 partition: 10 } ] }
spark-submit --class com.vesoft.nebula.tools.importer.Exchange --master 「local[4]」 /xxx/exchange-1.0.1.jar -c /xxx/nebula_application.conf -h
./db_dump --mode=stat --space=xxx --db_path=/home/xxx/data/storage0/nebula --limit 20000000
說明:Exchange 目前還不支持 Spark 3,編譯後運行報錯,因此無法驗證 Spark 3 環境apache
Spark Debug 部分參考博客:https://dzone.com/articles/how-to-attach-a-debugger-to-apache-spark微信
經過 Exchange 源碼的學習和 Debug 能加深對 Exchange 原理的理解,同時也能發現一些文檔描述不清晰的地方,好比 導入 SST 文件 和 Download and Ingest 只有結合源碼看才能發現文檔描述不清晰邏輯不嚴謹的問題。app
經過源碼 Debug 也能發現一些簡單的參數配置問題。socket
進入正題:分佈式
步驟一:
export SPARK_SUBMIT_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=4000
步驟二:
spark-submit --class com.vesoft.nebula.tools.importer.Exchange --master 「local」 /xxx/exchange-1.1.0.jar -c /xxx/nebula_application.conf -h Listening for transport dt_socket at address: 4000
步驟三:IDEA 配置
步驟四:在 IDEA 裏面點擊 Debug
感謝 vesoft 提供了宇宙性能最強的 Nebula Graph 圖數據庫,能解決業務中不少實際問題,中途這點痛不算什麼(看以前的分享,360 數科他們那個痛纔是真痛)。中途遇到的問題都有幸獲得社區及時的反饋解答,再次感謝
很期待 Exchange 支持 Nebula Graph 2.0
喜歡這篇文章?來來來,給咱們的 GitHub 點個 star 表鼓勵啦~~ 🙇♂️🙇♀️ [手動跪謝]
交流圖數據庫技術?交個朋友,Nebula Graph 官方小助手微信:NebulaGraphbot 拉你進交流羣~~