拆串后结构化,其中按行对齐

【问题】

I have a bit weired scenario where i need to fetch data

i have following three products

product1
product2
product3

and each product has different ids(e.g. p1345,p3453,p2345) and then each froduct have different options which are having different skus

option1(sku234),option2(sku345)
option1(sku1001)
option1(sku0022),option2(sku0033)

so if i store products in one csv file and options in other csv file,how can i fetch the relevant skus from the option file.

【回答】

直观的办法是两个文件按行JOIN起来,用计算列就能获得sku。但JAVA写起来很麻烦,用SPL要简单得多:


A

1

=file("d:\\product.csv").import@i()

2

=file("d:\\option.csv").import@i()

3

=join@p(A1,A2.(~.array(",").(mid(~,start=pos(~,"(")+1,pos(~,")")-start))))

4

=A3.conj(#2.new(A3.#1:product,~:sku))

 

A1读取文本文件的内容,将每一行作为一个成员返回成序列。

undefined

A2读取文本文件的内容,将每一行作为一个成员返回成序列。

undefined

A3:拆出A2中的sku,并和A1进行连接。

undefined

A4:拼结果集。

undefined

这段代码可以方便地集成进Java(参考Java 如何调用 SPL 脚本