List<Expression> values = node.values();
List<ColumnIdent> primaryKey = context.table().primaryKey();
for (int i = 0, valuesSize = values.size(); i < valuesSize; i++) {
Expression expression = values.get(i);
Symbol valuesSymbol = process(expression, context);
// implicit type conversion
Reference column = context.columns().get(i);
final ColumnIdent columnIdent = column.info().ident().columnIdent();
try {
valuesSymbol = context.normalizeInputForReference(valuesSymbol, column, true);
} catch (IllegalArgumentException | UnsupportedOperationException e) {
throw new ColumnValidationException(column.info().ident().columnIdent().fqn(), e);
}
try {
Object value = ((Input) valuesSymbol).value();
if (context.primaryKeyColumnIndices().contains(i)) {
int idx = primaryKey.indexOf(columnIdent);
if (idx < 0) {
// oh look, one or more nested primary keys!
assert value instanceof Map;
for (ColumnIdent pkIdent : primaryKey) {
if (!pkIdent.getRoot().equals(columnIdent)) {
continue;
}
int pkIdx = primaryKey.indexOf(pkIdent);
Object nestedValue = StringObjectMaps.fromMapByPath((Map) value, pkIdent.path());
addPrimaryKeyValue(pkIdx, nestedValue, primaryKeyValues);
}
} else {
addPrimaryKeyValue(idx, value, primaryKeyValues);
}
}
if (i == context.routingColumnIndex()) {
routingValue = extractRoutingValue(columnIdent, value, context);
}
if (context.partitionedByIndices().contains(i)) {
Object rest = processPartitionedByValues(columnIdent, value, context);
if (rest != null) {
builder.field(columnIdent.name(), rest);
}
} else {
if (value instanceof BytesRef) {
value = new BytesText(new BytesArray((BytesRef) value));
}
builder.field(columnIdent.name(), value);
}
} catch (ClassCastException e) {
// symbol is no input
throw new ColumnValidationException(columnIdent.name(),
String.format("invalid value '%s' in insert statement", valuesSymbol.toString()));
}
}
context.sourceMaps().add(builder.bytes());
context.addIdAndRouting(primaryKeyValues, routingValue);
}