Skip to content

DATACOUCH-616 - Fix parsing of String Query containing conditionals i… #265

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

Closed
wants to merge 2 commits into from

Conversation

mikereiche
Copy link
Collaborator

…n quotes

For a query as below that has conditional portions, the parsing for
parameters was being done before the conditional portions were being
resolved, which left the parameters between quotes where they wre
not being recognized as query parameters.

@query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
" #{#projectIds != null ? 'AND iata IN $1' : ''} ")
Long count(@param("projectIds") List projectIds)

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • 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).

@mikereiche mikereiche requested a review from daschl September 22, 2020 23:45
@@ -192,11 +191,11 @@ private PlaceholderType checkPlaceholders(String statement) {
}

if (posCount > 0) {
return PlaceholderType.POSITIONAL;
return placeHolderType = PlaceholderType.POSITIONAL;
Copy link
Contributor

Choose a reason for hiding this comment

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

assignment and return in one ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. It used to be called int the constructor as
this.placeHolderType = checkPlaceholders(...)
Now it is public and gets called by StringN1qlQueryCreator - but the placeHolderType still needs to be set. I suppose it could be changed to not return a value - it was private, nothing else could be calling it for that.

I'll change it.

@@ -103,7 +103,7 @@
private static final Logger LOGGER = LoggerFactory.getLogger(StringBasedN1qlQueryParser.class);
private final String statement;
private final QueryMethod queryMethod;
private final PlaceholderType placeHolderType;
private PlaceholderType placeHolderType;
Copy link
Contributor

Choose a reason for hiding this comment

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

you sure this is non final now? if so it maybe shold be volatile

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It gets set when StringBasedN1qlQueryParser.checkPlaceHolders() is called by StringN1qlQueryCreator.getExpression(). To make it final, the code in getExpression() would need to be executed in the constructor. It can be done. Not sure that it is better. See next push.

EvaluationContext evaluationContext = evaluationContextProvider.getEvaluationContext(
getQueryMethod().getParameters(), runtimeParameters);
N1QLExpression parsedStatement = x(this.queryParser.doParse(parser, evaluationContext, false));
boolean isCountQuery = queryMethod.getName().toLowerCase().startsWith("count"); // should be queryMethod.isCountQuery()
Copy link
Contributor

Choose a reason for hiding this comment

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

is this still a todo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

queryMethod.isCount() is in the datacouch-588 branch along with some others.

Copy link
Contributor

@daschl daschl left a comment

Choose a reason for hiding this comment

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

put in a couple comments which I dont think look right

@JesusTheHun
Copy link

JesusTheHun commented Sep 25, 2020

Is it possible to backport this fix to future 3.2.11 if any ?

@mikereiche
Copy link
Collaborator Author

Is it possible to backport this fix to future 3.2.11 if any ?

Yes. The original issue was for 3.2.x

@mikereiche mikereiche force-pushed the datacouch_616_string_query_parsing branch 2 times, most recently from f38dd09 to 3071763 Compare September 26, 2020 00:24
@JesusTheHun
Copy link

I'm the author of the issue. I was not sure you were going to make a new release for the 3.x branch though ;)
Thx

Copy link
Contributor

@daschl daschl left a comment

Choose a reason for hiding this comment

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

It would be good if we could have an integration test which covers this scenario, otherwise just minor nits

@@ -98,7 +97,7 @@ private InsertOptions buildInsertOptions() {
} else if (durabilityLevel != DurabilityLevel.NONE) {
options.durability(durabilityLevel);
}
if (expiry != null) {
if (expiry != null && !expiry.equals(Duration.ofSeconds(0))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can use Duration.ZERO;

@@ -98,7 +98,7 @@ private UpsertOptions buildUpsertOptions() {
} else if (durabilityLevel != DurabilityLevel.NONE) {
options.durability(durabilityLevel);
}
if (expiry != null) {
if (expiry != null && ! expiry.equals( Duration.ofSeconds(0))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: you can use Duration.ZERO;

…n quotes

For a query as below that has conditional portions, the parsing for
parameters was being done before the conditional portions were being
resolved, which left the parameters between quotes where they wre
not being recognized as query parameters.

@query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
	" #{#projectIds != null ? 'AND iata IN $1' : ''} ")
Long count(@param("projectIds") List<String> projectIds)
@mikereiche mikereiche force-pushed the datacouch_616_string_query_parsing branch from 3071763 to 6a58d84 Compare October 2, 2020 20:56
…n quotes

For a query as below that has conditional portions, the parsing for
parameters was being done before the conditional portions were being
resolved, which left the parameters between quotes where they wre
not being recognized as query parameters.

@query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} " +
" #{#projectIds != null ? 'AND iata IN $1' : ''} ")
Long count(@param("projectIds") List projectIds)
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