我有一个AWS Glue作业,它从这样的数据源读取:
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "dev-data", table_name = "contacts", transformation_ctx = "datasource0")
Run Code Online (Sandbox Code Playgroud)
但是,当我在动态帧上调用.toDF()时,标头为'col0','col1','col2'等,而我的实际标头位于数据帧的第一行。
注意-我无法手动设置它们,因为数据源中的列是可变的,并且在循环中遍历这些列以设置它们会导致错误,因为您必须多次设置相同的dataframe变量,这种粘合可以t处理。
从数据源读取时如何捕获标头?
我有两个试图使用PySpark 2.3.0加入的具有空值的数据框:
dfA:
# +----+----+
# |col1|col2|
# +----+----+
# | a|null|
# | b| 0|
# | c| 0|
# +----+----+
Run Code Online (Sandbox Code Playgroud)
dfB:
# +----+----+----+
# |col1|col2|col3|
# +----+----+----+
# | a|null| x|
# | b| 0| x|
# +----+----+----+
Run Code Online (Sandbox Code Playgroud)
可以使用以下脚本创建数据框:
dfA = spark.createDataFrame(
[
('a', None),
('b', '0'),
('c', '0')
],
('col1', 'col2')
)
dfB = spark.createDataFrame(
[
('a', None, 'x'),
('b', '0', 'x')
],
('col1', 'col2', 'col3')
)
Run Code Online (Sandbox Code Playgroud)
加入通话:
dfA.join(dfB, dfB.columns[:2], how='left').orderBy('col1').show()
Run Code Online (Sandbox Code Playgroud)
结果:
# +----+----+----+
# |col1|col2|col3|
# …Run Code Online (Sandbox Code Playgroud) 我有一个数据帧:
# +---+--------+---------+
# | id| rank | value |
# +---+--------+---------+
# | 1| A | 10 |
# | 2| B | 46 |
# | 3| D | 8 |
# | 4| C | 8 |
# +---+--------+---------+
Run Code Online (Sandbox Code Playgroud)
我想按价值排序,然后排名.这看起来应该很简单,但是我没有看到它是如何在文档中完成的,或者是Pyspark的SO,仅用于R和Scala.
这是排序后应该看的样子,.show()应该打印:
# +---+--------+---------+
# | id| rank | value |
# +---+--------+---------+
# | 4| C | 8 |
# | 3| D | 8 |
# | 1| A | 10 |
# | 2| B …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用cloudformation模板创建一个与胶粘事件匹配的Cloudwatch事件规则,并以SNS主题为目标向其发送消息,我可以在cloudwatch控制台中创建它,但是不能通过cloud watch模板创建它。这是我的活动规则:
NotifyEventRule:
Type: AWS::Events::Rule
Properties:
Name: JobNotifyEvent
Description: Notification event on job status change.
EventPattern:
source:
- aws.glue
account:
- !Ref AWS::AccountId
detail-type:
- Glue Job State Change
detail:
jobName:
- !Ref GlueJobName
Targets:
-
Arn:
Ref: "JobNotificationTopic"
Id:
Ref: "JobNotificationTopicName"
InputTransformer:
InputTemplate: "Job finished in the following state: <state>."
InputPathsMap:
state: "$.detail.state"
Run Code Online (Sandbox Code Playgroud)
问题出在InputTemplate上。我得到的错误是:
“,目标JobNotificationTopic的InputTemplate无效:[源:(String)”作业在以下状态下完成:null。“; 行:1,列:10]。(服务:AmazonCloudWatchEvents;状态代码:400;错误代码:ValidationException;请求ID:12345678 ...)
看来<state>可能是问题所在。