Start a new topic

Aggregation doesn't return any data in onSuccess callback but data is shown in HttpTransport logcat...

Making an aggregation count call on android doesn't return anything in the onSuccess. Even though onSuccess is called the data is empty. While debugging and looking at HtttpTransport log, I do see the data correctly. Using the same aggregation count on iOS/RestAPI etc works fine.


08-13 06:36:51.965 D/HttpTransport(22952): -------------- REQUEST --------------

08-13 06:36:51.965 D/HttpTransport(22952): POST https://baas.kinvey.com/appdata/kid_-yj4pCgcq/00CCUZones/_group

08-13 06:36:51.965 D/HttpTransport(22952): Accept-Encoding: gzip

08-13 06:36:51.965 D/HttpTransport(22952): Authorization: <Not Logged>

08-13 06:36:51.965 D/HttpTransport(22952): Content-Type: application/json; charset=UTF-8

08-13 06:36:51.965 D/HttpTransport(22952): User-Agent: android-kinvey-http/2.6.14

08-13 06:36:51.965 D/HttpTransport(22952): x-kinvey-api-version: 3

08-13 06:36:51.965 D/HttpTransport(22952): x-kinvey-device-information: Asus/Nexus_7 Android 4.2.2 bdd8697f-95b3-37c3-8974-2baf8e8a847f

08-13 06:36:51.965 D/HttpTransport(22952): Content-Type: application/json; charset=UTF-8

08-13 06:36:51.965 D/HttpTransport(22952): Content-Length: 94

08-13 06:36:51.965 D/HttpTransport(22952): curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.6.14' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: Asus/Nexus_7 Android 4.2.2 bdd8697f-95b3-37c3-8974-2baf8e8a847f' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/appdata/kid_-yj4pCgcq/00CCUZones/_group' << $$$

08-13 06:36:51.975 D/HttpTransport(22952): Total: 94 bytes

08-13 06:36:51.975 D/HttpTransport(22952): {"initial":{"_result":0},"key":{"room_id":true},"reduce":"function(doc,out){ out._result++;}"}

08-13 06:36:52.265 D/HttpTransport(22952): -------------- RESPONSE --------------

08-13 06:36:52.265 D/HttpTransport(22952): 200 OK

08-13 06:36:52.265 D/HttpTransport(22952): Content-Length: 347

08-13 06:36:52.265 D/HttpTransport(22952): Content-Type: application/json; charset=utf-8

08-13 06:36:52.265 D/HttpTransport(22952): Date: Thu, 13 Aug 2015 11:36:52 GMT

08-13 06:36:52.265 D/HttpTransport(22952): Server: ngx_openresty

08-13 06:36:52.265 D/HttpTransport(22952): X-Android-Received-Millis: 1439465812263

08-13 06:36:52.265 D/HttpTransport(22952): X-Android-Sent-Millis: 1439465811976

08-13 06:36:52.265 D/HttpTransport(22952): X-Kinvey-API-Version: 3

08-13 06:36:52.265 D/HttpTransport(22952): X-Kinvey-Request-Id: 44c14cf12ba14c048e9389d8288062bd

08-13 06:36:52.265 D/HttpTransport(22952): X-Powered-By: Express

08-13 06:36:52.265 D/HttpTransport(22952): Total: 347 bytes

08-13 06:36:52.265 D/HttpTransport(22952): [{"room_id":0,"_result":35},{"room_id":1,"_result":21},{"room_id":2,"_result":9},{"room_id":3,"_result":6},{"room_id":4,"_result":5},{"room_id":-1,"_result":27},{"room_id":5,"_result":4},{"room_id":6,"_result":4},{"room_id":7,"_result":2},{"room_id":8,"_result":1},{"room_id":9,"_result":1},{"room_id":10,"_result":1},{"room_id":null,"_result":1}]


 

AsyncAppData<GenericJson> error = getKinveyClient().appData("00CCUZones", GenericJson.class);
ArrayList<String> fields = new ArrayList<String>();
fields.add("room_id");
		
error.count(fields, null, new KinveyAggregateCallback() {
		    @Override
		    public void onSuccess(Aggregation res) { 
		    	if (res != null) {
					Log.d("KINVEY_ALERTS", "aggregate success: ".concat(res.toString()));
					Log.i("KINVEY_ALERTS",  "got: " + String.valueOf(res.results.length));
		    	}
			else
					Log.d("KINVEY_ALERTS", "aggregate success: ".concat("null"));
		        
		    }  
		    @Override
		    public void onFailure(Throwable error) {
		        Log.d("KINVEY_ALERTS", "something went wrong ".concat(error.toString()));
		    }     
		});

 


Awaiting some response? Is this a real bug or something wrong at my end?

Hello Pankaj,


We are currently working to test this issue now.  I will get back to you on this shortly.


Thanks,

Hi Damien


Any update on this. I see the issue anytime there is a array that comes in response. Even though the HttpTransport response shows that the data has arrived, the Kinvey client library for android is not able to serialism it correct to a json object and so the onSuccess reports a null.


Thanks

Pankaj

Hello Pankaj,


The reason that this isn't working is due to the fact that you're calling:


AsyncAppData<GenericJson> error = getKinveyClient().appData("00CCUZones", GenericJson[].class);


When you should be calling: 


AsyncAppData<GenericJson[]> error = getKinveyClient().appData("00CCUZones", GenericJson[].class);


You are correct in that the library is behaving poorly (onSuccess shouldn't be passed a null, it should instead be failing) but we are confident that this should resolve the issue in the near term.


Let me know if this handles your issue.


Thanks,

Thanks it worked.


Pankaj


I'm with the same problem. Putting GenericJSON[] in AsyncAppData<GenericJSON[]> and appData("expenses", GenericJSON[]) gives an error:


----> java.lang.ClassCastException: com.google.api.client.json.GenericJson[] cannot be cast to com.kinvey.java.model.Aggregation$Result[]

at com.kinvey.java.core.KinveyAggregateCallback.onSuccess(KinveyAggregateCallback.java:21)



# Kinvey Version Android - 2.10.5


# Expense Class


public class Expense extends GenericJson {


@Key("_id")

private String id;

@Key("_acl")

private KinveyMetaData.AccessControlList acl;

@Key("_kmd")

private KinveyMetaData meta;

@Key

private String date;

@Key

private String km;

@Key

private String note;

@Key

private String description;

@Key

private Double valueParts;

@Key

private Double valueServices;

@Key

private Double valueTotalExpense;

@Key

private String idExpenseType;

@Key

private String idExpenseTypeCategory;

@Key

private String idVehicle;

@Key

private String month;

@Key

private String year;

@Key

private KinveyReference expenseTypesReference;

@Key

private KinveyReference expenseTypeCategoryReference;


public Expense() {

acl = new KinveyMetaData.AccessControlList();

meta = new KinveyMetaData();

}

...

}


# Method


public void getAnualExpenses(Vehicle vehicle, String year, final KinveyDAOCallback daoCallback) {


final AsyncAppData<GenericJson> aggregate = app.getKinveyClient().appData(Expense.collectionName, GenericJson.class);

aggregate.setOffline(OfflinePolicy.ONLINE_FIRST, new SqlLiteOfflineStore<GenericJson>(app));


ArrayList<String> fields = new ArrayList<>();

fields.add("month");


Query query = app.getKinveyClient().query();

query.equals("year", year);

query.equals("idVehicle", vehicle.getId());

app.getKinveyClient().enableDebugLogging();

aggregate.sum(fields, "valueTotalExpense", query, new KinveyAggregateCallback() {

@Override

public void onSuccess(Aggregation aggregation) {

if (aggregation.results == null || aggregation.results.length == 0) {

Log.d("TEST", "No results found");

} else {

Log.d("TEST", aggregation.results.toString());

Log.d("TEST", "Count: " + aggregation.results.length);

}

app.getKinveyClient().disableDebugLogging();

}


@Override

public void onFailure(Throwable throwable) {

Log.e("TEST", "" + throwable.toString());

}

});

}



# LOG


02-13 15:27:23.786 16593-16670/? D/HttpTransport: -------------- REQUEST --------------

POST https://baas.kinvey.com/appdata/kid_bk1mkLf2j/expenses/_group

Accept-Encoding: gzip

Authorization: <Not Logged>

Content-Type: application/json; charset=UTF-8

User-Agent: android-kinvey-http/2.10.5

x-kinvey-api-version: 3

x-kinvey-device-information: samsung/GT-I9500 Android 5.0.1 20050068-a3ce-377d-beff-2af8da9875fc

Content-Type: application/json; charset=UTF-8

Content-Length: 194

02-13 15:27:23.786 16593-16670/? D/HttpTransport: curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'Content-Type: application/json; charset=UTF-8' -H 'User-Agent: android-kinvey-http/2.10.5' -H 'x-kinvey-api-version: 3' -H 'x-kinvey-device-information: samsung/GT-I9500 Android 5.0.1 20050068-a3ce-377d-beff-2af8da9875fc' -H 'Content-Type: application/json; charset=UTF-8' -d '@-' -- 'https://baas.kinvey.com/appdata/kid_bk1mkLf2j/expenses/_group' << $$$

02-13 15:27:23.801 16593-16670/? D/HttpTransport: Total: 194 bytes

02-13 15:27:23.801 16593-16670/? D/HttpTransport: {"condition":{"year":"2016","idVehicle":"56a6710a94e2949919026fcb"},"initial":{"_result":0},"key":{"month":true},"reduce":"function(doc,out){ out._result= out._result + doc.valueTotalExpense;}"}

02-13 15:27:24.061 16593-16670/? D/HttpTransport: -------------- RESPONSE --------------

200 OK

Content-Type: application/json

Date: Sat, 13 Feb 2016 17:27:25 GMT

Server: ngx_openresty

Transfer-Encoding: chunked

X-Android-Received-Millis: 1455384444063

X-Android-Response-Source: NETWORK 200

X-Android-Sent-Millis: 1455384443797

X-Kinvey-API-Version: 3

X-Kinvey-Request-Id: e29b14e5414d4e9cb864e7007d85ab8f

X-Powered-By: Express

02-13 15:27:24.061 16593-16670/? D/HttpTransport: Total: 29 bytes

02-13 15:27:24.061 16593-16670/? D/HttpTransport: [{"month":"2","_result":250}]

Login or Signup to post a comment