title: Compare a property value to an aggregated value in Gremlin
body: <p>I'm trying to implement a sort of "window function" in a Gremlin query: I want to select all the edges leaving a vertex, which have a timestamp within 24 hours of the last update (local to the vertex).</p>
  
  <p>For example if User A accessed the following resources:</p>
  
  <ul>
  <li>Resource 1 at 2019/04/02 23:00</li>
  <li>Resource 2 at 2019/04/02 01:00</li>
  <li>Resource 3 at 2019/04/01 22:00</li>
  </ul>
  
  <p>.. then I'd want the query to return resources 1 &amp; 2, and omit resource 3 because it was accessed 25 hours before User A's latest access (outside the 24-hour window).</p>
  
  <p>I've tried a few different approaches, for example using <code>local</code> and <code>aggregate</code>:</p>
  
  <pre><code>g.V()
    .hasLabel(VertexLabel.User)
  
    .local(__.outE(EdgeLabel.Accesses) // I also tried "sideEffect" here
      .values(EdgeProperties.UpdateTime).max().math("_ - 24*60*60*1000")
      .aggregate("windowStart"))
  
    .where(
        __.outE(EdgeLabel.Accesses)
          .has(EdgeProperties.UpdateTime, P.gt("windowStart"))
    )
  </code></pre>
  
  <p>This particular example gives me the error <code>ClassCastException: java.lang.Double cannot be cast to org.apache.tinkerpop.gremlin.structure.Element</code>.</p>
  
  <p>And also using a <code>sack</code>:</p>
  
  <pre><code>g.V()
    .hasLabel(VertexLabel.User)
  
    .sack(Operator.assign).by(
      __.outE(EdgeLabel.Accesses).values(EdgeProperties.UpdateTime).max())
    .sack(Operator.minus).by(__.constant(24*60*60*1000)
  
    .where(
        __.outE(EdgeLabel.Accesses)
          .not(__.sack().is(P.gt(__.values(EdgeProperties.UpdateTime))))
    )
  </code></pre>
  
  <p>This gives me the error <code>ClassCastException: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal cannot be cast to java.lang.Long</code>.</p>
  
  <p>I feel like I'm just getting hung up on Gremlin semantics--I'm trying to compare the values in the wrong form. What do I need to do to access the "windowStart" value for the current vertex in the traversal, in a gt/lt predicate?</p>