protected boolean isIndexedBin(Statement stmt, Qualifier qualifier) { if(null == qualifier.getField()) return false; Index index = this.indexCache.get(String.join(":", Arrays.asList(stmt.getNamespace(), stmt.getSetName(), qualifier.getField()))); if (index == null) return false; switch (qualifier.getOperation()){ case EQ: case BETWEEN: case GT: case GTEQ: case LT: case LTEQ: return true; default: return false; } }
/** * inserts a record, with a time to live, using a Statement and KeyQualifier. If the record exists, and exception will be thrown. * * @param stmt A Statement object containing Namespace and Set * @param keyQualifier KeyQualifier containin the primary key * @param bins A list of Bins to insert * @param ttl The record time to live in seconds */ public void insert(Statement stmt, KeyQualifier keyQualifier, List<Bin> bins, int ttl) { Key key = keyQualifier.makeKey(stmt.getNamespace(), stmt.getSetName()); // Key key = new Key(stmt.getNamespace(), stmt.getSetName(), keyQualifier.getValue1()); this.client.put(this.insertPolicy, key, bins.toArray(new Bin[0])); }
private KeyRecordIterator queryByLua(Statement stmt, Boolean metaOnly, Node node, Qualifier[] qualifiers){ Map<String, Object> originArgs = new HashMap<String, Object>(); originArgs.put("includeAllFields", 1); ResultSet resultSet = null; String filterFuncStr = buildFilterFunction(qualifiers); originArgs.put("filterFuncStr", filterFuncStr); if (metaOnly) stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "query_meta", Value.get(originArgs)); else stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "select_records", Value.get(originArgs)); if (node != null) { resultSet = this.client.queryAggregateNode(queryPolicy, stmt, node); } else { resultSet = this.client.queryAggregate(queryPolicy, stmt); } return new KeyRecordIterator(stmt.getNamespace(), resultSet); }
/** * Select records filtered by Qualifiers * * @param stmt A Statement object containing Namespace, Set and the Bins to be returned. * @param sortMap <STRONG>NOT IMPLEMENTED</STRONG> * @param qualifiers Zero or more Qualifiers for the update query * @return A KeyRecordIterator to iterate over the results */ public KeyRecordIterator select(Statement stmt, Map<String, String> sortMap, Qualifier... qualifiers) { KeyRecordIterator results = null; if (qualifiers != null && qualifiers.length > 0) { Map<String, Object> originArgs = new HashMap<String, Object>(); originArgs.put("includeAllFields", 1); String filterFuncStr = buildFilterFunction(qualifiers); originArgs.put("filterFuncStr", filterFuncStr); String sortFuncStr = buildSortFunction(sortMap); originArgs.put("sortFuncStr", sortFuncStr); stmt.setAggregateFunction(this.getClass().getClassLoader(), AS_UTILITY_PATH, QUERY_MODULE, "select_records", Value.get(originArgs)); ResultSet resultSet = this.client.queryAggregate(queryPolicy, stmt); results = new KeyRecordIterator(stmt.getNamespace(), resultSet); } else { RecordSet recordSet = this.client.query(queryPolicy, stmt); results = new KeyRecordIterator(stmt.getNamespace(), recordSet); } return results; }
/** * The list of Bins will update each record that match the Qualifiers supplied. * * @param stmt A Statement object containing Namespace and Set * @param bins A list of Bin objects with the values to updated * @param qualifiers Zero or more Qualifiers for the update query * @return returns a Map containing a number of successful updates. The Map will contain 2 keys "read" and "write", the values will be the count of successful operations */ public Map<String, Long> update(Statement stmt, List<Bin> bins, Qualifier... qualifiers) { if (qualifiers != null && qualifiers.length == 1 && qualifiers[0] instanceof KeyQualifier) { KeyQualifier keyQualifier = (KeyQualifier) qualifiers[0]; Key key = keyQualifier.makeKey(stmt.getNamespace(), stmt.getSetName()); this.client.put(this.updatePolicy, key, bins.toArray(new Bin[0])); Map<String, Long> result = new HashMap<String, Long>(); result.put("read", 1L); result.put("write", 1L); return result; } else { KeyRecordIterator results = select(stmt, true, null, qualifiers); return update(results, bins); } }
/** * Deletes the records specified by the Statement and Qualifiers * * @param stmt A Statement object containing Namespace and Set * @param qualifiers Zero or more Qualifiers for the update query * @return returns a Map containing a number of successful updates. The Map will contain 2 keys "read" and "write", the values will be the count of successful operations */ public Map<String, Long> delete(Statement stmt, Qualifier... qualifiers) { if (qualifiers == null || qualifiers.length == 0) { /* * There are no qualifiers, so delete every record in the set * using Scan UDF delete */ ExecuteTask task = client.execute(null, stmt, QUERY_MODULE, "delete_record"); task.waitTillComplete(); return null; } if (qualifiers.length == 1 && qualifiers[0] instanceof KeyQualifier) { KeyQualifier keyQualifier = (KeyQualifier) qualifiers[0]; Key key = keyQualifier.makeKey(stmt.getNamespace(), stmt.getSetName()); this.client.delete(null, key); Map<String, Long> map = new HashMap<String, Long>(); map.put("read", 1L); map.put("write", 1L); return map; } KeyRecordIterator results = select(stmt, true, null, qualifiers); return delete(results); }
else recordSet = this.client.query(queryPolicy, stmt); return new KeyRecordIterator(stmt.getNamespace(), recordSet); Key key = kq.makeKey(stmt.getNamespace(), stmt.getSetName()); Record record = null; if (metaOnly) record = this.client.get(null, key, stmt.getBinNames()); if (record == null) { return new KeyRecordIterator(stmt.getNamespace()); } else { KeyRecord keyRecord = new KeyRecord(key, record); return new KeyRecordIterator(stmt.getNamespace(), keyRecord); rs = client.queryNode(queryPolicy, stmt, node); return new KeyRecordIterator(stmt.getNamespace(), rs); }else{ return queryByLua(stmt, metaOnly, node, qualifiers);
executeValidate(tasks, policy.maxConcurrentNodes, statement.getNamespace());
executeValidate(tasks, policy.maxConcurrentNodes, statement.getNamespace());
if (statement.getNamespace() != null) { dataOffset += Buffer.estimateSizeUtf8(statement.getNamespace()) + FIELD_HEADER_SIZE; fieldCount++; if (statement.getNamespace() != null) { writeField(statement.getNamespace(), FieldType.NAMESPACE);
if (statement.getNamespace() != null) { dataOffset += Buffer.estimateSizeUtf8(statement.getNamespace()) + FIELD_HEADER_SIZE; fieldCount++; if (statement.getNamespace() != null) { writeField(statement.getNamespace(), FieldType.NAMESPACE);