kasakrisz commented on code in PR #5182:
URL: https://github.com/apache/hive/pull/5182#discussion_r1575886634


##########
hplsql/src/main/java/org/apache/hive/hplsql/functions/FunctionDatetime.java:
##########
@@ -162,6 +174,35 @@ void toTimestamp(HplsqlParser.Expr_func_paramsContext ctx) 
{
     }
   }
 
+  /**
+   * FROM_UNIXTIME() function (convert seconds since 1970-01-01 00:00:00 to 
timestamp)
+   */
+  void fromUnixtime(HplsqlParser.Expr_func_paramsContext ctx) {
+    int cnt = BuiltinFunctions.getParamCount(ctx);
+    if (cnt == 0) {
+      evalNull();
+      return;
+    }
+    Var value = evalPop(ctx.func_param(0).expr());
+    if (value.type != Var.Type.BIGINT) {
+      Var newVar = new Var(Var.Type.BIGINT);
+      value = newVar.cast(value);
+    }
+    long epoch = value.longValue();
+    String format = "yyyy-MM-dd HH:mm:ss";
+    if (cnt > 1) {
+      format = 
Utils.unquoteString(evalPop(ctx.func_param(1).expr()).toString());
+    }
+    evalString(Utils.quoteString(new SimpleDateFormat(format).format(new 
Date(epoch * 1000))));

Review Comment:
   IIUC by reintroducing this function consecutive calls may return different 
results depending on which implementation is used: Hive or HPL/SQL
   
   IMHO it should be consistent.
   
   https://github.com/apache/hive/pull/4965/files#r1444226220
   



##########
hplsql/src/main/java/org/apache/hive/hplsql/functions/FunctionMisc.java:
##########
@@ -113,7 +155,9 @@ void currentUser(HplsqlParser.Expr_spec_funcContext ctx) {
   }
   
   public static Var currentUser() {
-    return new Var("CURRENT_USER()");
+    String currentUser = System.getProperty("user.name");
+    currentUser = Utils.quoteString(currentUser);
+    return new Var(currentUser);

Review Comment:
   Sorry, I'm missing something. IIUC instances of `Var` are the internal 
representations of an SQL literal. In case of string the single quote 
characters in the beginning and the end should be removed at parse time and 
also single quote characters part of the text should be unescaped.
   If the original SQL form of the literal is needed there is  
https://github.com/apache/hive/blob/1a969f6642d4081027040f97e6a689bf2e687db3/hplsql/src/main/java/org/apache/hive/hplsql/Var.java#L620-L631
   



##########
hplsql/src/main/java/org/apache/hive/hplsql/functions/FunctionMisc.java:
##########
@@ -59,6 +64,43 @@ public void register(BuiltinFunctions f) {
   void activityCount(HplsqlParser.Expr_spec_funcContext ctx) {
     evalInt(Long.valueOf(exec.getRowCount()));
   }
+
+  /**
+   * CAST function
+   */
+  void cast(HplsqlParser.Expr_spec_funcContext ctx) {
+    if (ctx.expr().size() != 1) {
+      evalNull();
+      return;
+    }

Review Comment:
   If it should not be removed why not consider reverting HIVE-27492 ?



##########
hplsql/src/main/java/org/apache/hive/hplsql/Expression.java:
##########
@@ -565,7 +575,11 @@ public void 
operatorConcatSql(HplsqlParser.Expr_concatContext ctx) {
     sql.append("CONCAT(");
     int cnt = ctx.expr_concat_item().size();
     for (int i = 0; i < cnt; i++) {
-      sql.append(evalPop(ctx.expr_concat_item(i)).toString());
+      String concatStr = evalPop(ctx.expr_concat_item(i)).toString();
+      if (!concatStr.startsWith("'")) {

Review Comment:
   How about
   ```
   SELECT '#' || TRIM(''' Hello ') || '#';
   ```
   trim result is: `' Hello`



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

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