我正在试用 Scriptella,看看它是否能满足我的需求。到目前为止,它似乎是一个很棒的工具。我花了几个小时研究示例脚本、搜索论坛并尝试掌握嵌套查询/脚本的窍门。
这是我的 ETL 文件的一个示例,为简洁起见稍微清理了一下。添加以 # 开头的行,而不是实际 ETL 文件的一部分。我正在尝试插入/检索 ID,然后将它们传递给以后的脚本块。最有希望的方法似乎是使用全局变量,但在尝试检索值时我得到了 null。稍后,我将在脚本块中添加代码,在将字段添加到数据库之前解析和显着转换字段。
没有错误。我只是没有得到我期望的操作系统 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>