@Override public boolean isCastableTo(PDataType targetType) { // Allow cast to BOOLEAN so it can be used in an index or group by return super.isCastableTo(targetType) || targetType.equals(PDecimal.INSTANCE); }
@Override public boolean isCastableTo(PDataType targetType) { return super.isCastableTo(targetType) || equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE); }
public static PDataType getIndexColumnDataType(boolean isNullable, PDataType dataType) { if (dataType == null || !isNullable || !dataType.isFixedWidth()) { return dataType; } // for fixed length numeric types and boolean if (dataType.isCastableTo(PDecimal.INSTANCE)) { return PDecimal.INSTANCE; } // for CHAR if (dataType.isCoercibleTo(PVarchar.INSTANCE)) { return PVarchar.INSTANCE; } if (PBinary.INSTANCE.equals(dataType)) { return PVarbinary.INSTANCE; } throw new IllegalArgumentException("Unsupported non nullable type " + dataType); }
private static Expression convertToRoundExpressionIfNeeded(PDataType fromDataType, PDataType targetDataType, List<Expression> expressions) throws SQLException { Expression firstChildExpr = expressions.get(0); if(fromDataType == targetDataType) { return firstChildExpr; } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PLong.INSTANCE)) { return RoundDecimalExpression.create(expressions); } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PDate.INSTANCE)) { return RoundTimestampExpression.create(expressions); } else if(fromDataType.isCastableTo(targetDataType)) { return firstChildExpr; } else { throw TypeMismatchException.newException(fromDataType, targetDataType, firstChildExpr.toString()); } }
return LiteralExpression.newConstant(null, lhs.getDataType(), lhs.getDeterminism()); } else { if (rhs.getDataType() != null && lhs.getDataType() != null && !rhs.getDataType().isCastableTo(lhs.getDataType())) { throw TypeMismatchException.newException(lhs.getDataType(), rhs.getDataType());
private static Expression coerceIfNecessary(int index, List<? extends PDatum> targetColumns, Expression expression) throws SQLException { if (index < targetColumns.size()) { PDatum targetColumn = targetColumns.get(index); if (targetColumn.getDataType() != expression.getDataType()) { PDataType targetType = targetColumn.getDataType(); // Check if coerce allowed using more relaxed isCastableTo check, since we promote INTEGER to LONG // during expression evaluation and then convert back to INTEGER on UPSERT SELECT (and we don't have // (an actual value we can specifically check against). if (expression.getDataType() != null && !expression.getDataType().isCastableTo(targetType)) { throw new ArgumentTypeMismatchException(targetType, expression.getDataType(), "column: " + targetColumn); } expression = CoerceExpression.create(expression, targetType, targetColumn.getSortOrder(), targetColumn.getMaxLength()); } } return expression; } /**
@Override public boolean isCastableTo(PDataType targetType) { return super.isCastableTo(targetType) || equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE); }
@Override public boolean isCastableTo(PDataType targetType) { // Allow cast to BOOLEAN so it can be used in an index or group by return super.isCastableTo(targetType) || targetType.equals(PDecimal.INSTANCE); }
@Override public boolean isCastableTo(PDataType targetType) { // Allow cast to BOOLEAN so it can be used in an index or group by return super.isCastableTo(targetType) || targetType.equals(PDecimal.INSTANCE); }
@Override public boolean isCastableTo(PDataType targetType) { return super.isCastableTo(targetType) || equalsAny(targetType, PDecimal.INSTANCE, PLong.INSTANCE, PUnsignedLong.INSTANCE); }
expressionBuilder.setColumn(column); Expression expression = valueNode.accept(expressionBuilder); if (expression.getDataType() != null && !expression.getDataType().isCastableTo(column.getDataType())) { throw TypeMismatchException.newException( expression.getDataType(), column.getDataType(), "expression: " Expression updateExpression = updateNode.accept(compiler); if (updateExpression.getDataType() != null && !updateExpression.getDataType().isCastableTo(updateColumn.getDataType())) { throw TypeMismatchException.newException( updateExpression.getDataType(), updateColumn.getDataType(), "expression: "
public static PDataType getIndexColumnDataType(boolean isNullable, PDataType dataType) { if (dataType == null || !isNullable || !dataType.isFixedWidth()) { return dataType; } // for fixed length numeric types and boolean if (dataType.isCastableTo(PDecimal.INSTANCE)) { return PDecimal.INSTANCE; } // for CHAR if (dataType.isCoercibleTo(PVarchar.INSTANCE)) { return PVarchar.INSTANCE; } if (PBinary.INSTANCE.equals(dataType)) { return PVarbinary.INSTANCE; } throw new IllegalArgumentException("Unsupported non nullable type " + dataType); }
public static PDataType getIndexColumnDataType(boolean isNullable, PDataType dataType) { if (dataType == null || !isNullable || !dataType.isFixedWidth()) { return dataType; } // for fixed length numeric types and boolean if (dataType.isCastableTo(PDecimal.INSTANCE)) { return PDecimal.INSTANCE; } // for CHAR if (dataType.isCoercibleTo(PVarchar.INSTANCE)) { return PVarchar.INSTANCE; } if (PBinary.INSTANCE.equals(dataType)) { return PVarbinary.INSTANCE; } throw new IllegalArgumentException("Unsupported non nullable type " + dataType); }
private static Expression convertToRoundExpressionIfNeeded(PDataType fromDataType, PDataType targetDataType, List<Expression> expressions) throws SQLException { Expression firstChildExpr = expressions.get(0); if(fromDataType == targetDataType) { return firstChildExpr; } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PLong.INSTANCE)) { return RoundDecimalExpression.create(expressions); } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PDate.INSTANCE)) { return RoundTimestampExpression.create(expressions); } else if(fromDataType.isCastableTo(targetDataType)) { return firstChildExpr; } else { throw TypeMismatchException.newException(fromDataType, targetDataType, firstChildExpr.toString()); } }
private static Expression convertToRoundExpressionIfNeeded(PDataType fromDataType, PDataType targetDataType, List<Expression> expressions) throws SQLException { Expression firstChildExpr = expressions.get(0); if(fromDataType == targetDataType) { return firstChildExpr; } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PLong.INSTANCE)) { return RoundDecimalExpression.create(expressions); } else if((fromDataType == PDecimal.INSTANCE || fromDataType == PTimestamp.INSTANCE || fromDataType == PUnsignedTimestamp.INSTANCE) && targetDataType.isCoercibleTo( PDate.INSTANCE)) { return RoundTimestampExpression.create(expressions); } else if(fromDataType.isCastableTo(targetDataType)) { return firstChildExpr; } else { throw TypeMismatchException.newException(fromDataType, targetDataType, firstChildExpr.toString()); } }
return LiteralExpression.newConstant(null, lhs.getDataType(), lhs.getDeterminism()); } else { if (rhs.getDataType() != null && lhs.getDataType() != null && !rhs.getDataType().isCastableTo(lhs.getDataType())) { throw TypeMismatchException.newException(lhs.getDataType(), rhs.getDataType());
return LiteralExpression.newConstant(null, lhs.getDataType(), lhs.getDeterminism()); } else { if (rhs.getDataType() != null && lhs.getDataType() != null && !rhs.getDataType().isCastableTo(lhs.getDataType())) { throw TypeMismatchException.newException(lhs.getDataType(), rhs.getDataType());
private static Expression coerceIfNecessary(int index, List<? extends PDatum> targetColumns, Expression expression) throws SQLException { if (index < targetColumns.size()) { PDatum targetColumn = targetColumns.get(index); if (targetColumn.getDataType() != expression.getDataType()) { PDataType targetType = targetColumn.getDataType(); // Check if coerce allowed using more relaxed isCastableTo check, since we promote INTEGER to LONG // during expression evaluation and then convert back to INTEGER on UPSERT SELECT (and we don't have // (an actual value we can specifically check against). if (expression.getDataType() != null && !expression.getDataType().isCastableTo(targetType)) { throw new ArgumentTypeMismatchException(targetType, expression.getDataType(), "column: " + targetColumn); } expression = CoerceExpression.create(expression, targetType, targetColumn.getSortOrder(), targetColumn.getMaxLength()); } } return expression; } /**
private static Expression coerceIfNecessary(int index, List<? extends PDatum> targetColumns, Expression expression) throws SQLException { if (index < targetColumns.size()) { PDatum targetColumn = targetColumns.get(index); if (targetColumn.getDataType() != expression.getDataType()) { PDataType targetType = targetColumn.getDataType(); // Check if coerce allowed using more relaxed isCastableTo check, since we promote INTEGER to LONG // during expression evaluation and then convert back to INTEGER on UPSERT SELECT (and we don't have // (an actual value we can specifically check against). if (expression.getDataType() != null && !expression.getDataType().isCastableTo(targetType)) { throw new ArgumentTypeMismatchException(targetType, expression.getDataType(), "column: " + targetColumn); } expression = CoerceExpression.create(expression, targetType, targetColumn.getSortOrder(), targetColumn.getMaxLength()); } } return expression; } /**
expressionBuilder.setColumn(column); Expression expression = valueNode.accept(expressionBuilder); if (expression.getDataType() != null && !expression.getDataType().isCastableTo(column.getDataType())) { throw TypeMismatchException.newException( expression.getDataType(), column.getDataType(), "expression: " Expression updateExpression = updateNode.accept(compiler); if (updateExpression.getDataType() != null && !updateExpression.getDataType().isCastableTo(updateColumn.getDataType())) { throw TypeMismatchException.newException( updateExpression.getDataType(), updateColumn.getDataType(), "expression: "