我正试图分析大量的GitHub存档数据,但受到许多限制的困扰。在
所以我的分析需要我搜索一个350GB的数据集。我有一个本地的数据拷贝,还有一个拷贝可以通过googlebigquery获得。本地数据集被分成25000个单独的文件。数据集是事件的时间轴。在
我想画出每个存储库自创建以来的星数。(仅适用于目前超过1000英镑的回购)
我可以使用googlebigquery很快得到这个结果,但它每次“分析”13.6GB的数据。这就限制了我75个请求,而不必每增加75个就支付5美元。在
我的另一个选择是搜索本地副本,但在每个文件中搜索特定字符串(存储库名称)的时间太长。在我停止进程之前,我在一个SSD驱动器上花了一个多小时浏览了一半的文件。在
我有什么更好的方法来分析如此大量的数据?在
用于搜索所有本地文件的Python代码:
for yy in range(11,15):
for mm in range(1,13):
for dd in range(1,32):
for hh in range(0,24):
counter = counter + 1
if counter < startAt:
continue
if counter > stopAt:
continue
#print counter
strHH = str(hh)
strDD = str(dd)
strMM = str(mm)
strYY = str(yy)
if len(strDD) == 1:
strDD = "0" + strDD
if len(strMM) == 1:
strMM = "0" + strMM
#print strYY + "-" + strMM + "-" + strDD + "-" + strHH
try:
f = json.load (open ("/Volumes/WD_1TB/GitHub Archive/20"+strYY+"-"+strMM+"-"+strDD+"-"+strHH+".json", 'r') , cls=ConcatJSONDecoder)
for each_event in f:
if(each_event["type"] == "WatchEvent"):
try:
num_stars = int(each_event["repository"]["watchers"])
created_at = each_event["created_at"]
json_entry[4][created_at] = num_stars
except Exception, e:
print e
except Exception, e:
print e
Google Big Query SQL命令:
^{pr2}$我真的很为难,所以在这一点上的任何建议将不胜感激。在
如果大多数BigQuery查询只扫描数据的一个子集,则可以执行一个初始查询来提取该子集(使用“allowlargesults”)。然后针对小表的后续查询将花费更少的成本。在
例如,如果只查询type=“WatchEvent”的记录,则可以运行如下查询:
并设置目标表以及“允许大结果”标志。此查询将扫描整个13.6 GB,但输出只有1 GB,因此后续针对输出表的查询最多只收取1 GB的费用。在
这对你来说可能还不够便宜,但只是放弃了选择。在
我找到了解决这个问题的方法——使用数据库。我将360+GB JSON数据中的相关数据导入到MySQL数据库中并进行查询。以前每个元素3小时以上的查询时间变成了<;10秒。在
MySQL的设置不是最容易的,导入大约需要7.5小时,但是结果让我觉得值得。在
相关问题 更多 >
编程相关推荐