0

I am using aws neptune because of all the advantages it brings for developing a very configurable solution etc. It has been going very well till now until I am required to pull reports based on month name.

I have an attribute createdOn (where I store the datetime of when the ticket was created) for a vertex Ticket, now i need to pull a report which tell me how many tickets were created group by the month.

In MySql it would be a easily done by using MONTHNAME() function and group by clause and get count of the ticket.

Although in gremlin group().by() is there I am not able to find any possibility of using group().by() on the month name only.

I have come across solutions which says that I should be storing month, year, date, hour, min etc as separate attributes to be able to get the desired result but I was wondering if there was a more cleaner approach like the one in MySQL.

Thanks in advance for your help.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38

2 Answers2

0

At present, Neptune currently supports TinkerPop version 3.5.2 while the latest version of TinkerPop is 3.6. Neither of those versions have native support for Date/Time operations to parse a Datetime object into granular components. Only very recently [1] was a datetime() function added to support creating a Datetime object as part of a query.

So as you mentioned, the only current method to do this by storing each component of the date/time as a separate property and grouping based on those properties.

Also important to note that Labeled Property Graph data stored in Neptune is interoperable between both Gremlin and openCypher. So on occasion, there maybe certain aspects of one language that will help with gaps in the other. Unfortunately, the date functions in openCypher are not yet available on Neptune either. :) But I thought I would mention that for future use.

[1] https://issues.apache.org/jira/browse/TINKERPOP-2596

Taylor Riggan
  • 1,963
  • 6
  • 12
0

Adding a second answer that builds on the one from Taylor. This is essentially the art of the possible in Gremlin as it stands today, which would involve having the date stored as multiple properties, or as an integer and doing some pretty complex math (date math being non trivial). To go from the name to an index you could do this:

gremlin>   g.inject(
......1>       [[ 1:'January'],
......2>        [ 2:'February'],
......3>        [ 3:'March'],
......4>        [ 4:'April'],
......5>        [ 5:'May'],
......6>        [ 6:'June'],
......7>        [ 7:'July'],
......8>        [ 8:'August'],
......9>        [ 9:'September'],
.....10>        [10:'October'],
.....11>        [11:'November'],
.....12>        [12:'December']]).
.....13>     unfold().
.....14>     where(select(values).unfold().is('February')).
.....15>     select(keys).
.....16>     unfold()

==>2

Going in the opposite direction

gremlin>     g.inject(
......1>       [[ 1:'January'],
......2>        [ 2:'February'],
......3>        [ 3:'March'],
......4>        [ 4:'April'],
......5>        [ 5:'May'],
......6>        [ 6:'June'],
......7>        [ 7:'July'],
......8>        [ 8:'August'],
......9>        [ 9:'September'],
.....10>        [10:'October'],
.....11>        [11:'November'],
.....12>        [12:'December']]).
.....13>     unfold().
.....14>     where(select(keys).unfold().is(2)).
.....15>     select(values).
.....16>     unfold()

==>February 

Looking towards the future, adding additional date manipulation capabilities to Gremlin is something I would like to see done. It's part of a decent sized list of planned updates for future releases.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38