MaxGekk opened a new pull request #32120:
URL: https://github.com/apache/spark/pull/32120


   ### What changes were proposed in this pull request?
   1. Extend `IntervalUtils` methods: `toYearMonthIntervalString` and 
`toDayTimeIntervalString` to support formatting of year-month/day-time 
intervals in Hive style. The methods get new parameter style which can have to 
values; `HIVE_STYLE` and `ANSI_STYLE`.
   2. Invoke `toYearMonthIntervalString` and `toDayTimeIntervalString` from the 
`Cast` expression with the `style` parameter is set to `ANSI_STYLE`.
   3. Invoke `toYearMonthIntervalString` and `toDayTimeIntervalString` from 
`HiveResult` with `style` is set to `HIVE_STYLE`.
   
   ### Why are the changes needed?
   The `spark-sql` shell formats its output in Hive style by using 
`HiveResult.hiveResultString()`. The changes are needed to match Hive behavior. 
For instance,
   
   Hive:
   ```sql
   0: jdbc:hive2://localhost:10000/default> select timestamp'2021-01-01 
01:02:03.000001' - date'2020-12-31';
   +-----------------------+
   |          _c0          |
   +-----------------------+
   | 1 01:02:03.000001000  |
   +-----------------------+
   ``` 
   
   Spark before the changes:
   ```sql
   spark-sql> select timestamp'2021-01-01 01:02:03.000001' - date'2020-12-31';
   INTERVAL '1 01:02:03.000001' DAY TO SECOND
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. After the changes:
   ```sql
   spark-sql> select timestamp'2021-01-01 01:02:03.000001' - date'2020-12-31';
   1 01:02:03.000001000
   ```
   
   ### How was this patch tested?
   1. Added new tests to `IntervalUtilsSuite`:
   ```
   $  build/sbt "test:testOnly *IntervalUtilsSuite"
   ```
   2. Modified existing tests in `HiveResultSuite`:
   ```
   $  build/sbt -Phive-2.3 -Phive-thriftserver "testOnly *HiveResultSuite"
   ```
   3. By running cast tests:
   ```
   $ build/sbt "testOnly *CastSuite*"
   ```


-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to