Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Querying after partitioning returns an empty result #60

Open
tahmidkhan opened this issue Feb 22, 2019 · 0 comments
Open

Querying after partitioning returns an empty result #60

tahmidkhan opened this issue Feb 22, 2019 · 0 comments

Comments

@tahmidkhan
Copy link

tahmidkhan commented Feb 22, 2019

The project is running on Django. I set up my model as follows:

import architect
from django.contrib.postgres.fields import JSONField

@architect.install('partition', type='range', subtype='string_firstchars', constraint='10', column='collection')
class PartitionedDocument(models.Model):
	collection = models.CharField(max_length=10)
	content = JSONField(default=dict)

In other words, I am partitioning using the first 10 characters of the collection field. Plus, I ensure the collection is always a string of 10 characters (from a pre-determined list), so its a nice partitioning system. The list looks like this:

collection_labels = [
	'91IJAYXLPc',
	'kzMZFCHavP',
	'SMyJzyY9ze',
	'EAW95zQtED',
	'AzDWtgZ6MA',
	'Kv7wrKX9m3',
	'BO9CsGIqpd',
	'fQhDlqVNJs',
	'tvj1zF3Nmm',
	'IAPzdfsjFM',
	'hLuumRvCK4',
	'ErwIeGjMwE',
	'ebS3sy7xmJ',
	'aLyd8Hrcpe',
	'8hdhGCFmJU',
	'AfT7kLR0ep',
	'0MPS0KLsrT',
	'k17vDmktNB',
	'SluHmP1X2K',
	'9OMXJZJqHE'
]

Anyway, I added some data to my database after doing all this, and then ran a query like so:

PartitionedDocument.objects.annotate(
    full_name = RawSQL("(content->>'full_name')::text", []),
    age = RawSQL("(content->>'age')::int", [])
).filter(
    age__gte = 30
).extra(where=["lower(substr(collection, 1, 10)) = '91IJAYXLPc'"])

If everything went correctly, I should only be hitting the table that corresponds to the collection with a value of '91IJAYXLPc', and then I would filter based on the JSONField. I know for a fact that objects that fall under this condition exists in my database, however, the queryset returned is empty.

Did I do something wrong? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant