Skip to content

Conversation

@henadzit
Copy link
Contributor

@henadzit henadzit commented Feb 5, 2025

Description

Implements the following lookup types for ArrayField:

  • contains - await ArrayFields.filter(array__contains=[1, 2, 3]).first() which will use the @> operator
  • contained_by - will use the <@ operator
  • overlap - will use the && operator
  • len - will use the array_length function, e.g. await ArrayFields.filter(array__len=3).first()

Motivation and Context

This should close #1857 and #370.

The filters are modeled after Django's counterparts.

How Has This Been Tested?

make ci

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 5, 2025

CodSpeed Performance Report

Merging #1877 will not alter performance

Comparing henadzit:feat/array-filters (3cccc75) with develop (0898c2b)

Summary

✅ 16 untouched benchmarks

@henadzit
Copy link
Contributor Author

henadzit commented Feb 5, 2025

The psycopg tests are failing with

psycopg.errors.UndefinedFunction: operator does not exist: integer[] <@ smallint[]
LINE 1: SELECT "array" "0" FROM "arrayfields" WHERE "array"<@$1

because psycopg is trying to use the smallest type possible... I need to think how to overcome this.

@henadzit
Copy link
Contributor Author

The psycopg tests are failing with

psycopg.errors.UndefinedFunction: operator does not exist: integer[] <@ smallint[]
LINE 1: SELECT "array" "0" FROM "arrayfields" WHERE "array"<@$1

because psycopg is trying to use the smallest type possible... I need to think how to overcome this.

Fixed!

@coveralls
Copy link

coveralls commented Feb 13, 2025

Pull Request Test Coverage Report for Build 13367452752

Details

  • 53 of 60 (88.33%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.002%) to 89.424%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tortoise/filters.py 24 31 77.42%
Totals Coverage Status
Change from base Build 13362403703: -0.002%
Covered Lines: 6527
Relevant Lines: 7123

💛 - Coveralls

return get_backward_fk_filters(field_name, field)
if isinstance(field, JSONField):
return get_json_filter(field_name, source_field)
if field:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that if field is not None is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


Changed
^^^^^^^
- add benchmarks for `get_for_dialect` (#1862)
Copy link
Contributor Author

@henadzit henadzit Feb 17, 2025

Choose a reason for hiding this comment

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

Removed the internal notes that important only for the development process, not for the package users.

@henadzit henadzit requested a review from waketzheng February 17, 2025 10:22
@henadzit henadzit merged commit 5aae984 into tortoise:develop Feb 17, 2025
9 checks passed
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.

Array filter for postgres

3 participants