功能介紹
新發(fā)布的 Byzer 2.2.2 提供了 Oracle Upsert 功能。Upsert 意思是當(dāng)數(shù)據(jù)庫(kù)表存在數(shù)據(jù)時(shí) Insert , 否則 Update。舉個(gè)例子,有表 table_1
| c1 | c2 |
|---|---|
| 1 | "a" |
Upsert 的 結(jié)果集為
| c1 | c2 |
|---|---|
| 1 | "a_updated" |
| 2 | "b" |
Upsert時(shí),table_1 不包含 c1=2 的數(shù)據(jù),Insert ; 包含 c1=1 的數(shù)據(jù),則 Update.
使用方式
我們以 Linux 為例說(shuō)明。
下載 Byzer-lang 2.2.2 & Byzer-notebook 1.1.1, 參考 Byzer-lang 安裝文檔 和 Byzer-notebook 安裝文檔
下載 Oracle JDBC 包,請(qǐng)根據(jù) Oracle 版本選擇適配的 JDBC 版本。并拷貝至 Byzer-lang 安裝目錄的 libs 子目錄。
執(zhí)行 Byzer-lang 安裝目錄
bin/start-local.sh以啟動(dòng) Byzer-lang .檢查 byzer-notebook 安裝目錄
conf/notebook.properties中notebook.mlsql.engine-url是否指向 byzer-lang; 并確保conf/notebook.properties配置的 MySQL 能聯(lián)通。啟動(dòng) Byzer-notebook。瀏覽器 打開(kāi)
http://<byzer-notebook-ip>:9002。conf/notebook.properties配置項(xiàng)notebook.port=9002。第一次登錄時(shí),填寫(xiě)用戶名密碼,再點(diǎn)擊注冊(cè)。再次登錄即可。
新建一個(gè) Notebook,開(kāi)始寫(xiě)代碼。
CONNECT jdbc WHERE
url="jdbc:oracle:thin:<username>/<password>@<oracle_host>:<port>/orclpdb1.localdomain"
and driver="oracle.jdbc.driver.OracleDriver"
AS db_1;
SELECT 1 c1 ,"1_update" c2
UNION ALL
SELECT 2 c1, "2" c2 AS records;
SAVE APPEND records as jdbc.`db_1.zjc_11` WHERE idCol="c1";
APPEND 表明 Upsert Oracle;且 idCol = "c1" 表明 Upsert 時(shí) 比較 zjc_11 表 c1 字段。
如果你碰到問(wèn)題,歡迎加入 slack 提問(wèn)。