sarutak opened a new pull request #31442:
URL: https://github.com/apache/spark/pull/31442


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section 
is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster 
reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class 
hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other 
DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This PR change sthe type mapping for `money` and `money[]`  types for 
PostgreSQL.
   Currently, those types are tried to convert to `DoubleType` and `ArrayType` 
of `double` respectively.
   But the JDBC driver seems not to be able to handle those types properly.
   
   https://github.com/pgjdbc/pgjdbc/issues/100
   https://github.com/pgjdbc/pgjdbc/issues/1405
   
   Due to these issue, we can get the error like as follows.
   
   money type.
   ```
   [info]   org.apache.spark.SparkException: Job aborted due to stage failure: 
Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 
0.0 (TID 0) (192.168.1.204 executor driver): org.postgresql.util.PSQLException: 
Bad value for type double : 1,000.00
   [info]       at 
org.postgresql.jdbc.PgResultSet.toDouble(PgResultSet.java:3104)
   [info]       at 
org.postgresql.jdbc.PgResultSet.getDouble(PgResultSet.java:2432)
   [info]       at 
org.apache.spark.sql.execution.datasources.jdbc.JdbcUtils$.$anonfun$makeGetter$5(JdbcUtils.scala:418)
   ```
   
   money[] type.
   ```
   [info]   org.apache.spark.SparkException: Job aborted due to stage failure: 
Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 
0.0 (TID 0) (192.168.1.204 executor driver): org.postgresql.util.PSQLException: 
Bad value for type double : $2,000.00
   [info]       at 
org.postgresql.jdbc.PgResultSet.toDouble(PgResultSet.java:3104)
   [info]       at 
org.postgresql.jdbc.ArrayDecoding$5.parseValue(ArrayDecoding.java:235)
   [info]       at 
org.postgresql.jdbc.ArrayDecoding$AbstractObjectStringArrayDecoder.populateFromString(ArrayDecoding.java:122)
   [info]       at 
org.postgresql.jdbc.ArrayDecoding.readStringArray(ArrayDecoding.java:764)
   [info]       at org.postgresql.jdbc.PgArray.buildArray(PgArray.java:310)
   [info]       at org.postgresql.jdbc.PgArray.getArrayImpl(PgArray.java:171)
   [info]       at org.postgresql.jdbc.PgArray.getArray(PgArray.java:111)
   ```
   
   For money type, a known workaround is to treat it as string so this PR do it.
   For money[], however, there is no reasonable workaround so this PR remove 
the support.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   This is a bug.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as 
the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to 
the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes. As of this PR merged, money type is mapped to `StringType` rather than 
`DoubleType` and the support for money[] is stopped.
   For money type, if the value is less than one thousand,  `$100.00` for 
instance, it works so I also updated the migration guide.
   On the other hand, money[] seems not to work with any value but mentioned in 
the migration guide just in case.
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   New test.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to