当前位置: 首页 > 知识库问答 >
问题:

可能函数无法生成,错误我不明白

耿俊
2023-03-14

请看下面我在main.py中提供的内容

# Imports the BigQuery client library
    from google.cloud import bigquery

    def extract_data(request):
        # Replace these values according to your project
        project_name = "whr-asia-datalake-nonprod" 
        bucket_name = "whr-asia-datalake-dev-standard/outbound/Adobe/" 
        dataset_name = "WHR_DATALAKE" 
        table_name = "CONSUMER_EXTRACT" 
        destination_uri = "gs://{}/{}".format(bucket_name,"Consumer_master.csv")

        bq_client = bigquery.Client(project=project_name)

        dataset = bq_client.dataset(dataset_name, project=project_name)
        table_to_export = dataset.table(table_name)

        job_config = bigquery.job.ExtractJobConfig()
        
        extract_job = bq_client.extract_table(
            table_to_export,
            destination_uri,
            # Location must match that of the source table.
            location="asia-south1",
            job_config=job_config,
        )  
        return "Job with ID {} started exporting data from {}.{} to {}".format(extract_job.job_id, dataset_name, table_name, destination_uri)

在requirements.txt中,我提供了如下内容

google-cloud-bigquery

我的云函数将从一个pub子主题触发,该子主题创建一个事件,一旦我需要从中提取数据的大查询表被加载。

2021-02-13T11:23:38.518815ZCloud FunctionsUpdateFunctionasia-south1:xxxx@xxxx.com {@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, methodName: google.cloud.functions.v1.CloudFunctionsService.UpdateFunction, resourceName: projects/whr-asia-datalake-nonprod/locations/asia-south1/functions/Consumer_Extract_Bigquery, serviceName: cloudfunctions.google…
{@type: type.googleapis.com/google.cloud.audit.AuditLog, authenticationInfo: {…}, methodName: google.cloud.functions.v1.CloudFunctionsService.UpdateFunction, resourceName: projects/whr-asia-datalake-nonprod/locations/asia-south1/functions/Consumer_Extract_Bigquery, serviceName: cloudfunctions.google…

我可以通过在main.py中添加下面的内容来解决这个问题

# Imports the BigQuery client library
from google.cloud import bigquery
def extract_data(event, context):
 # Replace these values according to your project
    project_name = "whr-asia-datalake-nonprod"
    bucket_name = "whr-asia-datalake-dev-standard/outbound/Adobe/"
    dataset_name = "WHR_DATALAKE"
    table_name = "CONSUMER_EXTRACT"
    destination_uri = "gs://{}/{}".format(bucket_name,"Consumer_master.csv")
    bq_client = bigquery.Client(project=project_name)
    dataset = bq_client.dataset(dataset_name, project=project_name)
    table_to_export = dataset.table(table_name)
    job_config = bigquery.job.ExtractJobConfig()
    extract_job = bq_client.extract_table(
    table_to_export,
    destination_uri,
    # Location must match that of the source table.
    location="asia-south1",
    job_config=job_config,
    )
    return "Job with ID {} started exporting data from {}.{} to {}".format(extract_job.job_id, dataset_name, table_name, destination_uri)

并在requirements.txt中添加以下内容

google-cloud-bigquery==1
google-cloud-bigquery-datatransfer==1

共有1个答案

彭修筠
2023-03-14

我终于成功地做到了这一点。请在下面找到将通过酒吧子事件触发的云函数中的代码。

from google.cloud import bigquery
def extract_data(event, context):
 # Replace these values according to your project
    project_name = "whr-asia-datalake-nonprod"
    bucket_name = "whr-asia-datalake-dev-standard/outbound/Adobe/"
    dataset_name = "WHR_DATALAKE"
    table_name = "C4C_CONSUMER_CURATED"
    destination_uri = "gs://{}/{}".format(bucket_name,"Consumer_master_test.txt")
    bq_client = bigquery.Client(project=project_name)
    dataset = bq_client.dataset(dataset_name, project=project_name)
    table_to_export = dataset.table(table_name)
    job_config = bigquery.job.ExtractJobConfig()
    job_config.field_delimiter = "|"
    job_config.print_header = True

    extract_job = bq_client.extract_table(
    table_to_export,
    destination_uri,
    # Location must match that of the source table.
    location="asia-south1",
    job_config=job_config,
    )
    return "Job with ID {} started exporting data from {}.{} to {}".format(extract_job.job_id, dataset_name, table_name, destination_uri)

我能够为BigQuery.job.ExtractJobConfig提供其他属性,如管道分隔符和标头。

感谢@Maxim。你的帖子帮了我大忙。

 类似资料:
  • 致命错误:无法在第9行的E:\wamp1\wamp\www\sample.php中重新声明关闭()(先前在E:\wamp1\wamp\www\sample.php: 1中声明) 当我运行这个脚本时,它说不能在第9行中重新声明近()(以前在第1行中被标记)。 即使出现错误,与和相关的值也会传递给css。我在这里做错了什么?我正在调用第9行中的函数。有什么帮助吗?

  • 我知道有很多问题与类似的问题,但我一直在寻找答案,仍然无法找到我的问题。我已经尝试了几种方法来解决这个问题,但我找不到任何解决方案。。。 我代码的一部分:(我不会在其他任何地方使用这个函数) 我得到以下信息: 致命错误:无法在第20行的C:\wamp64\www\myProject-dev\Public\cajas\reposiciones\controller3.php:20中重新声明Valid

  • 我得到以下指定错误, 错误:(115)***Android NDK:正在中止。停下来。错误:执行任务“:un7zip:CompileReleAsendk”失败。 com.android.ide.common.process.processException:使用参数{ndk_project_path=null app_build_script=e:\apprizort\rizortCardboar

  • 当试图从我的wsdl生成类时,我有以下错误: 无法执行目标组织。jvnet。jaxb2。maven2:maven-jaxb2-plugin:0.12.3:在hblws项目上生成(CreateWebServiceAccountV1)。测试:执行目标组织的CreateWebServiceAccountV1。jvnet。jaxb2。maven2:maven-jaxb2-plugin:0.12.3:生成失

  • 试图构建一个简单的Vite项目,其中包含tailwindcss,但出现以下错误,有什么想法吗?

  • 我已经使用Java创建了一个由30个节点组成的链表。每个节点在实例化时被分配一个随机布尔值。 我希望为每个节点分配它自己的随机布尔方法/函数/规则,它接受三个布尔参数并返回结果: 我知道有256条这样的规则可供选择(2^2^3);我如何生成所有256个可能的规则而不手动键入它们?