AWSGlue作业有时无法解析给定的输入列'xxx'
创始人
2024-09-25 18:02:56
0

可能问题的根源是在Glue中定义的表模式与数据源中实际存在的模式不匹配。为了解决这个问题,你可以使用代码来指定输入源和输出表的模式。下面是一个源于GitHub上的代码示例:

from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from pyspark.sql import SparkSession
from pyspark.sql.types import StructType, StructField, IntegerType, StringType, DoubleType

glueContext = GlueContext(SparkContext.getOrCreate())
spark = glueContext.spark_session

# Here is where you specify the input source and output S3 path
input_job_path = "s3://my-bucket/input/"
output_job_path = "s3://my-bucket/output/"

input_schema = StructType([
    StructField("id", IntegerType(), True),
    StructField("name", StringType(), True),
    StructField("value", DoubleType(), True)])

# Read data from S3
dynamic_frame = glueContext.create_dynamic_frame_from_options(
    connection_type="s3",
    format="csv",
    connection_options={
        "path": input_job_path,
        "recurse":True},
    format_options={
        "withHeader": True,
        "separator": ","},
    schema=input_schema)

# Convert dynamic frame to data frame
df = dynamic_frame.toDF()

# Apply transformations to data frame
df_transformed = 

output_schema = StructType([
    StructField("new_id", IntegerType(), True),
    StructField("first_name", StringType(), True),
    StructField("last_name", StringType(), True),
    StructField("final_value", DoubleType(), True)])

# Write back to S3 with new schema
df_transformed.write.mode("overwrite").format("parquet").option("compression", "snappy").save(output_job_path)

# Glue Catalog metadata for new table schema
spark.catalog.refreshTable("default.new_table_name")
df_output = spark.read.format("parquet").load(output_job_path)

# Rename columns and convert to Glue dynamic frame
df_output_transformed = df_output

相关内容

热门资讯

现场直击!决战卡五星有挂吗(辅... 决战卡五星有挂吗 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理由: 1...
第七分钟开挂!欢乐对决破解版免... 第七分钟开挂!欢乐对决破解版免内购,闲聚app辅助软件,科技教程-2026最新版本欢乐对决破解版免内...
受玩家影响!潮汕汇鱼虾蟹辅助(... 受玩家影响!潮汕汇鱼虾蟹辅助(辅助挂)一直确实有挂(有挂教材)-哔哩哔哩《详细加薇136704302...
第8分钟开挂!微乐小程序辅助脚... 第8分钟开挂!微乐小程序辅助脚本平台,九九山城插件程序,第三方教程-2026最新版本所有人都在同一条...
这一问题亟待解决!网易棋牌辅助... 【亲,网易棋牌辅助器 这款游戏可以开挂的,确实是有挂的,很多玩家在这款网易棋牌辅助器中打牌都会发现很...
四分钟开挂!浙江茶园辅助,决战... 四分钟开挂!浙江茶园辅助,决战卡五星辅助,存在挂教程-2026最新版本在进入决战卡五星辅助辅助挂后,...
据相关数据显示!兴动互娱辅助脚... 您好:这款兴动互娱辅助脚本游戏是可以开挂的,确实是有挂的,很多玩家在这款兴动互娱辅助脚本游戏中打牌都...
第五分钟开挂!皇豪互众控制系统... 第五分钟开挂!皇豪互众控制系统下载,微信中至有辅助吗,攻略教程-2026最新版本1、点击下载安装,皇...
现就发布提示!一起宁德游戏万能... 现就发布提示!一起宁德游戏万能辅助器(辅助挂)果然有挂(有挂绝活儿)-哔哩哔哩;无需打开直接搜索打开...
第六分钟开挂!胡乐情怀宜春开挂... 第六分钟开挂!胡乐情怀宜春开挂,创思维激k辅助控制器,分享教程-2026最新版本1、上手简单,内置详...