MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / getForSelect

Method getForSelect

lib/mapping/object-selector.js:42–129  ·  view source on GitHub ↗

* Gets the table/view that should be used to execute the SELECT query. * @param {Client} client * @param {ModelMappingInfo} info * @param {Boolean} allPKsDefined * @param {Array} propertiesInfo * @param {Array} fieldsInfo * @param {Array >} orderByColumns * @return

(client, info, allPKsDefined, propertiesInfo, fieldsInfo, orderByColumns)

Source from the content-addressed store, hash-verified

40 * @return {Promise<String>} A promise that resolves to a table names.
41 */
42 static getForSelect(client, info, allPKsDefined, propertiesInfo, fieldsInfo, orderByColumns) {
43 return Promise.all(
44 info.tables.map(t => {
45 if (t.isView) {
46 return client.metadata.getMaterializedView(info.keyspace, t.name);
47 }
48 return client.metadata.getTable(info.keyspace, t.name);
49 }))
50 .then(tables => {
51 for (let i = 0; i < tables.length; i++) {
52 const table = tables[i];
53 if (table === null) {
54 throw new Error(`Table "${info.tables[i].name}" could not be retrieved`);
55 }
56
57 if (keysAreIncluded(table.partitionKeys, propertiesInfo) !== keyMatches.all) {
58 // Not all the partition keys are covered
59 continue;
60 }
61
62
63 if (allPKsDefined) {
64 if (keysAreIncluded(table.clusteringKeys, propertiesInfo) !== keyMatches.all) {
65 // All clustering keys should be included as allPKsDefined flag is set
66 continue;
67 }
68 }
69
70 if (propertiesInfo.length > table.partitionKeys.length) {
71 // Check that the Where clause is composed by partition and clustering keys
72 const allPropertiesArePrimaryKeys = propertiesInfo
73 .reduce(
74 (acc, p) => acc && (
75 contains(table.partitionKeys, c => c.name === p.columnName) ||
76 contains(table.clusteringKeys, c => c.name === p.columnName)
77 ),
78 true);
79
80 if (!allPropertiesArePrimaryKeys) {
81 continue;
82 }
83 }
84
85 // All fields must be contained
86 const containsAllFields = fieldsInfo
87 .reduce((acc, p) => acc && table.columnsByName[p.columnName] !== undefined, true);
88
89 if (!containsAllFields) {
90 continue;
91 }
92
93 // CQL:
94 // - "ORDER BY" is currently only supported on the clustered columns of the PRIMARY KEY
95 // - "ORDER BY" currently only support the ordering of columns following their declared order in
96 // the PRIMARY KEY
97 //
98 // In the mapper, we validate that the ORDER BY columns appear in the same order as in the clustering keys
99 const containsAllOrderByColumns = orderByColumns

Callers 1

getSelectExecutorMethod · 0.80

Calls 4

keysAreIncludedFunction · 0.85
containsFunction · 0.85
getMaterializedViewMethod · 0.65
getTableMethod · 0.65

Tested by

no test coverage detected