You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2019/03/04 19:38:24 UTC

[asterixdb] branch master updated: [NO ISSUE][FUN] Fix type inference for random()

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new bf98bd6  [NO ISSUE][FUN] Fix type inference for random()
bf98bd6 is described below

commit bf98bd66223f135e0577d255ea48b598c8a71e37
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Fri Mar 1 17:42:27 2019 -0800

    [NO ISSUE][FUN] Fix type inference for random()
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - random(arg) return type should be nullable
    - fix documentation for random(arg) to match implementation
    
    Change-Id: Ifc46ddeaad5bb8999c4a869e7fbc0a5b3c5cde7c
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/3240
    Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../queries_sqlpp/misc/random/random.1.query.sqlpp         |  4 +++-
 .../resources/runtimets/results/misc/random/random.1.adm   |  2 +-
 .../asterix-doc/src/main/markdown/builtins/12_misc.md      |  3 +--
 .../org/apache/asterix/om/functions/BuiltinFunctions.java  |  2 +-
 .../asterix/om/typecomputer/impl/ADoubleTypeComputer.java  | 14 ++++++++++----
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/random/random.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/random/random.1.query.sqlpp
index bf35f87..7d6bb85 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/random/random.1.query.sqlpp
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/random/random.1.query.sqlpp
@@ -38,5 +38,7 @@
     select distinct value random(t)
   )),
 
-  "t5": [ random(missing) is missing, random(null) is null ]
+  "t5": [ random(missing) is missing, random(null) is null ],
+
+  "t6": [ random("ILLEGAL_TYPE") ]
 }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/random/random.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/random/random.1.adm
index 4be3e9a..9366d4e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/random/random.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/misc/random/random.1.adm
@@ -1 +1 @@
-{ "t1": 6, "t2": 6, "t3": 6, "t4": 6, "t5": [ true, true ] }
\ No newline at end of file
+{ "t1": 6, "t2": 6, "t3": 6, "t4": 6, "t5": [ true, true ], "t6": [ null ] }
\ No newline at end of file
diff --git a/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md b/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md
index dfb1b0b..df7cf8c 100644
--- a/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md
+++ b/asterixdb/asterix-doc/src/main/markdown/builtins/12_misc.md
@@ -87,8 +87,7 @@
  * Return Value:
     * A random number of type `double` between 0 and 1,
     * `missing` if the argument is a `missing` value,
-    * `null` if the argument is a `null` value,
-    * any other non-numeric input value will cause a type error.
+    * `null` if the argument is a `null` value or a non-numeric value.
 
  * Example:
 
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
index 623cf08..43896d0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java
@@ -1483,7 +1483,7 @@ public class BuiltinFunctions {
         addFunction(CREATE_QUERY_UID, ABinaryTypeComputer.INSTANCE, false);
         addFunction(UUID_CONSTRUCTOR, AUUIDTypeComputer.INSTANCE, true);
         addFunction(RANDOM, ADoubleTypeComputer.INSTANCE, false);
-        addFunction(RANDOM_WITH_SEED, ADoubleTypeComputer.INSTANCE, false);
+        addFunction(RANDOM_WITH_SEED, ADoubleTypeComputer.INSTANCE_NULLABLE, false);
 
         addFunction(DATE_CONSTRUCTOR, ADateTypeComputer.INSTANCE, true);
         addFunction(DATETIME_CONSTRUCTOR, ADateTimeTypeComputer.INSTANCE, true);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ADoubleTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ADoubleTypeComputer.java
index ec415e8..00301b6 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ADoubleTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ADoubleTypeComputer.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.om.typecomputer.impl;
 
 import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer;
+import org.apache.asterix.om.types.AUnionType;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -26,14 +27,19 @@ import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
 
 public class ADoubleTypeComputer extends AbstractResultTypeComputer {
 
-    public static final ADoubleTypeComputer INSTANCE = new ADoubleTypeComputer();
+    public static final ADoubleTypeComputer INSTANCE = new ADoubleTypeComputer(false);
 
-    private ADoubleTypeComputer() {
+    public static final ADoubleTypeComputer INSTANCE_NULLABLE = new ADoubleTypeComputer(true);
+
+    private final IAType type;
+
+    private ADoubleTypeComputer(boolean nullable) {
+        IAType t = BuiltinType.ADOUBLE;
+        type = nullable ? AUnionType.createNullableType(t) : t;
     }
 
     @Override
     protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
-        return BuiltinType.ADOUBLE;
+        return type;
     }
-
 }