Skip to content

Enable using functions on ooquery wheres and Add Unaccent function - #37

Draft
guilleJB wants to merge 12 commits into
masterfrom
76327_enable_unaccent
Draft

Enable using functions on ooquery wheres and Add Unaccent function#37
guilleJB wants to merge 12 commits into
masterfrom
76327_enable_unaccent

Conversation

@guilleJB

Copy link
Copy Markdown
Member

No description provided.

@guilleJB guilleJB self-assigned this Aug 10, 2025
@guilleJB guilleJB changed the title Enable using functions on ooquery wheres Enable using functions on ooquery wheres and Add Unaccent function Aug 10, 2025
@guilleJB

Copy link
Copy Markdown
Member Author

Pyhton 2 an 3 runs

image

@ecarreras
ecarreras requested a review from Copilot September 3, 2025 08:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enables using functions in ooquery where clauses and adds a new Unaccent function for database queries. The changes allow SQL functions to be used in query conditions with proper field resolution and parameter handling.

Key changes:

  • Added support for Function objects in query expressions with recursive parameter resolution
  • Introduced new Unaccent function for PostgreSQL text normalization
  • Enhanced expression parsing to handle functions on both sides of comparisons

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 15 comments.

File Description
spec/ooquery_spec.py Comprehensive test coverage for Unaccent and Upper function usage in queries
ooquery/parser.py Core logic for function resolution and expression parsing with new resolve_value method
ooquery/functions.py New Unaccent function implementation extending sql.functions.Function
ooquery/init.py Module exports updated to include functions module
Comments suppressed due to low confidence (1)

ooquery/parser.py:1

  • [nitpick] Comments are written in Catalan. For consistency and maintainability, consider translating these to English as they document important logic about field resolution and function parameter handling.
# coding=utf-8

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread spec/ooquery_spec.py
sel.where = And((join2.right.code == 'XXX',))
expect(tuple(sql)).to(equal(tuple(sel)))

with it('unnacent funciton runs good'):

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

Spelling errors in test description: 'unnacent' should be 'unaccent' and 'funciton' should be 'function'.

Suggested change
with it('unnacent funciton runs good'):
with it('unaccent function runs good'):

Copilot uses AI. Check for mistakes.
Comment thread spec/ooquery_spec.py
sel.where = And((Upper(t.field3) > Upper('XXXX'),))
expect(tuple(sql)).to(equal(tuple(sel)))

with it('must support Upper queries with fields without especific and values'):

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

Spelling error: 'especific' should be 'specific'.

Suggested change
with it('must support Upper queries with fields without especific and values'):
with it('must support Upper queries with fields without specific and values'):

Copilot uses AI. Check for mistakes.
Comment thread spec/ooquery_spec.py

with it('must support unaccent queries with fields and values'):

from sql.functions import Upper

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The import from sql.functions import Upper is repeated in multiple test cases. Consider moving this import to the top of the file to reduce duplication.

Copilot uses AI. Check for mistakes.
Comment thread spec/ooquery_spec.py
expect(tuple(sql)).to(equal(tuple(sel)))

with it('must support Upper queries'):
from sql.functions import Upper

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The import from sql.functions import Upper is repeated in multiple test cases. Consider moving this import to the top of the file to reduce duplication.

Copilot uses AI. Check for mistakes.
Comment thread spec/ooquery_spec.py
expect(tuple(sql)).to(equal(tuple(sel)))

with it('must support Upper queries with fields and values'):
from sql.functions import Upper

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The import from sql.functions import Upper is repeated in multiple test cases. Consider moving this import to the top of the file to reduce duplication.

Copilot uses AI. Check for mistakes.
Comment thread ooquery/parser.py
if isinstance(value, string_types):
if in_function:
if side == 'right' and '.' not in value:
# dins de funció al RHS, cadena plana ⇒ literal (parametritzada)

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Comments are written in Catalan. For consistency and maintainability, consider translating these to English as they document important logic about field resolution and function parameter handling.

Copilot uses AI. Check for mistakes.
Comment thread ooquery/parser.py
if side == 'right' and '.' not in value:
# dins de funció al RHS, cadena plana ⇒ literal (parametritzada)
return value
# dins de funció al LHS o RHS amb camí 'a.b' ⇒ camp

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Comments are written in Catalan. For consistency and maintainability, consider translating these to English as they document important logic about field resolution and function parameter handling.

Copilot uses AI. Check for mistakes.
Comment thread ooquery/parser.py
return value
# dins de funció al LHS o RHS amb camí 'a.b' ⇒ camp
return self.get_table_field(self.table, value)
# Top-level: LHS ⇒ camp, RHS ⇒ literal

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Comments are written in Catalan. For consistency and maintainability, consider translating these to English as they document important logic about field resolution and function parameter handling.

Copilot uses AI. Check for mistakes.
Comment thread ooquery/parser.py
for p in value.params:
new_params.append(
self.resolve_value(p, side=side, in_function=True))
# IMPORTANT: no mutar tuples! Re-creem la funció amb els params resolts

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Comment is in Catalan. Consider translating to English: '# IMPORTANT: don't mutate tuples! Recreate the function with resolved params'.

Suggested change
# IMPORTANT: no mutar tuples! Re-creem la funció amb els params resolts
# IMPORTANT: don't mutate tuples! Recreate the function with resolved params

Copilot uses AI. Check for mistakes.
Comment thread ooquery/parser.py
Comment on lines 90 to +154
def get_expressions(self, expression):
fields = [expression[0]]
fields = []
if isinstance(expression[0], Function):
resolved_field = self.resolve_value(expression[0], side='left')
fields.append(resolved_field)
else:
fields.append(expression[0])

Copilot AI Sep 3, 2025

Copy link

Choose a reason for hiding this comment

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

The logic for handling Function vs non-Function expressions is duplicated between get_expressions and get_expressions2. Consider consolidating this into a single method or refactoring to avoid duplication.

Copilot uses AI. Check for mistakes.
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.

3 participants