[
https://issues.apache.org/jira/browse/HIVE-25268?focusedWorklogId=612356&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-612356
]
ASF GitHub Bot logged work on HIVE-25268:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 20/Jun/21 06:52
Start Date: 20/Jun/21 06:52
Worklog Time Spent: 10m
Work Description: ashish-kumar-sharma commented on a change in pull
request #2409:
URL: https://github.com/apache/hive/pull/2409#discussion_r654886574
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDateFormat.java
##########
@@ -85,21 +87,31 @@ public ObjectInspector initialize(ObjectInspector[]
arguments) throws UDFArgumen
String fmtStr = getConstantStringValue(arguments, 1);
if (fmtStr != null) {
try {
- formatter = new SimpleDateFormat(fmtStr);
-
formatter.setCalendar(DateTimeMath.getTimeZonedProlepticGregorianCalendar());
+ if (timeZone == null) {
+ timeZone = SessionState.get() == null ? new
HiveConf().getLocalTimeZone() : SessionState.get().getConf()
Review comment:
Combine redundant code at line 121.
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDateFormat.java
##########
@@ -111,17 +123,18 @@ public Object evaluate(DeferredObject[] arguments) throws
HiveException {
// the function should support both short date and full timestamp format
// time part of the timestamp should not be skipped
Timestamp ts = getTimestampValue(arguments, 0, tsConverters);
+
if (ts == null) {
Date d = getDateValue(arguments, 0, dtInputTypes, dtConverters);
if (d == null) {
return null;
}
ts = Timestamp.ofEpochMilli(d.toEpochMilli(id), id);
}
-
-
- date.setTime(ts.toEpochMilli(id));
- String res = formatter.format(date);
+ Timestamp ts2 = TimestampTZUtil.convertTimestampToZone(ts, timeZone,
ZoneId.of("UTC"));
Review comment:
No need to convert first convert timeZone to UTC and UTC to timeZone.
Timestamp class internally use localDateTime which is timezone less and only
depict the timestamp.
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDateFormat.java
##########
@@ -111,17 +123,18 @@ public Object evaluate(DeferredObject[] arguments) throws
HiveException {
// the function should support both short date and full timestamp format
// time part of the timestamp should not be skipped
Timestamp ts = getTimestampValue(arguments, 0, tsConverters);
+
if (ts == null) {
Date d = getDateValue(arguments, 0, dtInputTypes, dtConverters);
Review comment:
You can also remove this line because it is already taken care as part
of timestamp.
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFDateFormat.java
##########
@@ -111,17 +123,18 @@ public Object evaluate(DeferredObject[] arguments) throws
HiveException {
// the function should support both short date and full timestamp format
// time part of the timestamp should not be skipped
Timestamp ts = getTimestampValue(arguments, 0, tsConverters);
+
if (ts == null) {
Date d = getDateValue(arguments, 0, dtInputTypes, dtConverters);
if (d == null) {
return null;
}
ts = Timestamp.ofEpochMilli(d.toEpochMilli(id), id);
}
-
-
- date.setTime(ts.toEpochMilli(id));
- String res = formatter.format(date);
+ Timestamp ts2 = TimestampTZUtil.convertTimestampToZone(ts, timeZone,
ZoneId.of("UTC"));
+ Instant instant = Instant.ofEpochSecond(ts2.toEpochSecond(),
ts2.getNanos());
+ ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant,
ZoneOffset.UTC);
+ String res = formatter.format(zonedDateTime);
Review comment:
Instead use ts.format(formatter)
--
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 612356)
Time Spent: 1.5h (was: 1h 20m)
> date_format udf doesn't work for dates prior to 1900 if the timezone is
> different from UTC
> ------------------------------------------------------------------------------------------
>
> Key: HIVE-25268
> URL: https://issues.apache.org/jira/browse/HIVE-25268
> Project: Hive
> Issue Type: Bug
> Components: UDF
> Affects Versions: 3.1.0, 3.1.1, 3.1.2, 4.0.0
> Reporter: Nikhil Gupta
> Assignee: Nikhil Gupta
> Priority: Major
> Labels: pull-request-available
> Fix For: 4.0.0
>
> Time Spent: 1.5h
> Remaining Estimate: 0h
>
> *Hive 1.2.1*:
> {code:java}
> select date_format('1400-01-14 01:00:00', 'yyyy-MM-dd HH:mm:ss z');
> +--------------------------+--+
> | _c0 |
> +--------------------------+--+
> | 1400-01-14 01:00:00 ICT |
> +--------------------------+--+
> select date_format('1800-01-14 01:00:00', 'yyyy-MM-dd HH:mm:ss z');
> +--------------------------+--+
> | _c0 |
> +--------------------------+--+
> | 1800-01-14 01:00:00 ICT |
> +--------------------------+--+
> {code}
> *Hive 3.1, Hive 4.0:*
> {code:java}
> select date_format('1400-01-14 01:00:00', 'yyyy-MM-dd HH:mm:ss z');
> +--------------------------+
> | _c0 |
> +--------------------------+
> | 1400-01-06 01:17:56 ICT |
> +--------------------------+
> select date_format('1800-01-14 01:00:00', 'yyyy-MM-dd HH:mm:ss z');
> +--------------------------+
> | _c0 |
> +--------------------------+
> | 1800-01-14 01:17:56 ICT |
> +--------------------------+
> {code}
> VM timezone is set to 'Asia/Bangkok'
--
This message was sent by Atlassian Jira
(v8.3.4#803005)