[
https://issues.apache.org/jira/browse/FLINK-6237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15953533#comment-15953533
]
ASF GitHub Bot commented on FLINK-6237:
---------------------------------------
Github user fhueske commented on a diff in the pull request:
https://github.com/apache/flink/pull/3660#discussion_r109424139
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/codegen/calls/ScalarOperators.scala
---
@@ -911,6 +911,64 @@ object ScalarOperators {
}
}
+ def generateRand(
+ randField: String,
+ seedExpr: GeneratedExpression,
+ resultType: TypeInformation[_])
+ : GeneratedExpression = {
+ val resultTerm = newName("result")
+ val resultTypeTerm = primitiveTypeTermForTypeInfo(resultType)
+ val randCode = if (seedExpr != null) {
+ s"""
+ |if ($randField == null) {
+ | ${seedExpr.code}
+ | $randField = new java.util.Random(${seedExpr.resultTerm});
+ |}
+ |$resultTypeTerm $resultTerm = $randField.nextDouble();
+ """.stripMargin
+ } else {
+ s"""
+ |if ($randField == null) {
+ | $randField = new java.util.Random();
+ |}
+ |$resultTypeTerm $resultTerm = $randField.nextDouble();
+ """.stripMargin
+ }
+
+ GeneratedExpression(resultTerm, GeneratedExpression.NEVER_NULL,
randCode, resultType)
+ }
+
+ def generateRandInteger(
+ randField: String,
+ seedExpr: GeneratedExpression,
+ boundExpr: GeneratedExpression,
+ resultType: TypeInformation[_])
+ : GeneratedExpression = {
+ assert(boundExpr != null)
+ val resultTerm = newName("result")
+ val resultTypeTerm = primitiveTypeTermForTypeInfo(resultType)
+ val randCode = if (seedExpr != null) {
+ s"""
+ |if ($randField == null) {
--- End diff --
If we initialize `Random` before, we do not need this condition.
> support RAND and RAND_INTEGER on SQL
> ------------------------------------
>
> Key: FLINK-6237
> URL: https://issues.apache.org/jira/browse/FLINK-6237
> Project: Flink
> Issue Type: New Feature
> Components: Table API & SQL
> Reporter: godfrey he
> Assignee: godfrey he
>
> support RAND and RAND_INTEGER with and without seed on SQL.
> like:
> RAND([seed]),
> RAND_INTEGER([seed, ] bound)
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)