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

MBCUSTOMQUERY results should have a consistent column order by selector index not alias #40

Open
daenamkim opened this issue Dec 2, 2020 · 2 comments · May be fixed by #50
Open

MBCUSTOMQUERY results should have a consistent column order by selector index not alias #40

daenamkim opened this issue Dec 2, 2020 · 2 comments · May be fixed by #50
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@daenamkim
Copy link
Collaborator

daenamkim commented Dec 2, 2020

MBCUSTOMQUERY result columns are generated in order by alias of selector but it should be by index of selector to keep a consistent column order no matter what alias is.

alias: account, index: 0

Screen Shot 2020-12-02 at 13 11 28

alias: sender, index: 0

Screen Shot 2020-12-02 at 13 11 48

This part might need be fixed.

function keysFromObj(obj, sort) {
const keys = [];
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const key in obj) {
keys.push(key);
}
if (sort) {
keys.sort();
}
return keys;
}

@daenamkim daenamkim added question Further information is requested bug Something isn't working labels Dec 2, 2020
@daenamkim daenamkim self-assigned this Dec 7, 2020
@daenamkim
Copy link
Collaborator Author

@shoenseiwaso

I additionally found a backend API changes columns order according to alias (high priority) or name but not an input index in MBQUERY().
It reads presets from the backend so I might need to change backend for this.
What do you think?

MBCUSTOMQUERY() can set an input index in the spreadsheet so the order can be changed no matter what the backend returns.

If I set amount's alias to "total" from event query in the MultiBaas then the column will be switched.
image

@daenamkim daenamkim linked a pull request Dec 11, 2020 that will close this issue
@shoenseiwaso
Copy link
Collaborator

The back-end returns results in both cases as an array of objects (map). The elements (key/value pairs) are unordered by definition, even if the back-end always appears to return them in a consistent order, we cannot rely on this.

My suggestion for now is to use the default order for MBQUERY(), and for the spreadsheet plugin to re-order into the same order as the custom query for MBCUSTOMQUERY().

In the future (separate issue, low priority) for MBQUERY() we can first lookup the Event Query definition and then order by that order, but that is too much work for too little benefit at this point, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants