我正尝试使用toDF
和fromDF
函数(https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-extensions-dynamic-frame.html#aws-glue-api-crawler-pyspark-extensions-dynamic-frame-fromDF)将数据帧转换为动态帧,如下所示:
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)
## @type: DataSource
## @args: [database = "test-3", table_name = "test", transformation_ctx = "datasource0"]
## @return: datasource0
## @inputs: []
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "test-3", table_name = "test", transformation_ctx = "datasource0")
foo = datasource0.toDF()
bar = DynamicFrame.fromDF(foo, glueContext, "bar")
但是,我在网上遇到了一个错误:
bar = DynamicFrame.fromDF(foo, glueContext, "bar")
错误提示:
NameError: name 'DynamicFrame' is not defined
我尝试了通常的谷歌搜索,但没有成功,我无法从其他示例中看出我做错了什么。有人知道我为什么收到此错误以及如何解决该错误吗?
答案 0 :(得分:1)
from awsglue.dynamicframe import DynamicFrame
导入DynamicFrame
答案 1 :(得分:0)
您需要从awsglue.dynamic框架包中导入动态框架模块。
from awsglue.dynamicframe import DynamicFrame
AWS Glue ETL文档随附的示例中缺少很多东西。
但是,您可以参考以下github存储库,其中包含许多使用Glue ETL执行基本任务的示例: