Mapper find by secondary index

26 views
Skip to first unread message

Kilian Gosewisch

unread,
Sep 17, 2019, 3:19:33 PM9/17/19
to DataStax Node.js Driver for Apache Cassandra Mailing List
https://github.com/koriwi/nodejs-driver/commit/446d233fd5f2fd0bb40950c4216b904f4dd21a10

I had to add this getto fix right now because it is not possible/I'm to stupid to figure out how to do this correctly.

(Can't insert code because I'm on my phone)

Chat.find(subChats: q.contains('xxxid'))

It gives me an error that I did not specify enough primary keys.
But as a written query in cqlsh it works fine and with my little fix mentioned above.

Jorge Bay Gondra

unread,
Sep 18, 2019, 6:26:02 AM9/18/19
to nodejs-dr...@lists.datastax.com
Hi,
Currently the Mapper doesn't support secondary indexes


The patch you linked is in the good direction to add support for secondary indexes, but we would need several unit and integration tests to properly support secondary indexes in the Mapper.

Thanks,
Jorge


Kilian Gosewisch

unread,
Sep 18, 2019, 7:09:30 AM9/18/19
to nodejs-dr...@lists.datastax.com
Hi Jorge,
ok cool. 
Maybe if i got time in the future could complete this. for now it's working fine since 3 months or so.

Another question, https://github.com/koriwi/nodejs-driver/commit/46de110a1c0fa660e6e43d69263eb506a1a31843
I had to add this, because the object selector was crashing when i had more than one table per mapping. If the correct table was in second place in the array, it crashed.

--
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs-driver-u...@lists.datastax.com.

Jorge Bay Gondra

unread,
Sep 18, 2019, 8:27:21 AM9/18/19
to nodejs-dr...@lists.datastax.com
Hi Kilian,
interesting... could you share the schema of the tables?

Thanks,
Jorge

Kilian Gosewisch

unread,
Sep 18, 2019, 11:04:45 AM9/18/19
to nodejs-dr...@lists.datastax.com
Message: {
      tables: ['messages''messages_created_at'],
      keyspace: process.env.CASSANDRA_SCHEMA || 'maet',
      mappings: new mapping.UnderscoreCqlToCamelCaseMappings()
    }

CREATE TABLE maet.messages (
    id timeuuid PRIMARY KEY,
    attachments set<timeuuid>,
    chat_id timeuuid,
    from_user timeuuid,
    text text
)

CREATE TABLE maet.messages_created_at (
    chat_id timeuuid,
    id timeuuid,
    attachments set<timeuuid>,
    from_user timeuuid,
    text text,
    PRIMARY KEY (chat_id, id)
) WITH CLUSTERING ORDER BY (id ASC)

Jorge Bay Gondra

unread,
Sep 23, 2019, 5:34:36 AM9/23/19
to nodejs-dr...@lists.datastax.com
Hi Kilian,
I had some to review what could be causing the issue you were describing.

The underlying cause is the change in the condition you added here: https://github.com/datastax/nodejs-driver/compare/master...koriwi:index#diff-2d8698072357494ca328277e230d25e8R66. As validation passes above, it fails below.

For the Mapper in the driver codebase, this can be an issue in the (not very common) scenario where the user defines related tables with the same partition keys and different amount of clustering columns. In any case, it's safer to include the additional guard clause, I'll add it :)

Thanks,
Jorge

Kilian Gosewisch

unread,
Sep 26, 2019, 6:49:30 AM9/26/19
to nodejs-dr...@lists.datastax.com
Ah okay. I see.

Right now I'm rebasing my branch on you new release and testing it further :)
Reply all
Reply to author
Forward
0 new messages