You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 02:28:16