如何使用 Pentaho 在某些指定数字后开始向 MySql 数据库插入行?

How to start inserting row after some specified number to MySql database using Pentaho?

基本上我想做的是,

我有一个包含 10,000 行的 CSV 文件,我想将其插入到数据库中。当我开始转换时,我想在 4500 行之后开始插入数据库。 所以我想知道我指定的行数。

我怎样才能做到这一点? 任何帮助都会很棒。

图片描述:我只是创建了一个从 csv 读取数据并写入数据库的转换。我不知道哪一步可以帮助我实现这一目标。

注意:我附上了我的简单转换

我还没有找到计算处理行数的步骤,但是您可以使用“User Defined Java Class”步骤来计算行号并使用如下代码删除前 4500 行:

// This will be the counter.
Long rowCount;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
{
    if (first) {
        rowCount = 0l;
        first=false;
    }

    Object[] r = getRow();
    if (r == null) {
        setOutputDone();
        return false;
    }

    // Increment of the counter.
    rowCount++;

    // Check ouf the counter. Doesn't output the current row if it's less than 4501.
    if (rowCount>4500l) {
        Object[] outputRow = createOutputRow(r, data.outputRowMeta.size());
        // Adds the row count to a stream field.
        get(Fields.Out, "Count").setValue(outputRow, rowCount);
        putRow(data.outputRowMeta, outputRow);
    }

    return true;
}

我使用了以下 kettle 文件,解决了我的问题。 感谢@WorkingHard..和@jxc