Github user DaveBirdsall commented on a diff in the pull request:
https://github.com/apache/trafodion/pull/1444#discussion_r168606746
--- Diff: core/sql/exp/exp_function.cpp ---
@@ -2501,6 +2518,100 @@ ex_expr::exp_return_type
ExFunctionReverseStr::eval(char *op_data[],
return ex_expr::EXPR_OK;
};
+ex_expr::exp_return_type ex_function_sleep::eval(char *op_data[],
+ CollHeap* heap,
+ ComDiagsArea** diagsArea)
+{
+ Int32 sec = 0;
+ switch (getOperand(1)->getDatatype())
+ {
+ case REC_BIN8_SIGNED:
+ sec = *(Int8 *)op_data[1] ;
+ if(sec < 0 )
+ {
+ ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ *(*diagsArea) << DgString0("SLEEP");
+ return ex_expr::EXPR_ERROR;
+ }
+ sleep(sec);
+ *(Int64 *)op_data[0] = 1;
+ break;
+
+ case REC_BIN16_SIGNED:
+ sec = *(short *)op_data[1] ;
+ if(sec < 0 )
+ {
+ ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ *(*diagsArea) << DgString0("SLEEP");
+ return ex_expr::EXPR_ERROR;
+ }
+ sleep(sec);
+ *(Int64 *)op_data[0] = 1;
+ break;
+
+ case REC_BIN32_SIGNED:
+ *(Lng32 *)sec = labs(*(Lng32 *)op_data[1]);
+ if(sec < 0 )
+ {
+ ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ *(*diagsArea) << DgString0("SLEEP");
+ return ex_expr::EXPR_ERROR;
+ }
+ sleep(sec);
+ *(Int64 *)op_data[0] = 1;
+ break;
+
+ case REC_BIN64_SIGNED:
+ sec = *(Int64 *)op_data[1];
+ if(sec < 0 )
+ {
+ ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ *(*diagsArea) << DgString0("SLEEP");
+ return ex_expr::EXPR_ERROR;
+ }
+ sleep(sec);
+ *(Int64 *)op_data[0] = 1;
+ break;
+
+ default:
+ ExRaiseSqlError(heap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ *(*diagsArea) << DgString0("SLEEP");
+ return ex_expr::EXPR_ERROR;
+ break;
+ }
+ //get the seconds to sleep
+ return ex_expr::EXPR_OK;
+}
+
+ex_expr::exp_return_type ex_function_unixtime::eval(char *op_data[],
+ CollHeap* heap,
+ ComDiagsArea** diagsArea)
+{
+ char *opData = op_data[1];
+ //if there is input value
+ if(opData[0] != 0 && getNumOperands() == 2)
+ {
+ struct tm* ptr;
+ char* r = strptime(opData, "%Y-%m-%d %H:%M:%S", ptr);
+ if( r == NULL)
--- End diff --
Should we also test for *r pointing to a null character? See the man page
for strptime. If there is garbage data after the seconds field, r will point to
the first byte of the garbage. I'm guessing we want to raise an error in that
case. Consider a test of the form "if ((r == NULL) || (*r != '\0'))"
---