-
Notifications
You must be signed in to change notification settings - Fork 192
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
Conversation
@@ -192,11 +191,11 @@ private PlaceholderType checkPlaceholders(String statement) { | |||
} | |||
|
|||
if (posCount > 0) { | |||
return PlaceholderType.POSITIONAL; | |||
return placeHolderType = PlaceholderType.POSITIONAL; |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Is it possible to backport this fix to future |
Yes. The original issue was for 3.2.x |
f38dd09
to
3071763
Compare
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 ;) |
There was a problem hiding this 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))) { |
There was a problem hiding this comment.
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))) { |
There was a problem hiding this comment.
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)
3071763
to
6a58d84
Compare
…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)
…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)