您应该能够在 tJavaRow 中编写一段自定义的 Java 代码,以便在需要时解析出这些值。
您可能希望使用 tFileInputRaw 将原始源作为原始输入读取,这样您就可以在 tJavaRow 组件中解析整个内容。您需要向 tJavaRow 添加一个输出模式,其中包含您的 id、unit、value1、value2 和 value3 的列。
因为您有需要分解为多行的行,您可能最好将 1a、1b、1c 和 1d 等值连接在一起,然后您可以使用 tNormalize 组件进一步分解为单独的行,这将打破根据需要向下排列。
在我的脑海中,您的 tJavaRow 组件中的代码可能类似于:
// First we split the data on the delimiter of the file, assuming comma separated for now
String[] splitData = inputrow.content.split(",");
// Initialise the three value strings
String value1 = ""
String value2 = ""
String value3 = ""
for (int i = 0; i < splitData.length; i++) {
if (i == 1) {
// id field is the first field
String id = splitData[i];
} else if (i == 2) {
unit field is the second field
String unit = splitData[i];
} else if (i == 3) {
// Don't need to do anything with the count data
} else if (i % 3 == 1) {
// value1 fields are 4, 7, 10 etc so modulo 3 == 1
if (value1.length == 0) {
value1 + splitData[i];
} else {
// if the value field isn't empty (ie. for val1b) then we need to add a delimiter for further processing
value1 + "|" + splitData[i];
}
} else if (i % 3 == 1) {
if (value2.length == 0) {
value2 + splitData[i];
} else {
value2 + "|" + splitData[i];
}
} else if (i % 3 == 3) {
if (value3.length == 0) {
value3 + splitData[i];
} else {
value3 + "|" + splitData[i];
}
}
}
// Finally we then assign these strings to their output schema columns
output_row.id = id;
output_row.unit = unit;
output_row.value1 = value1;
output_row.value2 = value2;
output_row.value3 = value3;
如果您的任何字段的内容可以包含逗号(或您的文件具有的任何分隔符,您将遇到一些问题,因为您需要制作一个更复杂的解析方法来允许引用的字段数据。
从这里您只需要连接 tNormalize 组件并将其拆分到 | 字符(或者您选择的任何字符,它应该是一个不会在您的源数据中找到的字符)。您可能需要执行此操作 3 次才能获得所需的输出(因为您需要对三列进行规范化)。