You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "learningchess2003 (via GitHub)" <gi...@apache.org> on 2023/05/26 20:57:45 UTC

[GitHub] [spark] learningchess2003 commented on a diff in pull request #41319: [SPARK-43815] Add to_varchar alias for to_char

learningchess2003 commented on code in PR #41319:
URL: https://github.com/apache/spark/pull/41319#discussion_r1207339425


##########
sql/core/src/test/resources/sql-tests/inputs/charvarchar.sql:
##########
@@ -117,3 +117,26 @@ drop table char_tbl4;
 -- ascii value for Latin-1 Supplement characters
 select ascii('§'), ascii('÷'), ascii('×10');
 select chr(167), chr(247), chr(215);
+
+-- [SPARK-43815] Add to_varchar alias for to_char
+-- TO_VARCHAR()
+-- Alias of TO_CHAR()
+create table num_data (id int, val decimal(38,10)) using parquet;
+
+insert into num_data values (0, 0);
+insert into num_data values (1, 0);
+insert into num_data values (2, -34338492.215397047);
+insert into num_data values (3, 4.31);
+insert into num_data values (4, 7799461.4119);
+insert into num_data values (5, 16397.038491);
+insert into num_data values (6, 93901.57763026);
+insert into num_data values (7, -83028485);
+insert into num_data values (8, 74881);
+insert into num_data values (9, -24926804.045047420);
+
+select * from num_data;
+
+select '' as to_varchar_3, to_varchar(val, '9999999999999999.999999999999999PR'), val
+from num_data;
+
+drop table num_data;

Review Comment:
   @MaxGekk  I don't think to_char/to_varchar accepts a timestamp literal yet. At the very least, when running this command, I got the following error:
   ```
   -- !query
   select to_varchar(date'26-May-2023', 'yyyy.mm.dd')
   -- !query schema
   struct<>
   -- !query output
   org.apache.spark.sql.catalyst.parser.ParseException
   {
     "errorClass" : "INVALID_TYPED_LITERAL",
     "sqlState" : "42604",
     "messageParameters" : {
       "value" : "'26-May-2023'",
       "valueType" : "\"DATE\""
     },
     "queryContext" : [ {
       "objectType" : "",
       "objectName" : "",
       "startIndex" : 19,
       "stopIndex" : 35,
       "fragment" : "date'26-May-2023'"
     } ]
   }
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org