Terabyte of Click Logs from Criteo

可以从 http://labs.criteo.com/downloads/download-terabyte-click-logs/ 上下载数据

创建原始数据对应的表结构:

  1. CREATE TABLE criteo_log (date Date, clicked UInt8, int1 Int32, int2 Int32, int3 Int32, int4 Int32, int5 Int32, int6 Int32, int7 Int32, int8 Int32, int9 Int32, int10 Int32, int11 Int32, int12 Int32, int13 Int32, cat1 String, cat2 String, cat3 String, cat4 String, cat5 String, cat6 String, cat7 String, cat8 String, cat9 String, cat10 String, cat11 String, cat12 String, cat13 String, cat14 String, cat15 String, cat16 String, cat17 String, cat18 String, cat19 String, cat20 String, cat21 String, cat22 String, cat23 String, cat24 String, cat25 String, cat26 String) ENGINE = Log

下载数据:

  1. $ for i in {00..23}; do echo $i; zcat datasets/criteo/day_${i#0}.gz | sed -r 's/^/2000-01-'${i/00/24}'\t/' | clickhouse-client --host=example-perftest01j --query="INSERT INTO criteo_log FORMAT TabSeparated"; done

创建转换后的数据对应的表结构:

  1. CREATE TABLE criteo
  2. (
  3. date Date,
  4. clicked UInt8,
  5. int1 Int32,
  6. int2 Int32,
  7. int3 Int32,
  8. int4 Int32,
  9. int5 Int32,
  10. int6 Int32,
  11. int7 Int32,
  12. int8 Int32,
  13. int9 Int32,
  14. int10 Int32,
  15. int11 Int32,
  16. int12 Int32,
  17. int13 Int32,
  18. icat1 UInt32,
  19. icat2 UInt32,
  20. icat3 UInt32,
  21. icat4 UInt32,
  22. icat5 UInt32,
  23. icat6 UInt32,
  24. icat7 UInt32,
  25. icat8 UInt32,
  26. icat9 UInt32,
  27. icat10 UInt32,
  28. icat11 UInt32,
  29. icat12 UInt32,
  30. icat13 UInt32,
  31. icat14 UInt32,
  32. icat15 UInt32,
  33. icat16 UInt32,
  34. icat17 UInt32,
  35. icat18 UInt32,
  36. icat19 UInt32,
  37. icat20 UInt32,
  38. icat21 UInt32,
  39. icat22 UInt32,
  40. icat23 UInt32,
  41. icat24 UInt32,
  42. icat25 UInt32,
  43. icat26 UInt32
  44. ) ENGINE = MergeTree(date, intHash32(icat1), (date, intHash32(icat1)), 8192)

将第一张表中的原始数据转化写入到第二张表中去:

  1. INSERT INTO criteo SELECT date, clicked, int1, int2, int3, int4, int5, int6, int7, int8, int9, int10, int11, int12, int13, reinterpretAsUInt32(unhex(cat1)) AS icat1, reinterpretAsUInt32(unhex(cat2)) AS icat2, reinterpretAsUInt32(unhex(cat3)) AS icat3, reinterpretAsUInt32(unhex(cat4)) AS icat4, reinterpretAsUInt32(unhex(cat5)) AS icat5, reinterpretAsUInt32(unhex(cat6)) AS icat6, reinterpretAsUInt32(unhex(cat7)) AS icat7, reinterpretAsUInt32(unhex(cat8)) AS icat8, reinterpretAsUInt32(unhex(cat9)) AS icat9, reinterpretAsUInt32(unhex(cat10)) AS icat10, reinterpretAsUInt32(unhex(cat11)) AS icat11, reinterpretAsUInt32(unhex(cat12)) AS icat12, reinterpretAsUInt32(unhex(cat13)) AS icat13, reinterpretAsUInt32(unhex(cat14)) AS icat14, reinterpretAsUInt32(unhex(cat15)) AS icat15, reinterpretAsUInt32(unhex(cat16)) AS icat16, reinterpretAsUInt32(unhex(cat17)) AS icat17, reinterpretAsUInt32(unhex(cat18)) AS icat18, reinterpretAsUInt32(unhex(cat19)) AS icat19, reinterpretAsUInt32(unhex(cat20)) AS icat20, reinterpretAsUInt32(unhex(cat21)) AS icat21, reinterpretAsUInt32(unhex(cat22)) AS icat22, reinterpretAsUInt32(unhex(cat23)) AS icat23, reinterpretAsUInt32(unhex(cat24)) AS icat24, reinterpretAsUInt32(unhex(cat25)) AS icat25, reinterpretAsUInt32(unhex(cat26)) AS icat26 FROM criteo_log;
  2. DROP TABLE criteo_log;

原始文章