1

I know the title is a bit broad, but I have tried a bunch of things with different errors, so I was going to use this space to describe each of them. I have a model in datastax's python-driver below:

class DIDSummary(Model):
    __keyspace__ = 'processor_api'

    did = columns.Text(required=True, primary_key=True, partition_key=True)
    month = columns.DateTime(required=True, primary_key=True, partition_key=True)
    direction = columns.Text(required=True)
    duration = columns.Counter(required=True)
    cost = columns.Counter(required=True)

but then when I try this:

didsummaries = DIDSummary.filter(did__in=dids, month__in=datetime_range)

I get this error:

code=2200 [Invalid query] message="Partition KEY part did cannot be restricted by IN relation (only the last part of the partition key can)"

I then tried this:

class DIDSummary(Model):
    # ...
    month = columns.DateTime(required=True, primary_key=True)
    # ...

Which brought up the error:

code=2200 [Invalid query] message="Clustering column "month" cannot be restricted by an IN relation"

I also tried this:

class DIDSummary(Model):
    # ...
    month = columns.DateTime(required=True, primary_key=True, index=True)
    # ...

Which gave me this error:

InvalidRequest: code=2200 [Invalid query] message="Secondary indexes are not supported on counter tables"

When I tried to sync_table(DIDSummary)

Finally, I tried to do this:

class DIDSummary(Model):
    # ...
    month = columns.DateTime(required=True, primary_key=True)
    direction = columns.Text(required=True)
    # ...

Which wouldn't even let me run the server, ending up with this error in the log:

cassandra.cqlengine.models.ModelDefinitionException: counter models may not have data columns

Any help on how I should better design this so I can run the above command would be greatly appreciated. Thanks!

EDIT: I also have to do this:

didsummaries = DIDSummary.filter(did__in=dids, month=month)

which means that actually did has to be the last part of my partition_key. Can I just assign a random uuid to each element and just lookup the elements based on primary_keys and indexes? Would that work? I'm super lost.

Ethan Brouwer
  • 975
  • 9
  • 32

1 Answers1

1

You need to make direction a primary key too.

From the Datastax documentation:

Define a counter in a dedicated table only and use the counter data type. You cannot index, delete, or re-add a counter column. All non-counter columns in the table must be defined as part of the primary key.

TheGeorgeous
  • 3,927
  • 2
  • 20
  • 33
  • That should solve part of the problem, but will it let me filter by an in query on both parts of the partition key? Or do I have to just live with only querying it using an Eq query? – Ethan Brouwer Jul 20 '15 at 14:47