AWS Glue, crawlers and issue with money datatype

0

I'm using a AWS Glue crawler for a RDS Aurora PostgreSQL, the table contains some columns with the money datatype, the crawler create the table with those columns as double.

AWSGlueDataCatalog_node1652381535100 = glueContext.create_dynamic_frame.from_catalog( database="tmp_db", table_name="postgres_public_list", transformation_ctx="AWSGlueDataCatalog_node1652381535100",)

But then when I start to working on the AWS Glue, any action, even a simple AWSGlueDataCatalog_node1652381535100.count() gives me this kind of error:

... Caused by: org.postgresql.util.PSQLException: Bad value for type double : 2,400.00 ...

Doesn't matter if I try to change the columns datatype to string, keeps saying the same error.

Any ideas how to solve this issue?

alcom
질문됨 2년 전234회 조회
1개 답변
0

Hello,

I would like to inform you that MONEY[] is not supported due to the JDBC driver for PostgreSQL can’t handle those types properly. To process this kind of data, please cast the column to decimal type and make sure to verify it using printschema. B

For dynamic frame you can use Applymapping:

## To verify the datatype of the column
datasource0.printtSchema()

## Cast it to decimal using ApplyMapping
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("v1", "string", "v1", "string"),("XX_threshold", "double", "XX_threshold", "decimal(25,10)")], transformation_ctx = "applymapping1")

##Verify the schma if it is counted to Decimal or not.
applymapping1.printSchema()

applymapping1.toDF().show()

For dataframe you can use cast function:

from pyspark.sql.types import *

df=datasource0.toDF()
df2 = df.withColumn("age",col("age").cast("decimal(25,10)"))
df2.printSchema()
df2.show()
AWS
답변함 2년 전
  • Thank you your response. However this doesn't work, I tried the ApplyMapping before (even casting to string), and executing applymapping1.toDF().show() gives me the same error:

    ... Caused by: org.postgresql.util.PSQLException: Bad value for type double : ...

    Is like even doing transformations AWS Glue keeps the original datatype from the crawler, at least thats the behaviour that I experience until now.

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

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

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

관련 콘텐츠