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

SOLR-15576: Allow filtering on ISO-8601 formatted timestamp literals in SQL WHERE clause #247

Merged
merged 7 commits into from
Aug 6, 2021

Conversation

thelabdude
Copy link
Contributor

@thelabdude thelabdude commented Aug 3, 2021

https://issues.apache.org/jira/browse/SOLR-15576

Description

Minor improvement for robustness of the SQL backend to allow filtering with ISO-8601 timestamp formatted literals.

Solution

Just needed to fix the proper handling of RexNode types in the translateBinary call. Also found a bug where the left and right operands were being swapped but that's only valid for equals operator. I mean we could also adapt the operator to the swap but that seems awkward, so leaving that as an open issue for now.

Tests

Added new unit test

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

Comment on lines 274 to 275
terms = "\"" + terms + "\"";
wrappedQuotes = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope here, but #236 has me thinking about what if there are quotes inside of the terms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if terms has a quote, the query breaks ... I think we should just fix this here vs. opening another PR though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@madrob This is a good catch and I just fixed in this PR but could break out to its own if you feel strongly about not fixing it here ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was imagining that it would be more work than it ended up actually being

@@ -283,8 +283,9 @@ public void open() throws IOException {
resultSet = statement.executeQuery(sqlQuery);
resultSet.setFetchSize(fetchSize);
} catch (SQLException e) {
throw new IOException(String.format(Locale.ROOT, "Failed to execute sqlQuery '%s' against JDBC connection '%s'.\n"
+ e.getMessage(), sqlQuery, connectionUrl), e);
// don't embed the exception message in the format template as wildcard '%' will throw off the formatter
Copy link
Contributor

@madrob madrob Aug 5, 2021

Choose a reason for hiding this comment

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

I'm confused here, why does exception message have a %, but sqlQuery wouldn't?

edit: I'm not saying the code is wrong, but the comment could be little more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No actually you're right, if the SQL has a %, then it will confuse the formatter too. This was just something I found while debugging another issue and it looked like it was the exception message that caused the issue but the sql query would too. Will escape any percents in the query / error message with %% and add a test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, no ... now I'm confusing myself ;-) The reason the exception message and not the sqlQuery was messing up the formatter is the code (before I changed it) was appending the exception message to the formatter template whereas the sqlQuery is injected as a %s parameter. I think the better fix here is to just inject the exception message as a %s parameter as well

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.

2 participants