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.

질문됨 일 년 전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
전문가
답변함 일 년 전
  • 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" )

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠