From fbed7b1fad80bdce5bdd38d33f055dac828048fe Mon Sep 17 00:00:00 2001 From: Chris Elder Date: Wed, 1 Mar 2017 08:55:43 -0500 Subject: [PATCH] FAB-2560 GetQueryResult() query re-write is incorrect Query is getting re-written in fabric with duplicate "data" wrappers. Query in chaincode: {"selector":{"docTypeId":3,"oriRe":"SMP","ctB":"CTB","valDt":"1990-12-24", "orB":"YYY","tD":"TD","cuVoB":52,"cuIoBu":"AA","cuSt":"NA"}} Result: 2017-03-01 06:48:14.782 UTC [statecouchdb] ApplyQueryWrapper -> DEBU 441 Rewritten query with data wrapper: {"selector":{"$and":[ {"chaincodeid":"marbles"}, {"data.cuIoBu":"AA","data.cuVoB":52,"data.data.ctB":"CTB","data.data.cuSt":"NA", "data.docTypeId":3,"data.orB":"YYY","data.oriRe":"SMP","data.tD":"TD" "data.valDt":"1990-12-24"}]}} Multiple fields have the "data" wrapper repeated. Change-Id: I50445f15222dbdf5bd61e475666c2c34fde6fda4 Signed-off-by: Chris Elder --- .../kvledger/txmgmt/statedb/statecouchdb/query_wrapper.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/query_wrapper.go b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/query_wrapper.go index d73f4eba1ce..cbb823be05d 100644 --- a/core/ledger/kvledger/txmgmt/statedb/statecouchdb/query_wrapper.go +++ b/core/ledger/kvledger/txmgmt/statedb/statecouchdb/query_wrapper.go @@ -198,8 +198,14 @@ func processAndWrapQuery(jsonQueryMap map[string]interface{}) { //the next level of the json query func processInterfaceMap(jsonFragment map[string]interface{}) { - //iterate the the item in the map + //create a copy of the jsonFragment for iterating + var bufferFragment = make(map[string]interface{}) for keyVal, itemVal := range jsonFragment { + bufferFragment[keyVal] = itemVal + } + + //iterate the the item in the map + for keyVal, itemVal := range bufferFragment { //check to see if the key is an operator if arrayContains(validOperators, keyVal) {