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 get JSON/POJO from the KustoResultSetTable #233

Closed
saumilsdk opened this issue Mar 23, 2022 · 2 comments
Closed

How to get JSON/POJO from the KustoResultSetTable #233

saumilsdk opened this issue Mar 23, 2022 · 2 comments

Comments

@saumilsdk
Copy link

I want to get JSON object or array of JSON POJO objects on the query returning multiple rows. I am not comfortable with iterating each row one by one and creating those manually.

@AsafMah
Copy link
Contributor

AsafMah commented Mar 27, 2022

Either way you will have to create the objects - the rows we get from the server are arrays, and someone has to merge them with the columns.

We don't have anything like this built in, but you can use getData() to easily do it yourself -

KustoOperationResult completeResult= queryClient.execute(<databaseName>, <your query>);
KustoResultSetTable mainTableResult = completeResult.getPrimaryResults();
List<Map<String, Object>> resultMap = mainTableResult.getData()
        .stream().map(row ->
                IntStream.range(0, row.size()).
                        mapToObj(ir -> new AbstractMap.SimpleEntry<>(mainTableResult.getColumns()[ir].getColumnName(), row.get(ir)))
                        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
                        .collect(Collectors.toList());

JSONArray jsonArray = new JSONArray(resultMap);

@yihezkel
Copy link
Member

yihezkel commented Apr 5, 2022

Hi @saumilsdk,

We implemented executeToJsonResult() to bypass the conversion to KustoResultSetTable in the first place. It returns the json as a String, intended for specific performance scenarios.

That said, our service returns results in this KustoResultSetTable format, so the json will still need to be parsed to obtain the POJO components of it.

I want to understand your issue better, though. What do you mean by, "I am not comfortable with iterating each row one by one and creating those manually"? What exactly is the concern with working with a KustoResultSetTable object? Note that we have examples of working with results.

@yogilad yogilad closed this as completed Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants