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 SpEL in @Query #2826

Merged
merged 11 commits into from Jan 19, 2024
Merged

Conversation

puppylpg
Copy link
Contributor

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our issue tracker. Add the issue number to the Closes #issue-number line below
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

Closes #2083

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 13, 2024
Copy link
Collaborator

@sothawo sothawo left a comment

Choose a reason for hiding this comment

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

Nice work. I have some remarks and questions and will do more tests later that week (being a little busy currently in the evenings).

And this needs to be added to the reactive parts as well.

/**
* Convert a collection into string for value part of the elasticsearch query.
* <p>
* The string should be wrapped with square brackets, with each element quoted therefore
Copy link
Collaborator

Choose a reason for hiding this comment

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

quoted elements means Strings? What about other types, i.e. numeric ones?

Copy link
Contributor Author

@puppylpg puppylpg Jan 17, 2024

Choose a reason for hiding this comment

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

The non string types will be converted correctly by other converters in ConversionSerivce. Take integers as the example:

				{
				  "bool":{
				    "must":{
				      "terms":{
				        "age": [1, 2, 3]
				      }
				    }
				  }
				}

I'll add more tests to prove this.

Copy link
Contributor Author

@puppylpg puppylpg Jan 17, 2024

Choose a reason for hiding this comment

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

And the comment is also changed to avoid this misleading.

Object targetElement = this.conversionService.convert(
sourceElement, sourceType.elementTypeDescriptor(sourceElement), targetType);
if (sourceElement instanceof String) {
sb.add("\"" + targetElement + "\"");
Copy link
Collaborator

Choose a reason for hiding this comment

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

targetElement can be null at this place; the + and the valueOf will convert this to `"null"; is that ok or should that produce an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the code to check that source is not null, and target may have no need to check null again after that.

puppylpg and others added 3 commits January 17, 2024 10:39
Co-authored-by: Peter-Josef Meisch <pj.meisch@sothawo.com>
@puppylpg
Copy link
Contributor Author

puppylpg commented Jan 17, 2024

Review suggestions are accepted and more tests has been added. Reactive parts will be handle later.

UPDATE: reactive parts is also finished.

@puppylpg puppylpg requested a review from sothawo January 17, 2024 08:57
@sothawo sothawo merged commit e1a2412 into spring-projects:main Jan 19, 2024
1 check passed
@puppylpg puppylpg deleted the query-spel branch February 19, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for SpEl in @Query
3 participants