mw 发帖数: 525 | 1 两个table,都是csv形式存在硬盘上,每个100万行,每个的第一列都是timestamp,怎
么样实现一个fuzzy join,产生一个新的一百万行的table,每行都是table 1,和小或
者等于table1的timestamp的table2的对应的那一行
我感觉这个好像没有什么巧办法,只能一行一行的从两个table轮流读。
如果要把两个table同时读到内存,然后建立索引什么的,那对内存需求就太大了
各位有什么好办法啊? |
mw 发帖数: 525 | 2 70多个人看了,没点意见吗?
是不是我没有解释清楚?
大牛们不要吝惜拍一下哈
【在 mw 的大作中提到】 : 两个table,都是csv形式存在硬盘上,每个100万行,每个的第一列都是timestamp,怎 : 么样实现一个fuzzy join,产生一个新的一百万行的table,每行都是table 1,和小或 : 者等于table1的timestamp的table2的对应的那一行 : 我感觉这个好像没有什么巧办法,只能一行一行的从两个table轮流读。 : 如果要把两个table同时读到内存,然后建立索引什么的,那对内存需求就太大了 : 各位有什么好办法啊?
|
g*****g 发帖数: 34805 | 3 不明白这有啥难的。1M的数据,就算每个数据1K,不就1G,这年头内存随便放。
如果每条记录很大,存一个timestamp加一个offset也就几个字节的事情。
把两个表简单内排O(NlogN),然后做个Merge, O(M+N)就完了。 |
r***6 发帖数: 401 | 4 #!/usr/bin/python
f1 = open("f1.csv")
f2 = open("f2.csv")
ts2 = 0
line2 = "\n"
for line1 in f1:
ts1 = int(line1.split(",")[0])
while ts2 <= ts1:
nextline2 = f2.readline()
if not nextline2:
break
ts2 = line2.split(",")[0]
if ts2 <= ts1:
line2 = nextline2
print line1 + "," + line2, |
d****n 发帖数: 1637 | 5 nice!
otherwise, try linux command tool "join"
http://www.folkstalk.com/2012/02/join-command-in-unixlinux-exam
【在 r***6 的大作中提到】 : #!/usr/bin/python : f1 = open("f1.csv") : f2 = open("f2.csv") : ts2 = 0 : line2 = "\n" : for line1 in f1: : ts1 = int(line1.split(",")[0]) : while ts2 <= ts1: : nextline2 = f2.readline() : if not nextline2:
|
D****r 发帖数: 309 | 6 not quite understood your request:
" 每行都是table 1,和小或者等于table1的timestamp的table2的对应的那一行"
would be better print some sample line here of each table, and what is the
result format you want.
I think apart from rc256's python solution, shell scripting would be easy to
handle that. e.g. using awk with certain split symbol and compare the
result and print together.
【在 mw 的大作中提到】 : 两个table,都是csv形式存在硬盘上,每个100万行,每个的第一列都是timestamp,怎 : 么样实现一个fuzzy join,产生一个新的一百万行的table,每行都是table 1,和小或 : 者等于table1的timestamp的table2的对应的那一行 : 我感觉这个好像没有什么巧办法,只能一行一行的从两个table轮流读。 : 如果要把两个table同时读到内存,然后建立索引什么的,那对内存需求就太大了 : 各位有什么好办法啊?
|
r***6 发帖数: 401 | 7 Another solution is to use R says package. Essentially what you needed is
last observation carried forward.
There are many stats package does that.
not quite understood your request: " 每行都是table 1,和小或者等于table1的
timestamp的table2的对应的那一行"wo........
【在 D****r 的大作中提到】 : not quite understood your request: : " 每行都是table 1,和小或者等于table1的timestamp的table2的对应的那一行" : would be better print some sample line here of each table, and what is the : result format you want. : I think apart from rc256's python solution, shell scripting would be easy to : handle that. e.g. using awk with certain split symbol and compare the : result and print together.
|