对约 35g 的数据去重 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yylxbiubiu

对约 35g 的数据去重

  •  
  •   yylxbiubiu Feb 4, 2020 5212 views
    This topic created in 2277 days ago, the information mentioned may be changed or developed.
    数据占了 35g 左右存储,有标识每条数据的 id,还剩大约 7g 空闲空间,需要对这 35g 的数据去重,内存是 8g 的.如何对数据进行去重?
    34 replies    2020-02-05 09:44:08 +08:00
    alalida
        1
    alalida  
       Feb 4, 2020 via Android
    你先想一想目标时间复杂度和空间复杂度。去重意味要查找,那最好也就对数时间复杂度。此外要看能否分批处理,数据有无规律。可以分批处理也会快很多。总之要先看数据长什么样。
    otakustay
        2
    otakustay  
       Feb 4, 2020
    数据是 35G,其中 id 部分有多大?不大的话哈希应该是有办法建起来的……
    shuangyeying
        3
    shuangyeying  
       Feb 4, 2020
    是裤子么?
    opengps
        4
    opengps  
       Feb 4, 2020
    去重字段仅仅是 id 字段?还是全字段匹配?
    malusama
        5
    malusama  
       Feb 4, 2020
    bloomfilter 有误差率
    yylxbiubiu
        6
    yylxbiubiu  
    OP
       Feb 4, 2020
    @opengps 每个 id 字段标识这条数据
    yylxbiubiu
        7
    yylxbiubiu  
    OP
       Feb 4, 2020
    @shuangyeying 不是的,亲
    yylxbiubiu
        8
    yylxbiubiu  
    OP
       Feb 4, 2020
    @alalida 在用分片,时间换空间,但很慢,每次 10w 条
    yylxbiubiu
        9
    yylxbiubiu  
    OP
       Feb 4, 2020
    @malusama 有空间限制的
    yylxbiubiu
        10
    yylxbiubiu  
    OP
       Feb 4, 2020
    @alalida 经过分析,每条数据里边的 id 唯一标识这条数据
    wysnylc
        11
    wysnylc  
       Feb 4, 2020 via Android
    把 id 提出来,还能有 35g ?
    ho121
        12
    ho121  
       Feb 4, 2020 via Android
    对每条数据 hash 后存到哈希表或者二叉树中。
    hash 算法也不需要碰撞率很低的那种,比如 crc32,crc64 这种简单的就行,这样可以加快 hash 速度,并减少内存使用。当碰到 hash 相同的,需要做完全匹配来判断数据是否真的是相等。
    哈希表或者二叉树每个节点要存下每个 hash 对应的 id (可能有多个)。

    数据用流式读取,或者扔进数据库中。


    手机码字,有点乱
    grimpil
        13
    grimpil  
       Feb 4, 2020 via Android   5
    还以为是 35 克数据
    yylxbiubiu
        14
    yylxbiubiu  
    OP
       Feb 4, 2020
    @grimpil 哈哈哈哈哈哈
    keepeye
        15
    keepeye  
       Feb 4, 2020
    遍历所有数据,id 字段走布隆过滤器去重 用不了多少内存
    mxT52CRuqR6o5
        16
    mxT52CRuqR6o5  
       Feb 4, 2020 via Android
    Bitmap
    binux
        17
    binux  
       Feb 4, 2020
    如果数据>>id,拿 id 出来随便爱怎么搞怎么搞
    如果数据就是 id,每 7g 分片排序再 merge 排序。
    zengguibo
        18
    zengguibo  
       Feb 4, 2020
    如果只是文本数据,压缩一下传到性能强内存大的机器上,直接导入内存去重
    Tlvncks
        19
    Tlvncks  
       Feb 4, 2020
    引用;@grimpil #13 还以为是 35 克数据

    -------------------------------------------------------
    我也看了半天,还在想 35g 啥玩意?难道想提纯??
    Rekkles
        20
    Rekkles  
       Feb 4, 2020
    数据 hash 然后对比去重?
    有个笨一点的办法,数据导入 db 做唯一索引 一条一条导入,导入失败的就是重复的,牺牲时间换空间。
    coolcfan
        21
    coolcfan  
       Feb 4, 2020 via Android
    跟 13 楼一样,看到是小写第一反应是 35 克数据……
    suotm
        22
    suotm  
       Feb 4, 2020
    取 3.5G 做好去重的脚本,然后开一个 64GB 内存的云主机跑
    lululau
        23
    lululau  
       Feb 4, 2020 via iPhone
    35g? 用什么称的?
    hhhsuan
        24
    hhhsuan  
       Feb 4, 2020 via Android
    大小写很重要啊
    netnr
        25
    netnr  
       Feb 4, 2020
    直接执行开窗函数按 id 分组排序取大于 1 的项并删除,难道顶不住?
    ofblyt
        26
    ofblyt  
       Feb 4, 2020
    最近做饭做的,看到 35g 还想 35 克去重( zhong )是给什么去皮吗
    yufeng0681
        27
    yufeng0681  
       Feb 4, 2020
    根据 id 第一位进行文件分拣(切割到),假设有 26 个字母,10 个数字; 估计每个文件 1G 左右,那样问题就变成了 1G 文件的处理
    gfreezy
        28
    gfreezy  
       Feb 4, 2020
    shell 里面 sort | uniq 就可以。内存不够的时候 sort 会自动交换到磁盘上。

    https://unix.stackexchange.com/questions/383056/sort-huge-list-130gb-in-linux
    yylxbiubiu
        29
    yylxbiubiu  
    OP
       Feb 4, 2020
    @lululau 电子秤吧
    yylxbiubiu
        30
    yylxbiubiu  
    OP
       Feb 4, 2020
    @ofblyt 姜吧
    yylxbiubiu
        31
    yylxbiubiu  
    OP
       Feb 4, 2020
    @gfreezy 存储有限的,都在数据库里
    yylxbiubiu
        32
    yylxbiubiu  
    OP
       Feb 4, 2020
    @yufeng0681 id 是纯数字,剩余的空间只有 7 个 G
    gfreezy
        33
    gfreezy  
       Feb 4, 2020
    @fields 建个新表加上 unique key,重新 load 一下就可以
    fuye
        34
    fuye  
       Feb 5, 2020 via Android
    create table tmp(id bigint,unique key id ( id ))
    insert into tmp select id from 你的表
    About     Help     Advertise     Blog     API     FAQ     Solana     2208 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 70ms UTC 00:32 PVG 08:32 LAX 17:32 JFK 20:32
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86