DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

josef.schauer_169242 avatar image
josef.schauer_169242 asked ·

DSE 6.8 Graph: Sort on UDT subfield

Hello,


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

schema:

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()

schema.vertexLabel('Vertex').searchIndex().ifNotExists().by('id').by('names').create()


data:

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.

Josef


dsegraphuser-defined type
10 |1000 characters needed characters left characters exceeded

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

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

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")
==>[{id:7b2cb045-4fcf-434a-902b-6c65aa2bc8f1,value:'Name2',cids:{ba6ade30-8af8-44a0-8847-fef76f98324f}}]

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 characters needed characters left characters exceeded

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 · ·
josef.schauer_169242 avatar image josef.schauer_169242 bettina.swynnerton ♦♦ ·

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.

Thanks!

0 Likes 0 · ·