Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to order items in makeset? #24135

Closed
imeya opened this issue Feb 4, 2019 — with docs.microsoft.com · 7 comments
Closed

How to order items in makeset? #24135

imeya opened this issue Feb 4, 2019 — with docs.microsoft.com · 7 comments

Comments

Copy link

imeya commented Feb 4, 2019

Is there a way to order items in makeset()?

There are some confusion in docs.

In this doc -> Returns section, it says that
: Returns a dynamic (JSON) array of the set of distinct values that Expr takes in the group. The array's sort order is undefined.

But in another doc, it says that: Like makelist, makeset also works with ordered data and will generate the arrays based on the order of the rows that are passed into it.

I also tried some methods, but no ordering in the makeset() result.

method 1:

let topCities =
requests
   | distinct client_City 
   | order by client_City asc;

topCities
| summarize makeset(client_City)

method 2:

requests
   | distinct client_City 
   | order by client_City asc
   | summarize makeset(client_City) 

And the result like this: ["","Hong Kong","Chicago","Boydton","Campinas","Des Moines"].
but I want the items should be ordered like this: ["","Boydton","Campinas","Chicago","Des Moines","Hong Kong"]


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@MohitVerma-MSFT
Copy link

MohitVerma-MSFT commented Feb 4, 2019

Hi @imeya ,
Thank you for reaching out. Could you please try below syntax:-

requests | summarize makeset(client_City) by client_City | distinct client_City | order by client_City asc

@imeya
Copy link
Author

imeya commented Feb 4, 2019

thank you. But what I want is that the result is a set(in 1 row like ["a","b","c"]), not in many rows like in row1: a, in row 2, b.

MohitVerma-MSFT added a commit that referenced this issue Feb 4, 2019
Proposing changes for makeset functionality as it return array  and sort is undefined in the array item
@MohitVerma-MSFT
Copy link

Hi @imeya ,

I tried to reproduce the issue with the steps you mentioned. here are my findings;
Correct statement with regards to makeset would be , it would returns a dynamic (JSON) array of the set of distinct values that Expr takes in the group. The array's sort order is undefined.
Meanwhile we are working on to correct this document.

Though for a workaround for this , you can use blow query -

requests | summarize makeset(client_City) by client_City | distinct client_City | order by client_City asc

which will give you result in rows and later you can concat the result in one row(comma seperated).

@imeya
Copy link
Author

imeya commented Feb 4, 2019

thanks again. then how to concat the result in one row, with comma seperated?

@MohitVerma-MSFT
Copy link

MohitVerma-MSFT commented Feb 5, 2019

Hi @imeya ,

Try this code , it should give you what you are looking for.

requests | summarize makeset(client_City) by client_City | distinct client_City | order by client_City asc | summarize makelist(client_City)

Hope it helps.

@imeya
Copy link
Author

imeya commented Feb 5, 2019

@MohitVerma-MSFT, thank you very much. Please correct the document. And actually, we can directly use makelist() which supports ordering.

@MohitVerma-MSFT
Copy link

Yes, Makelist preserve the ordering of the input items. I have corrected the document and it will be published soon.
I am closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants