Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
Google cloud platform Apache Beam无法识别脚本GCP中的全局函数_Google Cloud Platform_Google Cloud Dataflow_Apache Beam - Fatal编程技术网

Google cloud platform Apache Beam无法识别脚本GCP中的全局函数

Google cloud platform Apache Beam无法识别脚本GCP中的全局函数,google-cloud-platform,google-cloud-dataflow,apache-beam,Google Cloud Platform,Google Cloud Dataflow,Apache Beam,我正在做一个项目,在GCP上创建一个流处理预测引擎。我主要是从这次回购中学习。然而,当我尝试执行脚本blogposts/got_emotional/4_streaming_pipeline/streaming_tweet.py时,我总是出错 NameError: name 'estimate' is not defined [while running 'generatedPtransform-129'] 我的函数如下所示 from __future__ import absolute_imp

我正在做一个项目,在GCP上创建一个流处理预测引擎。我主要是从这次回购中学习。然而,当我尝试执行脚本blogposts/got_emotional/4_streaming_pipeline/streaming_tweet.py时,我总是出错

NameError: name 'estimate' is not defined [while running 'generatedPtransform-129']
我的函数如下所示

from __future__ import absolute_import

import argparse
import datetime
import json
import logging

import numpy as np

import apache_beam as beam
import apache_beam.transforms.window as window
from apache_beam.io.gcp.bigquery import parse_table_schema_from_json
from apache_beam.options.pipeline_options import StandardOptions, GoogleCloudOptions, SetupOptions, PipelineOptions
from apache_beam.transforms.util import BatchElements

from googleapiclient import discovery

def init():
    ........

def estimate_cmle():

   init()
   .....

def estimate(instances):

   estimate_cmle()
   ......


def run(argv=None):
....

   output = (lines
                     | 'assign window key' >> beam.WindowInto(window.FixedWindows(10))
                     | 'batch into n batches' >> BatchElements(min_batch_size=49, max_batch_size=50)
                     | 'predict sentiment' >> beam.FlatMap(lambda messages: estimate(messages))
                     )

.....


f __name__ == '__main__':
    logging.getLogger().setLevel(logging.INFO)
    run()
这就是beam似乎无法识别estimate函数的地方,尽管我正在使用相同的脚本创建它

编辑

尝试使用
beam.FlatMap(估计值)
时出现错误

name 'estimate_cmle' is not defined [while running 'generatedPtransform-1208']
看看这两个部分:

函数定义

def estimate(instances):
......
函数调用

beam.FlatMap(lambda messages: estimate(messages,estimate_cmle))
您的调用需要一个具有2个参数的函数,而您声明的函数只有一个参数。python脚本只包含一个带有1个参数的估计值,并且没有定义带有2个参数的函数


例如,在repo中,调用只包含1个参数,因此它可以工作。如果要解决这个问题,那么它应该可以工作了

很抱歉,这是我在尝试的东西。即使没有争论,我也会遇到同样的错误。您是否尝试过使用beam.FlatMap(估计)而不是beam.FlatMap(lambda消息:估计(消息))?我尝试过。现在它给了我estimate_cmle not found:(您在哪里以及如何使用estimate_cmle?在estimate函数中,estimate_cmle用于调用cmle上的模型API以获得预测您使用的是哪个python版本?我在github上看到了代码,它应该可以工作