How to remove Unnamed column while creating dynamic frame from catalog options

0

Hi Team,

I have created a glue job which reading a table from glue data catalog and creating dynamic frame. But while running the job, it is throwing the below error. After checking the logs I saw it is not able create the dynamic frame due to the below error.

"Attribute name "Unnamed: 7" contains invalid character(s) among " ,;{}()\n\t=". Please use alias to rename it."

I am using the below statement to create dynamic frame. I want to avoid creating the unnamed columns during the creation of dynamic frame. Any help would be much appreciated. Thank you

demotable= glueContext.create_dynamic_frame.from_catalog( database="intraday", table_name="demo_table", push_down_predicate = "bus_dt = 20180117", transformation_ctx="demotable", )

  • Not sure how the table can have unnamed columns, sounds more likely that the data doesn't really match the table and DynamicFrame get confused. If you read using DataFrame (e.g. spark.sql()) it will enforce the table schema but not sure if it will read the data correctly. I would try to solve the underlying issue with the table/data.

質問済み 1年前766ビュー
1回答
0

o remove the unnamed column while creating a dynamic frame from the catalog options, you can use the ApplyMapping class from the awsglue.transforms module. This allows you to selectively keep the columns you want and exclude the unnamed columns.

Here's an example of how you can do this:

from awsglue.transforms import ApplyMapping

# Read the data from the catalog
demotable = glueContext.create_dynamic_frame.from_catalog(
    database="intraday",
    table_name="demo_table",
    push_down_predicate="bus_dt = 20180117",
    transformation_ctx="demotable"
)

# Define the schema mapping, excluding the unnamed column
mapping = [
    ("column1", "string", "column1", "string"),
    ("column2", "string", "column2", "string"),
    # Add all other columns that you want to keep, but exclude "Unnamed: 7"
]

# Apply the mapping
demotable_transformed = ApplyMapping.apply(frame=demotable, mappings=mapping, transformation_ctx="demotable_transformed")

# Continue to the code ....
profile picture
エキスパート
回答済み 1年前
  • Hi sdtslmn,

    Thanks for your response!

    The glue job is failing in the below step while creating the dynamic frame. Apply mapping is the next step but it is failing before that.

    Is there a way I can pass any parameter while creating the dynamic frame so that unnamed column gets excluded?

    Read the data from the catalog

    demotable = glueContext.create_dynamic_frame.from_catalog( database="intraday", table_name="demo_table", push_down_predicate="bus_dt = 20180117", transformation_ctx="demotable" )

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ