TsReaper 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_r314185942
 
 

 ##########
 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:
   We actually do not support timestamp with precision larger than 3. We can 
support timestamp with precision not larger than 3.

----------------------------------------------------------------
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