diff --git a/velox/docs/functions/presto/conversion.rst b/velox/docs/functions/presto/conversion.rst index 33b48bea4e7f..2cce8f53429a 100644 --- a/velox/docs/functions/presto/conversion.rst +++ b/velox/docs/functions/presto/conversion.rst @@ -30,7 +30,7 @@ are supported if the conversion of their element types are supported. In additio supported conversions to/from JSON are listed in :doc:`json`. .. list-table:: - :widths: 25 25 25 25 25 25 25 25 25 25 25 25 25 + :widths: 25 25 25 25 25 25 25 25 25 25 25 25 25 25 :header-rows: 1 * - @@ -45,6 +45,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - timestamp - timestamp with time zone - date + - interval day to second - decimal * - tinyint - Y @@ -58,6 +59,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - smallint - Y @@ -71,6 +73,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - integer - Y @@ -84,6 +87,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - bigint - Y @@ -97,6 +101,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - boolean - Y @@ -110,6 +115,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - real - Y @@ -123,6 +129,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - double - Y @@ -136,6 +143,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y * - varchar - Y @@ -149,6 +157,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - Y - - Y + - - Y * - timestamp - @@ -163,6 +172,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - Y - Y - + - * - timestamp with time zone - - @@ -176,8 +186,22 @@ supported conversions to/from JSON are listed in :doc:`json`. - Y - - + - * - date - + - + - + - + - + - + - + - Y + - Y + - + - + - + - + * - interval day to second - - - @@ -189,6 +213,8 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - + - * - decimal - Y - Y @@ -201,6 +227,7 @@ supported conversions to/from JSON are listed in :doc:`json`. - - - + - - Y Cast to Integral Types @@ -263,7 +290,7 @@ supported cases. SELECT cast(nan() as bigint); -- 0 -From strings +From VARCHAR ^^^^^^^^^^^^ Casting a string to an integral type is allowed if the string represents an @@ -337,7 +364,7 @@ Valid examples SELECT cast(0.5 as boolean); -- true SELECT cast(-0.5 as boolean); -- true -From strings +From VARCHAR ^^^^^^^^^^^^ There is a set of strings allowed to be casted to boolean. Casting from other strings to boolean throws. @@ -389,7 +416,7 @@ behavior. SELECT cast(1.7E308 as real); -- Presto returns Infinity but Velox throws SELECT cast(-1.7E308 as real); -- Presto returns -Infinity but Velox throws -From strings +From VARCHAR ^^^^^^^^^^^^ Casting a string to real is allowed if the string represents an integral or @@ -454,7 +481,7 @@ Invalid example SELECT cast(decimal '300.001' as tinyint); -- Out of range -Cast to String +Cast to VARCHAR -------------- Casting from scalar types to string is allowed. @@ -478,6 +505,7 @@ Valid examples From Floating-Point Types ^^^^^^^^^^^^^^^^^^^^^^^^^ + By default, casting a real or double to string returns standard notation if the magnitude of input value is greater than or equal to 10 :superscript:`-3` but less than 10 :superscript:`7`, and returns scientific notation otherwise. @@ -525,6 +553,16 @@ Valid examples if legacy_cast = true, SELECT cast(real '-0.00012' as varchar); -- '-0.00011999999696854502' +From DATE +^^^^^^^^^ + +Casting DATE to VARCHAR returns an ISO-8601 formatted string: YYYY-MM-DD. + +:: + + SELECT cast(date('2024-03-14') as varchar); -- '2024-03-14' + + From TIMESTAMP ^^^^^^^^^^^^^^ @@ -553,10 +591,26 @@ Valid examples if legacy_cast = true, SELECT cast(timestamp '384-01-01 08:00:00.000' as varchar); -- '384-01-01T08:00:00.000' SELECT cast(timestamp '-10-02-01 10:00:00.000' as varchar); -- '-10-02-01T10:00:00.000' +From INTERVAL DAY TO SECOND +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Casting INTERVAL DAY TO SECOND to VARCHAR returns a string formatted as +'[sign]D HH:MM:SS.ZZZ', where 'sign' is an optional '-' sign if interval is negative, D +is the number of whole days in the interval, HH is then number of hours between 00 and +24, MM is the number of minutes between 00 and 59, SS is the number of seconds between +00 and 59, and zzz is the number of milliseconds between 000 and 999. + +:: + + SELECT cast(interval '1' day as varchar); -- '1 00:00:00.000' + SELECT cast(interval '123456' second as varchar); -- '1 10:17:36.000' + SELECT cast(now() - date('2024-03-01') as varchar); -- '35 09:15:54.092' + SELECT cast(date('2024-03-01') - now() as varchar); -- '-35 09:16:20.598' + Cast to TIMESTAMP ----------------- -From strings +From VARCHAR ^^^^^^^^^^^^ Casting from a string to timestamp is allowed if the string represents a @@ -578,7 +632,7 @@ Invalid example SELECT cast('2012-Oct-23' as timestamp); -- Invalid argument -From date +From DATE ^^^^^^^^^ Casting from date to timestamp is allowed. @@ -649,7 +703,7 @@ Valid examples Cast to Date ------------ -From strings +From VARCHAR ^^^^^^^^^^^^ Only ISO 8601 strings are supported: `[+-]YYYY-MM-DD`. Casting from invalid input values throws.