lirui-apache commented on a change in pull request #9342: [FLINK-13438][hive] 
Fix DataTypes.DATE/TIME/TIMESTAMP support for hive connectors
URL: https://github.com/apache/flink/pull/9342#discussion_r314153819
 
 

 ##########
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/util/HiveTableUtil.java
 ##########
 @@ -133,4 +141,48 @@ public static Partition createHivePartition(String 
dbName, String tableName, Lis
                return partition;
        }
 
+       /**
+        * Create a new catalog table according to the given catalog table.
+        * The two catalog tables are the same except for their table schemas.
+        * DataTypes not supported by hive will be changed to the types that 
hive supports.
+        *
+        * <p>TODO:
+        * Can we just change the table schema of the given catalog table
+        * without creating a new catalog table?
+        */
+       public static CatalogTable toHiveCatalogTable(CatalogTable oldTable) {
+               TableSchema oldSchema = oldTable.getSchema();
+               DataType[] fieldDataTypes = oldSchema.getFieldDataTypes();
+               String[] fieldNames = oldSchema.getFieldNames();
+
+               TableSchema.Builder builder = TableSchema.builder();
+               for (int i = 0; i < fieldDataTypes.length; i++) {
+                       // Hive stores date and timestamp using java.sql.*,
+                       // so we change our date / time / timestamp type here.
+                       switch 
(fieldDataTypes[i].getLogicalType().getTypeRoot()) {
+                               case DATE:
+                                       builder.field(fieldNames[i], 
fieldDataTypes[i].bridgedTo(Date.class));
+                                       break;
+                               case TIME_WITHOUT_TIME_ZONE:
+                                       builder.field(fieldNames[i], 
fieldDataTypes[i].bridgedTo(Time.class));
+                                       break;
+                               case TIMESTAMP_WITHOUT_TIME_ZONE:
+                                       Preconditions.checkArgument(
 
 Review comment:
   Why not just error out here since we don't support timestamp for now?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to