Moved from GitHub dgraph/1050
Posted by sungwoncho:
Version: 0.7.7
When aggregating using min
or max
, as a user I would like to do the following:
max(v1, v2, v3)
rather than
max(max(v1, v2), v3)
Therefore it might be useful if min
and max
supported more than two arguments.
Use case: https://gist.github.com/sungwoncho/ddba3a287ad87288331c493c2de5a5cb#file-get_active_answers
Dataset:
dgraph-1-2017-07-10-18-51.rdf.gz
dgraph-schema-1-2017-07-10-18-51.rdf.gz
Query:
# You might need to change the value of id
{
var (id: 0xd18499a5ac49c3a6) {
Has.Answer {
answerTs as Timestamp
~Post {
historyTs as Timestamp
}
Comment {
commentTs as Timestamp
}
commentTsMax as max(var(commentTs))
historyTsMax as max(var(historyTs))
lastActive as math(max(max(answerTs, commentTsMax), historyTsMax))
# The following line should work, if replaced with the above line
# lastActive as math(max(answerTs, commentTsMax, historyTsMax))
}
}
question(id: 0xd18499a5ac49c3a6) {
Has.Answer(orderdesc: var(lastActive)) {
Body {
Text
}
}
}
}