gpt4 book ai didi

python - 全局名称 'bigquery' 未定义

转载 作者:行者123 更新时间:2023-12-05 07:29:54 25 4
gpt4 key购买 nike

我创建了一个谷歌数据流作业,但我一直收到未定义的全局名称“bigquery”,即使我已经导入了所需的变量。

这是我的导入列表:

from __future__ import absolute_import

import argparse
import logging
import ast
import json

import apache_beam as beam
from apache_beam.io import ReadFromText, WriteToText
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.options.pipeline_options import SetupOptions
from apache_beam.options.pipeline_options import StandardOptions
from google.cloud import bigquery

这是返回错误的类:

class CheckExistance(beam.DoFn):

def __init__(self, table):
self.table = table.replace(":", ".")

def process(self, element):

client = bigquery.Client()
date = element['date'].split(" ")[0]

query_job = client.query("""
QUERY """ % (self.table, date))

yield element

你们知道是什么导致了这个错误吗?顺便说一句,我只在将它部署到 google 的数据流作业时遇到此错误,它在本地运行良好。

编辑:

我能够通过将导入的位置更改为需要 bigquery 变量的函数内部来解决最初的问题,如下所示:

class CheckExistance(beam.DoFn):

def __init__(self, table):
self.table = table.replace(":", ".")

def process(self, element):
from google.cloud import bigquery
client = bigquery.Client()
date = element['date'].split(" ")[0]

query_job = client.query("""
QUERY""" % (self.table, date))

yield element

但现在我收到一条错误消息,指出“客户端”没有属性查询,即使我在数据流作业上的包是最新的并且它在本地运行也没有任何问题。

错误信息:

AttributeError: 'Client' object has no attribute 'query'

最佳答案

我猜你需要启用 BigQuery

资源/高级 Google 服务/启用 BigQuery

编辑:检查评论以查看故障排除、发现和有效的方法。

关于python - 全局名称 'bigquery' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com