如何通过Pentaho高效读取CSV表名并导出对应SQL Server表数据?
用Pentaho批量导出SQL Server表数据到CSV的高效实现方案
问题背景
我在Ubuntu环境下有一个CSV文件,里面存储着SQL Server实例中的表名,格式如下:
Tables
TableName1
TableName2
TableName3
...
我的需求是读取这个CSV文件,把每个表的数据导出为${table_name}.csv文件。作为Pentaho新手,我已经尝试了一种实现方法,但想了解有没有Pentaho内置的方法或者更高效的实现方式,欢迎各位提供建议。
已尝试的Job方案详情
- 第一步:
Set Variables步骤,用于初始化循环变量 - 第二步:
CSV Reader Job,通过bash脚本读取CSV文件及总行数,将变量存储到config.properties文件中,脚本代码如下:
#!/bin/bash # CSV file path csv_file="/home/ubuntuv2204/taskDir/tables.csv" property_file="/home/ubuntuv2204/taskDir/dwconfig.properties" # Get the total number of rows in the CSV file (excluding the header) total_rows=$(($(wc -l < "$csv_file"))) # Read the second line of the CSV file (excluding the header) and store it as table_name table_name=$(sed '${NEW_LOOP}q;d' "$csv_file" | cut -d ',' -f 1) # Check if the table_name is not empty if [ -n "$table_name" ]; then # Print the table name echo "Table Name: $table_name" else echo "Table name is empty or CSV file is not formatted correctly." fi # Store the total number of rows in a variable called loop_break #loop_break=$total_rows #echo "#DW" > "$property_file" echo "table_name=$table_name" > "$property_file" echo "loop_break=$total_rows" >> "$property_file"
- 第三步:
Loop Transformation,用于每次递增循环值 - 第四步:
Set DW Transformation,读取config.properties文件,设置table_name和总行数变量 - 第五步:
rw_ktr,包含Table Input步骤,读取对应表的数据并导出为TXT文件 - 第六步:
Simple Evaluation步骤,检查循环值是否等于CSV总行数,若是则结束Job
该方案可以满足需求,但我认为不够理想,希望找到更高效的解决方案。
内容的提问来源于stack exchange,提问作者Aravind S
相关产品推荐
相关产品推荐

