Skip to content

min, max: Support more than two arguments #1050

@sungwoncho

Description

@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
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

area/parsingIssues related to the parser or lexer.area/querylangIssues related to the query language specification and implementation.exp/expertDeeply technical issue not recommended to beginners.kind/enhancementSomething could be better.status/acceptedWe accept to investigate/work on it.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions