if (!valueNode.isConstant()) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.VALUE_IN_UPSERT_NOT_CONSTANT).build().buildException();
}
PColumn column = allColumns.get(columnIndexes[nodeIndex]);
expressionBuilder.setColumn(column);
LiteralExpression literalExpression = (LiteralExpression)valueNode.accept(expressionBuilder);
byte[] byteValue = literalExpression.getBytes();
if (literalExpression.getDataType() != null) {
// If ColumnModifier from expression in SELECT doesn't match the
// column being projected into then invert the bits.
if (literalExpression.getColumnModifier() != column.getColumnModifier()) {
byte[] tempByteValue = Arrays.copyOf(byteValue, byteValue.length);
byteValue = ColumnModifier.SORT_DESC.apply(byteValue, 0, tempByteValue, 0, byteValue.length);
}
if (!literalExpression.getDataType().isCoercibleTo(column.getDataType(), literalExpression.getValue())) {
throw new TypeMismatchException(
literalExpression.getDataType(), column.getDataType(), "expression: "
+ literalExpression.toString() + " in column " + column);
}
if (!column.getDataType().isSizeCompatible(literalExpression.getDataType(),
literalExpression.getValue(), byteValue, literalExpression.getMaxLength(),
column.getMaxLength(), literalExpression.getScale(), column.getScale())) {
throw new SQLExceptionInfo.Builder(
SQLExceptionCode.DATA_INCOMPATIBLE_WITH_TYPE).setColumnName(column.getName().getString())
.setMessage("value=" + literalExpression.toString()).build().buildException();
}
}
byteValue = column.getDataType().coerceBytes(byteValue, literalExpression.getValue(),
literalExpression.getDataType(), literalExpression.getMaxLength(), literalExpression.getScale(),
column.getMaxLength(), column.getScale());
values[nodeIndex] = byteValue;
nodeIndex++;
}
return new MutationPlan() {