Skip to content
Merged
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
28 changes: 20 additions & 8 deletions client/src/com/aerospike/client/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.aerospike.client.BatchWrite;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Log;
import com.aerospike.client.Operation;
import com.aerospike.client.Record;
import com.aerospike.client.ResultCode;
Expand Down Expand Up @@ -2075,21 +2076,32 @@ public final void setQuery(
fieldCount++;
}

// Operations (used in query execute) and bin names (used in scan/query) are mutually exclusive.
// Operations and bin names are mutually exclusive.
Operation[] operations = statement.getOperations();
int operationCount = 0;

if (operations != null) {
// Estimate size for background operations.
if (! background) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Operations not allowed in foreground query");
if (binNames != null) {
Log.warn("Operations and bin names are mutually exclusive.");
}

for (Operation operation : operations) {
if (! operation.type.isWrite) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR, "Read operations not allowed in background query");
if (background) {
for (Operation operation : operations) {
if (! operation.type.isWrite) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR,
"Background query operations must be write-only. Use query for read-only operations.");
}
estimateOperationSize(operation);
}
}
else {
for (Operation operation : operations) {
if (operation.type.isWrite) {
throw new AerospikeException(ResultCode.PARAMETER_ERROR,
"Query operations must be read-only. Use background query for write-only operations.");
}
estimateOperationSize(operation);
}
estimateOperationSize(operation);
}
operationCount = operations.length;
}
Expand Down
20 changes: 15 additions & 5 deletions client/src/com/aerospike/client/query/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public String getIndexName() {
}

/**
* Set query bin names.
* Set query bin names for bin projection in queries.
* Mutually exclusive with {@link #setOperations(Operation[])}.
*/
public void setBinNames(String... binNames) {
this.binNames = binNames;
Expand Down Expand Up @@ -232,16 +233,25 @@ public Value[] getFunctionArgs() {
}

/**
* Set operations to be performed on a background query
* {@link com.aerospike.client.AerospikeClient#execute(com.aerospike.client.policy.WritePolicy, Statement, Operation...)}
* A foreground query that returns records to the client will silently ignore these operations.
* Set operations to be performed on query/execute.
* <p>
* For foreground queries ({@link com.aerospike.client.AerospikeClient#query(com.aerospike.client.policy.QueryPolicy, Statement)}),
* only read operations are allowed (e.g., {@link Operation#get(String)},
* {@link com.aerospike.client.exp.ExpOperation#read(String, com.aerospike.client.exp.Expression, com.aerospike.client.exp.ExpReadFlags)}).
* Read operations act as bin projections, limiting which bins are returned.
* <p>
* For background execute ({@link com.aerospike.client.AerospikeClient#execute(com.aerospike.client.policy.WritePolicy, Statement, Operation...)}),
* only write operations are allowed (e.g., {@link com.aerospike.client.exp.ExpOperation#write}).
* <p>
* Operations and {@link #setBinNames(String...)} are mutually exclusive. If both are set,
* operations take precedence and a warning is logged.
*/
public void setOperations(Operation[] operations) {
this.operations = operations;
}

/**
* Return operations to be performed on a background query.
* Return operations to be performed on query/execute.
*/
public Operation[] getOperations() {
return this.operations;
Expand Down
2 changes: 2 additions & 0 deletions test/src/com/aerospike/test/SuiteSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.aerospike.test.sync.query.TestQueryGeo;
import com.aerospike.test.sync.query.TestQueryInteger;
import com.aerospike.test.sync.query.TestQueryKey;
import com.aerospike.test.sync.query.TestQueryOperations;
import com.aerospike.test.sync.query.TestQueryRPS;
import com.aerospike.test.sync.query.TestQueryString;
import com.aerospike.test.sync.query.TestQuerySum;
Expand Down Expand Up @@ -113,6 +114,7 @@
TestQueryGeo.class,
TestQueryInteger.class,
TestQueryKey.class,
TestQueryOperations.class,
TestQueryRPS.class,
TestQueryString.class,
TestQuerySum.class
Expand Down
Loading
Loading