1

I need to sort by a field in a SAQL query, but I do not want that field to appear in my results.

For example, I am trying to do this

q = load "xxx";
q = foreach q generate 'account_id' as 'account_id', 'asset_type' as 'Asset Type', 'asset_name' as 'Asset Name', 'asset_link' as 'Asset Link';
q = order q by ('rank' asc, 'Asset Type' asc);

but I get the following error.

Unknown IDTOKEN: rank

However, if do this:

q = load "xxx";
q = foreach q generate 'account_id' as 'account_id', 'asset_type' as 'Asset Type', 'asset_name' as 'Asset Name', 'asset_link' as 'Asset Link', 'rank' as 'rank';
q = order q by ('rank' asc, 'Asset Type' asc);

It works just fine.

I don't want the rank field to appear on my results, but I do not seem to have any luck with this.

1

Appending another query line should work here:

s = foreach q generate 'account_id' as 'account_id', 'asset_type' as 'Asset Type', 'asset_name' as 'Asset Name', 'asset_link' as 'Asset Link'

So the final SAQL would become

q = load "xxx";
q = foreach q generate 'account_id' as 'account_id', 'asset_type' as 'Asset Type', 'asset_name' as 'Asset Name', 'asset_link' as 'Asset Link', 'rank' as 'rank';
q = order q by ('rank' asc, 'Asset Type' asc);
s = foreach q generate 'account_id' as 'account_id', 'asset_type' as 'Asset Type', 'asset_name' as 'Asset Name', 'asset_link' as 'Asset Link'

Explanation: Here the variable 'q' has got the resultset sorted. Now in variable 's', I am selecting the required fields from the resultset 'q'

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.