Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DELETE without providing full primary key #421

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/mapping/object-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,33 @@ class ObjectSelector {
throw new Error(`Table "${info.tables[i].name}" could not be retrieved`);
}

// All partition and clustering keys from the table should be included in the document
const keyNames = table.partitionKeys.concat(table.clusteringKeys).map(k => k.name);
const columns = propertiesInfo.map(p => p.columnName);
if (keysAreIncluded(table.partitionKeys, propertiesInfo) !== keyMatches.all) {
return false;
}

for (let i = 0; i < keyNames.length; i++) {
if (columns.indexOf(keyNames[i]) === -1) {
const clusteringKeyNames = table.clusteringKeys.map(k => k.name);
const queriedClusteringKeyNames = propertiesInfo.filter(k => clusteringKeyNames.includes(k.columnName)).map(k => k.columnName);
for (const queriedClusteringKeyName of queriedClusteringKeyNames) {
if (clusteringKeyNames.indexOf(queriedClusteringKeyName) >= queriedClusteringKeyNames.length) {
// One of the clustering columns preceding queriedClusteringKeyName is omitted
return false;
}
}

// The filter makes sure that the column doesn't appear in `doc` (but it may appear in `docInfo`)
const queriedColumnNames = propertiesInfo.filter(p => p.value).map(p => p.columnName);
const primaryKeyColumnNames = table.partitionKeys.concat(table.clusteringKeys).map(k => k.name);
if (queriedColumnNames.some(queriedColumnName => !primaryKeyColumnNames.includes(queriedColumnName))) {
// Only primary key columns are allowed
return false;
}

// "when" conditions should be contained in the table
return when.reduce((acc, p) => acc && table.columnsByName[p.columnName] !== undefined, true);
});

if (filteredTables.length === 0) {
let message = `No table matches (all PKs have to be specified) fields: [${
let message = `No table matches (must specify all partition key and top-level clustering columns) fields: [${
propertiesInfo.map(p => p.columnName)}]`;

if (when.length > 0) {
Expand Down
Loading