Source:
<code>private void checkTypesMatchForInsert(Insert insert, Scope queryScope, List<ColumnMetadata> expectedColumns) { List<Type> queryColumnTypes = queryScope.getRelationType().getVisibleFields().stream() .map(Field::getType) .collect(toImmutableList()); String errorMessage = ""; if (expectedColumns.size() != queryColumnTypes.size()) { errorMessage = format("Insert query has %d expression(s) but expected %d target column(s). ", queryColumnTypes.size(), expectedColumns.size()); <START> } <END> List<Expression> rows = ((Values) (insert.getQuery().getQueryBody())).getRows(); if (rows.isEmpty()) { throw new SemanticException(MISSING_COLUMN, insert, "Missing column values."); } for (int i = 0; i < Math.max(expectedColumns.size(), queryColumnTypes.size()); i++) { int columnIndex = Math.min(i, queryColumnTypes.size() - 1); Expression node = ((Row) rows.get(0)).getItems().get(columnIndex); if (i == expectedColumns.size()) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d", i + 1); } if (i == queryColumnTypes.size()) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d: '%s'", i + 1, expectedColumns.get(i).getName()); } if (!metadata.getTypeManager().canCoerce( queryColumnTypes.get(i), expectedColumns.get(i).getType())) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d: '%s' is of type %s but expression is of type %s", i + 1, expectedColumns.get(i).getName(), expectedColumns.get(i).getType(), queryColumnTypes.get(i)); } } }</code><technical_language>Nit: generally %s is safer fancy number formatting here</technical_language>

Target:
private void checkTypesMatchForInsert(Insert insert, Scope queryScope, List<ColumnMetadata> expectedColumns) { List<Type> queryColumnTypes = queryScope.getRelationType().getVisibleFields().stream() .map(Field::getType) .collect(toImmutableList()); String errorMessage = ""; if (expectedColumns.size() != queryColumnTypes.size()) { errorMessage = format("Insert query has %d expression(s) but expected %d target column(s). ", queryColumnTypes.size(), expectedColumns.size()); } for (int i = 0; i < Math.max(expectedColumns.size(), queryColumnTypes.size()); i++) { Node node = insert; QueryBody queryBody = insert.getQuery().getQueryBody(); if (queryBody instanceof Values) { List<Expression> rows = ((Values) queryBody).getRows(); checkState(!rows.isEmpty(), "Missing column values"); node = rows.get(0); if (node instanceof Row) { int columnIndex = Math.min(i, queryColumnTypes.size() - 1); node = ((Row) rows.get(0)).getItems().get(columnIndex); } } if (i == expectedColumns.size()) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d", i + 1); } if (i == queryColumnTypes.size()) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d: '%s'", i + 1, expectedColumns.get(i).getName()); } if (!metadata.getTypeManager().canCoerce( queryColumnTypes.get(i), expectedColumns.get(i).getType())) { throw new SemanticException(MISMATCHED_SET_COLUMN_TYPES, node, errorMessage + "Mismatch at column %d: '%s' is of type %s but expression is of type %s", i + 1, expectedColumns.get(i).getName(), expectedColumns.get(i).getType(), queryColumnTypes.get(i)); } } }