Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python从bigquery获取数据时linux服务器上出现内存错误?_Python_Google Bigquery - Fatal编程技术网

使用python从bigquery获取数据时linux服务器上出现内存错误?

使用python从bigquery获取数据时linux服务器上出现内存错误?,python,google-bigquery,Python,Google Bigquery,我正在尝试使用python从大查询中获取数据。代码在我的笔记本电脑上运行良好,但在Linux服务器上抛出内存错误。是否可以对其进行优化,使其也可以在服务器上运行 错误:表有500万行…Linux计算机有8 GB ram…错误“内存不足”,进程被终止 代码如下: os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/Users/Desktop/big_query_test/soy-serenity-89ed73.json" client = bigqu

我正在尝试使用python从大查询中获取数据。代码在我的笔记本电脑上运行良好,但在Linux服务器上抛出内存错误。是否可以对其进行优化,使其也可以在服务器上运行

错误:表有500万行…Linux计算机有8 GB ram…错误“内存不足”,进程被终止

代码如下:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/Users/Desktop/big_query_test/soy-serenity-89ed73.json"

client = bigquery.Client()

# Perform a query.

QUERY = “SELECT * FROM `soy-serenity-89ed73.events10`”


query_job = client.query(QUERY)

df = query_job.to_dataframe()

我可以提出两种方法:

选项1
选择
数据块,以减少每次迭代时从BigQuery收到的数据大小。 例如,您的表是分区,您可以执行以下操作:

WHERE _PARTITIONTIME = currentLoopDate
其中currentLoopDate将是python代码中的一个日期变量(类似的选项将使用
行号

选项2
通过使用,您可以使用作业。插入API并将配置。查询。优先级设置为批处理

# from google.cloud import bigquery
# client = bigquery.Client()

query = (
    'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '
    'WHERE state = "TX" '
    'LIMIT 100')
query_job = client.query(
    query,
    # Location must match that of the dataset(s) referenced in the query.
    location='US')  # API request - starts the query

for row in query_job:  # API request - fetches results
    # Row values can be accessed by field name or index
    assert row[0] == row.name == row['name']
    print(row)
有关更多详细信息,请参见此
在获得jobId后,通过设置API的
maxResults
参数编写一个循环,使用来获取数据块,我可以建议两种方法:

选项1
选择
数据块,以减少每次迭代时从BigQuery收到的数据大小。 例如,您的表是分区,您可以执行以下操作:

WHERE _PARTITIONTIME = currentLoopDate
其中currentLoopDate将是python代码中的一个日期变量(类似的选项将使用
行号

选项2
通过使用,您可以使用作业。插入API并将配置。查询。优先级设置为批处理

# from google.cloud import bigquery
# client = bigquery.Client()

query = (
    'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '
    'WHERE state = "TX" '
    'LIMIT 100')
query_job = client.query(
    query,
    # Location must match that of the dataset(s) referenced in the query.
    location='US')  # API request - starts the query

for row in query_job:  # API request - fetches results
    # Row values can be accessed by field name or index
    assert row[0] == row.name == row['name']
    print(row)
有关更多详细信息,请参见此
在您获得作业ID后,编写一个循环,通过设置API的
maxResults
参数来获取数据块

@nk23如果我的答案有任何帮助,请接受/投票支持,我们将不胜感激,stackoverflow.com/help/someone-answers–@nk23如果我的答案有任何帮助,我们将不胜感激,stackoverflow.com/help/someone-answers-