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

add support for partial indexes #159

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

timgraham
Copy link
Collaborator

refs #104

where = query.build_where(self.condition)
compiler = query.get_compiler(connection=schema_editor.connection)
mql_ = where.as_mql(compiler, schema_editor.connection)
# Transform aggregate() query syntax into find() syntax.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stinks and doesn't work for multiple conditions / null conditions (but maybe could be done). I wonder if it would be better to have a separate path from as_mql() to generate find() compatible MQL rather than trying to convert from the aggregate syntax.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, we're pulling the index conditions from a model's field definitions using the compiler built by the schema editor? Is this schema_editor compiler different from our Mongo one?

can self.condition ever be a list of items?

Speaking more broadly, I'd say, yes, let's include the find compatible conversions, but how many nodes/expressions would we need that for? Also, since find is much more limited there would still be gaps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query.get_compiler() is the same compiler we use for other queries.

condition is a Q object: "For example, condition=Q(pages__gt=400) indexes records with more than 400 pages."

What doesn't currently work is multiple conditions like:

Q(
    pub_date__gt=datetime.datetime(
        year=2015,
        month=1,
        day=1,
        tzinfo=timezone.get_current_timezone(),
    )
)
& Q(headline__contains="China")

Maybe that can be translated without too much difficulty. I didn't think about it too much.

Obviously, we can only support conditions that MongoDB supports.

Copy link
Collaborator

@Jibola Jibola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments! Will circle back and ask some more tomorrow :)

if unique:
kwargs["unique"] = True
if field:
filter_expression[field.column].update({"$type": field.db_type(self.connection)})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to maintain type? if so, why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is below: "Use partialFilterExpression to allow multiple null values for a unique constraint." It's not really in the best spot and should be amended to reference $type since partialFilterExpression is also used for condition.

where = query.build_where(self.condition)
compiler = query.get_compiler(connection=schema_editor.connection)
mql_ = where.as_mql(compiler, schema_editor.connection)
# Transform aggregate() query syntax into find() syntax.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, we're pulling the index conditions from a model's field definitions using the compiler built by the schema editor? Is this schema_editor compiler different from our Mongo one?

can self.condition ever be a list of items?

Speaking more broadly, I'd say, yes, let's include the find compatible conversions, but how many nodes/expressions would we need that for? Also, since find is much more limited there would still be gaps.

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

Successfully merging this pull request may close these issues.

2 participants