Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



josef.schauer_169242 avatar image
josef.schauer_169242 asked josef.schauer_169242 commented

DSE 6.8 Graph: Sort on UDT subfield


I have the following question: How to sort on UDT subfields?


schema.type('UDT').ifNotExists().property('id', Uuid).property('value', Varchar).property('cids', setOf(Uuid)).create()
schema.vertexLabel('Vertex').ifNotExists().partitionBy('id', Uuid).property('names', setOf(frozen(typeOf('UDT')))).create()



g.addV('Vertex').property('id', UUID.randomUUID())
.property('names', [ [ id: UUID.randomUUID(), value:'Name1', cids: [UUID.randomUUID()] as Set] as UDT] as Set)

g.addV('Vertex').property('id', UUID.randomUUID())
.property('names', [ [ id: UUID.randomUUID(), value:'Name2', cids: [UUID.randomUUID()] as Set] as UDT] as Set)

I want to sort on the values in names, is this possible? I found in the documentation (link), that it is not possible in DSE Search. But is it possible in a gremlin Query?

Thanks in advance.


dsegraphuser-defined type
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

bettina.swynnerton avatar image
bettina.swynnerton answered bettina.swynnerton commented

Hi @josef.schauer_169242,

no, unfortunately it is not possible to retrieve the nested UDT properties by traversal and sort them.

It's possible to query and filter using the nested properties, but can't retrieve them individually as values (and then sort them).

gremlin> g.V().hasLabel("Vertex").has("names.value", "Name2").values("names")

The following query returns no results, as "names.value" is not recognised as a property:

g.V().hasLabel("Vertex").has("names.value", "Name2").values("names.value")

I hope this helps.

5 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

as a side note, it might be better to avoid using "id" as a property name, as I mentioned in a previous answer, particularly to avoid serialisation conflicts. Not sure wether this is still possible.

0 Likes 0 ·

I saw your previous comment. Thanks.

0 Likes 0 ·

This solution would mean I have to sort in the client, but this makes no sense, because usually sorting is applied together with paging and then we are not able to use both together.

Is it planned to support sorting on UDT subfields? It's mandatory for us.

Is there another way to have some kind of SubProperties and have sorting available?

0 Likes 0 ·

@bettina.swynnerton Can you please answer this question.

0 Likes 0 ·

Hi @josef.schauer_169242,

I am discussing with the wider team to understand what options we have, will get back to you.


0 Likes 0 ·
karsten.stoehr avatar image
karsten.stoehr answered josef.schauer_169242 commented

To finish this question: DSE 6.8.3 has just been released which adds the desired functionality. Taking the above schema I can now execute for example the following gremlin query:


which returns the result [ "Name2", "Name1" ].

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

How do I get the complete vertex back?

I need the whole information of the vertices which were sorted before.

0 Likes 0 ·

could answer it on my own:

g.V().order().by(values('names').unfold().values('value').unfold(), asc).elementMap()

0 Likes 0 ·