Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
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

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...