Skip to content

Instantly share code, notes, and snippets.

@bobvanluijt
Last active October 25, 2018 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobvanluijt/a6f812589095f7435e4e8a99a7f8fef6 to your computer and use it in GitHub Desktop.
Save bobvanluijt/a6f812589095f7435e4e8a99a7f8fef6 to your computer and use it in GitHub Desktop.
Idea for grouping
###
# The result below shows the sum of population of all cities.
###
{
Local {
Get(where:{
operands: [{
path: ["Things", "City", "population"],
operator: GreaterThan
valueInt: 1000000
}]
},{
group:{
operands: [{
path: ["Things", "City", "population"],
aggregate: SUM # other options: COUNT, MAX, MIN, SUM, AVG,
}]
}
}) {
Things {
City {
population
}
}
}
}
}
@bobvanluijt
Copy link
Author

That indeed sounds reasonable. Not necessarily in favor for one or the other but syntactically it might absolutely be preferable to introduce a Stats{} function.

Naming wise, maybe Aggregate{} would suit better. Any thoughts @laura-ham and @moretea?

It would also be possible to add all aggregation functions as GQL-functions.

{
  Local {
    Aggregate(where: { ... }) { # or Stats...
      Sum{}
      Percentile{}
      Count{}
      Average{} 
      Maximum{}
      Median{}
      Minimum{}
      Mode{}
      GroupBy() {} # Would be used for more complext group by functions.
  }
} 

@moretea would it be fair to say that splitting these aggregate functions (except for GroupBy()) would be relatively easier to implement?

@moretea
Copy link

moretea commented Oct 25, 2018

Maybe they are simple to implement. I would expect so, based on my experience with SQL. However, Gremlin is not as well rounded, and I did not research this yet for Gremlin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment