You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@hive.apache.org by "amansinha100 (via GitHub)" <gi...@apache.org> on 2023/08/18 01:57:07 UTC
[GitHub] [hive] amansinha100 commented on a diff in pull request #4615: HIVE-25576: Configurable datetime formatter for unix_timestamp, from_unixtime
amansinha100 commented on code in PR #4615:
URL: https://github.com/apache/hive/pull/4615#discussion_r1297900381
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UnixTimeFormatter.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.type.TimestampTZUtil;
+import org.apache.hadoop.hive.conf.HiveConf;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
+import java.time.ZoneId;
+import java.util.concurrent.ExecutionException;
+
+public abstract class UnixTimeFormatter<T> {
+
+ enum Type {
+ SIMPLE {
+ @Override
+ UnixTimeFormatter<?> newFormatter(ZoneId zone) {
+ return new UnixTimeSimpleDateFormatter(zone);
+ }
+ }, DATETIME {
+ @Override
+ UnixTimeFormatter<?> newFormatter(final ZoneId zone) {
+ return new UnixTimeDateTimeFormatter(zone);
+ }
+ };
+
+ abstract UnixTimeFormatter<?> newFormatter(ZoneId zone);
+ }
+
+ public static UnixTimeFormatter<?> from(Configuration conf) {
+ ZoneId zoneId = TimestampTZUtil.parseTimeZone(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_LOCAL_TIME_ZONE));
+ Type type = Type.valueOf(HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_DATETIME_FORMATTER).toUpperCase());
+ return type.newFormatter(zoneId);
+ }
+
+ protected final ZoneId zoneId;
+ private final LoadingCache<String, T> formatters;
Review Comment:
In the typical case, do we expect the cache to be populated with more than 2 instances ? I was thinking if it would be sufficient to keep 2 separate member variables for each of the formatters. If we absolutely need the LoadingCache , a comment to justify would be useful.
##########
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/UnixTimeFormatter.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.ql.udf.generic;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.common.type.TimestampTZUtil;
+import org.apache.hadoop.hive.conf.HiveConf;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
+import java.time.ZoneId;
+import java.util.concurrent.ExecutionException;
+
+public abstract class UnixTimeFormatter<T> {
+
+ enum Type {
+ SIMPLE {
+ @Override
+ UnixTimeFormatter<?> newFormatter(ZoneId zone) {
Review Comment:
nit: add final for the zone to be consistent with the DATETIME newFormatter method.
--
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.
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@hive.apache.org
For additional commands, e-mail: gitbox-help@hive.apache.org