Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Blockchain by (4.1k points)

I'm trying to use a VaultCustomQueryCriteria (Corda - Java) with the aggregate function SUM, but I get no results.

If I use another VaultCustomQueryCriteria, the query works.

What am I doing wrong?

Below some examples:

Query OK:

QueryCriteria statusCriteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED);

Field name = ExampleSchemaV1.Ingestion.class.getDeclaredField("name");

QueryCriteria countCriteria = new QueryCriteria.VaultCustomQueryCriteria(Builder.equal(name, "Mark"));
List<StateAndRef<IngestionState>> results = rpcOps.vaultQueryByCriteria(countCriteria,IngestionState.class).getStates();

Query KO: (no results)

QueryCriteria statusCriteria = new QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED);

Field nr = ExampleSchemaV1.Ingestion.class.getDeclaredField("nr");   
Field name = ExampleSchemaV1.Ingestion.class.getDeclaredField("name");

CriteriaExpression sumQta = Builder.sum(nr, Arrays.asList(name));   
QueryCriteria sumQtaCriteria = new QueryCriteria.VaultCustomQueryCriteria(sumQta);

QueryCriteria criteria = statusCriteria.and(sumQtaCriteria);

List<StateAndRef<IngestionState>> results = rpcOps.vaultQueryByCriteria(criteria,IngestionState.class).getStates();

1 Answer

0 votes
by (14.4k points)

Each vault query always returns a Vault.Page object. 

While performing a sum query, the result of the sum is accessible via Vault.Page.getOtherResults() and not via Vault.Page.getStates().

What is the reason behind this? The sum query doesn't return any actual states, but rather returns the result of a computation of these states.

Related questions

0 votes
1 answer
asked Jul 9, 2019 in Blockchain by Karan Singh (4.1k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories