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

Ordering with default value doesn't work #53

Open
vmx opened this issue Dec 12, 2017 · 1 comment · May be fixed by #57
Open

Ordering with default value doesn't work #53

vmx opened this issue Dec 12, 2017 · 1 comment · May be fixed by #57

Comments

@vmx
Copy link
Member

vmx commented Dec 12, 2017

According to the query language reference, it's possible to have a default value for the ordering, if the field it is ordered on isn't defined.

Here's an example:

drop target/tests/querytestorder;
create target/tests/querytestorder;

add {"_id":"9", "bar": true};
"9"
add {"_id":"10", "bar": false};
"10"
add {"_id":"15", "foo":"coll", "bar": "string"};
"15"
add {"_id":"18"};
"18"

# This one is OK
find {}
order .bar asc
return .bar;
[
null,
false,
true,
"string"
]

# This one is also OK
find {}
order .bar default=1 asc
return .bar default=1;
[
false,
true,
1,
"string"
]

# This one fails. It returns `null` as first element.
# If it would take the `default=1` into account,
# it would have the order shown below.
find {}
order .bar default=1 asc
return .bar;
[
false,
true,
null,
"string"
]
@vmx
Copy link
Member Author

vmx commented Dec 12, 2017

The bug only happens if the value that it is ordered by is also returned. If you return e.g. the _id it workds as expected:

find {}
order .bar asc
return ._id;
[
"18",
"10",
"9",
"15"
]

# As epected, the "18" is now at the third position, not the first anymore.
find {}
order .bar default=1 asc
return ._id;
[
"10",
"9",
"18",
"15"
]

Thanks @Damienkatz for pointing that out.

vmx added a commit to vmx/noise that referenced this issue Dec 14, 2017
When there's a default value specified on the order clause on a
Keypath that is also part of the return value with a different
default value, then the returned results were wrong. It was sorted
by the return value default, not by the order clause default.

This fixes pipedown#53.
@vmx vmx linked a pull request Dec 14, 2017 that will close this issue
vmx added a commit to vmx/noise that referenced this issue Dec 17, 2017
When there's a default value specified on the order clause on a
Keypath that is also part of the return value with a different
default value, then the returned results were wrong. It was sorted
by the return value default, not by the order clause default.

This fixes pipedown#53.
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

Successfully merging a pull request may close this issue.

1 participant