Skip to content

Commit

Permalink
Ajm/fix 1720 bad order inserted return (#1722)
Browse files Browse the repository at this point in the history
Co-authored-by: Mahesh Rajamani <99678631+maheshrajamani@users.noreply.github.com>
  • Loading branch information
amorton and maheshrajamani authored Nov 14, 2024
1 parent db465e1 commit dc6bd25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public Optional<ColumnsDescContainer> schemaDescription() {
return Optional.empty();
}

var apiColumns =
schemaObject.apiTableDef().allColumns().filterBy(row.keyColumns().getIdentifiers());
var apiColumns = schemaObject.apiTableDef().primaryKeys();
if (!apiColumns.filterByUnsupported().isEmpty()) {
throw new IllegalStateException(
"Unsupported columns primary key: %s" + apiColumns.filterByUnsupported());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,26 @@ public WriteableTableRow build(JsonNamedValueContainer source) {
// now need to split the columns into key and non key columns
var keyColumns = new CqlNamedValueContainer();
var nonKeyColumns = new CqlNamedValueContainer();
for (var cqlNamedValue : decoded.values()) {
if (tableMetadata.getPrimaryKey().contains(cqlNamedValue.name())) {
keyColumns.put(cqlNamedValue);

// Get the primary keys out of the new values in the order they are defined on the table
for (var keyMetadata : tableMetadata.getPrimaryKey()) {
if (decoded.containsKey(keyMetadata)) {
keyColumns.put(decoded.get(keyMetadata));
} else {
// the primary keys have been checked above
throw new IllegalStateException(
String.format(
"build: primary key column not found in decoded values, column=%s", keyMetadata));
}
}

// any column in decoded that is now not in keyColumns is a non key column
for (var cqlNamedValue : decoded.values()) {
if (!keyColumns.containsKey(cqlNamedValue.name())) {
nonKeyColumns.put(cqlNamedValue);
}
}

return new WriteableTableRow(tableSchemaObject, keyColumns, nonKeyColumns);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ApiColumnDefContainer filterBy(ApiTypeName type) {

public ApiColumnDefContainer filterBy(Collection<CqlIdentifier> identifiers) {
return new ApiColumnDefContainer(
identifiers.stream().map(this::get).filter(Objects::nonNull).toList());
values().stream().filter(columnDef -> identifiers.contains(columnDef.name())).toList());
}

public ApiColumnDefContainer filterByUnsupported() {
Expand Down

0 comments on commit dc6bd25

Please sign in to comment.