tanclary commented on code in PR #3720:
URL: https://github.com/apache/calcite/pull/3720#discussion_r1517138851


##########
site/_docs/reference.md:
##########
@@ -2813,6 +2813,7 @@ In the following:
 | b | PARSE_TIMESTAMP(format, string[, timeZone])    | Uses format specified 
by *format* to convert *string* representation of timestamp to a TIMESTAMP WITH 
LOCAL TIME ZONE value in *timeZone*
 | h s | PARSE_URL(urlString, partToExtract [, keyToExtract] ) | Returns the 
specified *partToExtract* from the *urlString*. Valid values for 
*partToExtract* include HOST, PATH, QUERY, REF, PROTOCOL, AUTHORITY, FILE, and 
USERINFO. *keyToExtract* specifies which query to extract
 | b s | POW(numeric1, numeric2)                      | Returns *numeric1* 
raised to the power *numeric2*
+| p | RANDOM()                                       | Generates a random 
double between 0 and 1 inclusive

Review Comment:
   Is there already documentation for RAND? If so, just say `Equivalent to 
RAND` (see other functions w multiple names for examples)



##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -2257,4 +2258,16 @@ private static RelDataType 
deriveTypeMapFromEntries(SqlOperatorBinding opBinding
   @LibraryOperator(libraries = {SPARK})
   public static final SqlFunction GETBIT =
       BIT_GET.withName("GETBIT");
+
+  /** The RANDOM() function. Equivalent to RAND(). */
+  @LibraryOperator(libraries = {POSTGRESQL})
+  public static final SqlFunction RANDOM = new SqlRandFunction() {

Review Comment:
   what's to keep you from doing 
RAND.withName("RANDOM").withReturnTypeInferance(...)` I think that's better 
than these overrides



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -6307,6 +6307,22 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
     }
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6314";>[CALCITE-6314]
+   * Support PostgreSQL RANDOM</a>. */
+  @Test void testRandomFunc() {
+    final SqlOperatorFixture f = fixture();
+    f.setFor(SqlLibraryOperators.RANDOM, VmName.EXPAND);
+    f.checkFails("^random^", "Column 'RANDOM' not found in any table", false);
+    Consumer<SqlOperatorFixture> test = fixture -> {
+      for (int i = 0; i < 100; i++) {
+        // Result must always be between 0 and 1, inclusive.
+        fixture.checkScalarApprox("random()", "DOUBLE NOT NULL", isWithin(0.5, 
0.5));
+      }
+    };
+    f.forEachLibrary(list(SqlLibrary.POSTGRESQL), test);

Review Comment:
   do any other main dialects used by Calcite support this function? If so, 
enable them too please



-- 
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: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to