luoyuxia commented on code in PR #18975:
URL: https://github.com/apache/flink/pull/18975#discussion_r959114755


##########
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveDialectQueryITCase.java:
##########
@@ -788,7 +788,7 @@ public void testCastTimeStampToDecimal() throws Exception {
                                                     timestamp))
                                     .collect());
             assertThat(results.toString())
-                    .isEqualTo(String.format("[+I[%s]]", 
expectTimeStampDecimal.toFormatString(8)));
+                    .isEqualTo(String.format("[+I[%s]]", 
expectTimeStampDecimal));

Review Comment:
   Yes, it's. But there's a special case when comes to cast constant and 
constant fold is enabled. Actually, the current behavior  is same to Hive.
    I try with the following sql in Hive:
   ```sql
   hive> select cast(cast('2012-12-19 11:12:19.1234567' as timestamp) as 
decimal(30,8));
   1355915539.1234567
   
   hive> insert into t2 values('2012-12-19 11:12:19.1234567')
   
   hive> select  cast(c2 as decimal(30, 8)) from t2;
   1355915539.12345670
   
   hive > insert into t1 select * from t2;
   
   hive > select * from t1;
   1355915539.12345670
   ```
   The plan for the sql in hive `select cast(cast('2012-12-19 11:12:19.1234567' 
as timestamp) as decimal(30,8))` is:
   ```sql
   STAGE PLANS:
     Stage: Stage-0
       Fetch Operator
         limit: -1
         Processor Tree:
           TableScan
             alias: _dummy_table
             Row Limit Per Split: 1
             Statistics: Num rows: 1 Data size: 10 Basic stats: COMPLETE Column 
stats: COMPLETE
             Select Operator
               expressions: 1355915539.1234567 (type: decimal(30,8))
               outputColumnNames: _col0
               Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE 
Column stats: COMPLETE
               ListSink
   ```
   The plan for `select cast(c1 as decimal(30, 8)) from t1` is :
   ```sql
   STAGE DEPENDENCIES:
     Stage-0 is a root stage
   
   STAGE PLANS:
     Stage: Stage-0
       Fetch Operator
         limit: -1
         Processor Tree:
           TableScan
             alias: t1
             Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE 
Column stats: NONE
             Select Operator
               expressions: CAST( c1 AS decimal(30,8)) (type: decimal(30,8))
               outputColumnNames: _col0
               Statistics: Num rows: 1 Data size: 112 Basic stats: COMPLETE 
Column stats: NONE
               ListSink
   ```
   
   The reason I found is the `HiveDecimalConverter` used to convert data in 
Hive's `GenericUDFToDecimal` function actually won't padding zero for  
`2012-12-19 11:12:19.1234567`,  althogh the type is ` decimal(30,8)`. 
   Then, the first sql will select a constant `1355915539.1234567`.
    But for the second sql, a further padding will be done which will result 
`1355915539.12345670`.
   



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to