python-3.x - Pyspark:使用 google bigquery 连接器使用 aws 胶水作业将嵌套数据插入 bigquery 时出现问题
问题描述
我在使用 google bigquery 连接器使用 aws 胶水作业将嵌套数据插入 bigquery 时遇到问题
下面是我的大查询表方案
competition FLOAT NULLABLE
categories RECORD REPEATED
id INTEGER REQUIRED
在 aws 胶水的自定义转换中,我试图将 python dict 列表发送到如下类别:
[{"id":10004},{"id":10009},{"id":10301}]
我的数据框的架构类似于
root
|-- categories: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- id: integer (nullable = false)
我的代码
def MyTransform (glueContext, dfc) -> DynamicFrameCollection:
from pyspark.sql.types import ArrayType, StringType, StructType, IntegerType, StructField
from pyspark.sql.functions import udf
newdf = dfc.select(list(dfc.keys())[0]).toDF()
newdf = newdf.select("keyword", "spell","spell_type", \
"keyword_info.competition", "keyword_info.cpc", \
"keyword_info.search_volume", "keyword_info.categories");
newdf = newdf.withColumnRenamed('search_volume', 'volume')
udf_history_modification("history"))
udf_categories_modification = udf(lambda x: [{'id': id} for id in x], \
ArrayType(
StructType([
StructField("id", IntegerType(), True)
])
))
newdf = newdf.withColumn("categories", udf_categories_modification("categories"))
newcustomerdyc = DynamicFrame.fromDF(newdf, glueContext, "modifieddata")
return (DynamicFrameCollection({"CustomTransform0": newcustomerdyc}, glueContext))
请注意,类别是数据框列之一。此外,未嵌套的字段也会插入到 bigquery 中。
以下是错误:
Caused by: com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryException: Provided Schema does not match Table ml-training-231514:data_for_seo_test.au_2021_11. Field categories.id is missing in new schema
解决方案
推荐阅读
- javascript - Javascript“for in”无法获取嵌套对象(非标准键标识符)
- webpack - 需要 Babel "^7.0.0-0" 但在 CI 服务器上测试时加载了 "6.26.3"
- google-maps-api-3 - 如何在不应用图像或图标的标记上应用自定义 CSS 样式
- javascript - 更新查询中的 MongoDB $graphLookup
- java - 我想使用 Android KeyChain 来存储公钥和私钥
- java - 必需的字符串参数“姓”不存在
- c# - 一次将控制器操作请求限制为一个
- rust - 无法创建将字节切片转换为整数的通用函数,因为在编译时大小未知
- css - 改变侧边栏宽度的 CSS 是什么?
- node.js - 当用户将文档/图像附加到聊天机器人时如何遇到回复(使用对话流和通信构建)?