diff --git ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java index 4f0db03..955aa91 100644 --- ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java +++ ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/translator/ExprNodeConverter.java @@ -224,12 +224,24 @@ public ExprNodeDesc visitLiteral(RexLiteral literal) { case DECIMAL: return new ExprNodeConstantDesc(TypeInfoFactory.getDecimalTypeInfo(lType.getPrecision(), lType.getScale()), literal.getValue3()); - case VARCHAR: - return new ExprNodeConstantDesc(TypeInfoFactory.getVarcharTypeInfo(lType.getPrecision()), - new HiveVarchar((String) literal.getValue3(), lType.getPrecision())); - case CHAR: - return new ExprNodeConstantDesc(TypeInfoFactory.getCharTypeInfo(lType.getPrecision()), - new HiveChar((String) literal.getValue3(), lType.getPrecision())); + case VARCHAR: { + int varcharLength = lType.getPrecision(); + // If we cannot use Varchar due to type length restrictions, we use String + if (varcharLength < 1 || varcharLength > HiveVarchar.MAX_VARCHAR_LENGTH) { + return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3()); + } + return new ExprNodeConstantDesc(TypeInfoFactory.getVarcharTypeInfo(varcharLength), + new HiveVarchar((String) literal.getValue3(), varcharLength)); + } + case CHAR: { + int charLength = lType.getPrecision(); + // If we cannot use Char due to type length restrictions, we use String + if (charLength < 1 || charLength > HiveChar.MAX_CHAR_LENGTH) { + return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3()); + } + return new ExprNodeConstantDesc(TypeInfoFactory.getCharTypeInfo(charLength), + new HiveChar((String) literal.getValue3(), charLength)); + } case INTERVAL_YEAR_MONTH: { BigDecimal monthsBd = (BigDecimal) literal.getValue(); return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo,