diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index f5df9cd302..d0b41f50d8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -7835,7 +7835,8 @@ protected Operator genFileSinkPlan(String dest, QB qb, Operator input) } if (!(destType == QBMetaData.DEST_DFS_FILE && qb.getIsQuery())) { - input = genConversionSelectOperator(dest, qb, input, tableDescriptor, dpCtx); + input = genConversionSelectOperator(dest, qb, input, tableDescriptor, dpCtx, + destinationTable.getPartCols()); } inputRR = opParseCtx.get(input).getRowResolver(); @@ -8378,7 +8379,8 @@ These props are now enabled elsewhere (see commit diffs). It would be better in * types that are expected by the table_desc. */ private Operator genConversionSelectOperator(String dest, QB qb, Operator input, - TableDesc table_desc, DynamicPartitionCtx dpCtx) throws SemanticException { + TableDesc table_desc, DynamicPartitionCtx dpCtx, List partitionCols) + throws SemanticException { StructObjectInspector oi = null; try { Deserializer deserializer = table_desc.getDeserializerClass() @@ -8460,16 +8462,23 @@ private Operator genConversionSelectOperator(String dest, QB qb, Operator input, } } - // deal with dynamic partition columns: convert ExprNodeDesc type to String?? + // deal with dynamic partition columns if (dynPart && dpCtx != null && dpCtx.getNumDPCols() > 0) { + int partColIdx = 0; // DP columns starts with tableFields.size() for (int i = tableFields.size() + (updating(dest) ? 1 : 0); i < rowFields.size(); ++i) { TypeInfo rowFieldTypeInfo = rowFields.get(i).getType(); ExprNodeDesc column = new ExprNodeColumnDesc( rowFieldTypeInfo, rowFields.get(i).getInternalName(), "", true); + String partitionType = partitionCols.get(partColIdx).getType(); + PrimitiveTypeInfo partitionTypeInfo = TypeInfoFactory.getPrimitiveTypeInfo(partitionType); + if (!partitionTypeInfo.equals(rowFieldTypeInfo)) { + column = ParseUtils.createConversionCast(column, partitionTypeInfo); + converted = true; + } expressions.add(column); + partColIdx++; } - // converted = true; // [TODO]: should we check & convert type to String and set it to true? } if (converted) {