Scriptella を試して、自分のニーズを満たすかどうかを確認しています。これまでのところ、それは素晴らしいツールのようです。サンプル スクリプトの調査、フォーラムの検索、およびネストされたクエリ/スクリプトのコツをつかむために数時間を費やしました。
これは私の ETL ファイルの例で、簡潔にするために少しクリーンアップされています。# で始まる行が追加され、実際の ETL ファイルの一部ではありません。ID を挿入/取得して、後のスクリプト ブロックに渡そうとしています。これを行う最も有望な方法は、グローバル変数を使用することですが、値を取得しようとすると null になります。後で、DB にフィールドを追加する前に、フィールドを解析して大幅に変換するスクリプト ブロックにコードを追加します。
エラーはありません。期待する OS ID とカテゴリ ID を取得できません。前もって感謝します。
<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd">
<etl>
<connection id="in" driver="csv" url="mycsvfile.csv"/>
<connection id="dest" url="jdbc:mysql://localhost:3306/pvm3" user="user" password="password"/>
<connection id="js" driver="script"/>
<query connection-id="in">
<!-- all columns are selected, notably: OPERATINGSYSTEM, CATEGORY, QID, TITLE -->
<query connection-id="dest">
#Check to see if the OS already exists, and get the ID if it does
select max(os_id) as os_id, count(*) as os_cnt from etl_os where os = ?OPERATINGSYSTEM;
#If it doesnt exist then add it and get the auto_increment value
<script if="os_cnt==0">
insert into etl_os(os) values(?OPERATINGSYSTEM);
<query connection-id="dest">
select last_insert_id() as os_id;
#Store in global so it can be accessed in later script blocks
<script connection-id="js">
etl.globals.put('os_id', os_id);
</script>
</query>
</script>
#Same style select/insert as above for category_id (excluded for brevity)
#See if KB record exists by qid, if not then add it with the OS ID and category ID we got earlier
<query connection-id="dest">
select max(qid) as existing_qid, count(*) as kb_cnt from etl_qids where qid = ?QID
<script if="kb_cnt==0">
insert into etl_qids(qid, category_id, os_id) values (?QID, ?{etl.globals.get('category_id')}, ?{etl.globals.get('os_id')});
</script>
</query>
</query>
</query>
</etl>