[ 
https://issues.apache.org/jira/browse/PHOENIX-1516?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14255215#comment-14255215
 ] 

James Taylor commented on PHOENIX-1516:
---------------------------------------

Thanks, [~lhofhansl]. Looks good. A couple of minor items:
- For the RandomFunction, but the initialization of random in a separate init() 
method which is called after readFields() which is the entry point of 
construction for server-side usage (i.e. if RAND() is used in a WHERE clause):
{code}
+@BuiltInFunction(name = RandomFunction.NAME, args = 
{@Argument(allowedTypes={PLong.class},defaultValue="null",isConstant=true)})
+public class RandomFunction extends ScalarFunction {
+    public static final String NAME = "RAND";
+    private final Random random;
+    private final boolean hasSeed;
+    private Double current;
+
+    public RandomFunction(List<Expression> children) {
+        super(children);
+        init();
+    }
+
+    @Override
+    public void readFields(DataInput input) throws IOException {
+        super.readFields(input);
+        init();
+    }
+
+    private void init() {
+        Number seed = (Number)((LiteralExpression)children.get(0)).getValue();
+        random = seed == null ? new Random() : new Random(seed.longValue());
+        hasSeed = seed != null;
+        current = random.nextDouble();
+    }
{code}
- For the call to reset in PhoenixResultSet, call it after the next() call if 
currentRow != null for consistency with when it's called on the server-side:
{code}
     @Override
     public boolean next() throws SQLException {
         checkOpen();
+        if (currentRow != BEFORE_FIRST) {
+            rowProjector.reset();
+        }
         try {
             currentRow = scanner.next();
         } catch (RuntimeException e) {
{code}
- Would be good to have a test that uses RAND in the WHERE clause, but I don't 
know how you'd validate it. Maybe through a subquery as Julian suggested before?

> Add RANDOM built-in function
> ----------------------------
>
>                 Key: PHOENIX-1516
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1516
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Lars Hofhansl
>            Assignee: Lars Hofhansl
>         Attachments: 1516-v2.txt, 1516.txt
>
>
> I often find it useful to generate some rows with random data.
> Here's a simple RANDOM() function that we could use for that.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to