【问题】
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:读取文本文件的内容,将每一行作为一个成员返回成序列。

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

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

A4:拼结果集。

这段代码可以方便地集成进Java(参考Java 如何调用 SPL 脚本)
本文介绍了一种使用SPL脚本来高效处理两个CSV文件的方法,旨在从产品及其选项中提取相关SKU数据。通过简单的代码实现,有效地解决了数据整合的问题。
684

被折叠的 条评论
为什么被折叠?



