zengxl created HIVE-25559: ----------------------------- Summary: to_unix_timestamp udf result incorrect Key: HIVE-25559 URL: https://issues.apache.org/jira/browse/HIVE-25559 Project: Hive Issue Type: Bug Components: UDF Affects Versions: 3.1.2 Reporter: zengxl Assignee: zengxl
when I use *unix_timestamp* udf,What this function actually calls is *to_unix_timestamp* udf.This return result is incorrect.Here is my SQL: {code:java} //代码占位符 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/local/hive/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/usr/local/hadoop-3.2.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Hive Session ID = 3a04a9cf-1fdb-4017-a4bb-14763a3163c7Logging initialized using configuration in file:/usr/local/hive/conf/hive-log4j2.properties Async: true Hive Session ID = 92ca916b-cfde-43b5-bd86-10d50ff7d861 Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases. hive> select unix_timestamp('2021-09-24 00:00:00'); OK 1632441600 Time taken: 3.729 seconds, Fetched: 1 row(s) {code} We see GenericUDFToUnixTimeStamp class code,I found that the fixed time zone is set {color:#de350b}UTC{color}, not according to the user time zone.Time zones vary with users,My time zone is {color:#de350b}Asia/Shanghai{color} .Therefore, the function should use the user time zone Here is the code I modified {code:java} //代码占位符 SessionState ss = SessionState.get(); String timeZoneStr = ss.getConf().get("hive.local.time.zone"); if (timeZoneStr == null || timeZoneStr.trim().isEmpty() || timeZoneStr.toLowerCase().equals("local")) { timeZoneStr = System.getProperty("user.timezone"); } formatter.setTimeZone(TimeZone.getTimeZone(timeZoneStr)); {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)