-
Notifications
You must be signed in to change notification settings - Fork 30
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
SQLAlchemy DQL: Use CrateDB's native ILIKE
operator
#564
Conversation
return "%s ILIKE %s" % ( | ||
self.process(binary.left, **kw), | ||
self.process(binary.right, **kw), | ||
) + ( | ||
" ESCAPE " + self.render_literal_value(escape, sqltypes.STRINGTYPE) | ||
if escape | ||
else "" | ||
) |
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.
Does CrateDB support ESCAPE
in this context? Do you suggest to remove this code, if not?
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.
No,
UnsupportedFeatureException[ESCAPE is not supported.]
Maybe we should raise a feature request?
How were % and _ handled previously in the lower() like lower()
implementation?
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.
Escape character for _
and %
in CrateDB is \
, so \%' or
_`:
cr> create table t(s string);
CREATE OK, 1 row affected (0.385 sec)
cr> insert into t values('f%oo');
INSERT OK, 1 row affected (0.062 sec)
cr> refresh table t;
REFRESH OK, 1 row affected (0.005 sec)
cr> select * from t where s ilike 'f\%O%';
+------+
| s |
+------+
| f%oo |
+------+
SELECT 1 row in set (0.003 sec)
I don't get what's this ESCAPE
here, can you please explain?
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.
I was hoping that you can explain, and/or follow up with proper guidance. ;]
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.
Shall we just remove the corresponding code, in order to be able to bring in the patch, and create an issue at crate/crate to track concerns of the ESCAPE
operator/keyword? I guess it can also be used on statements/clauses other than this specific spot?
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 please, it seems that postgres supports defining a custom escape char seq:
https://www.postgresql.org/docs/15/functions-matching.html
https://stackoverflow.com/questions/196626/escaping-in-a-ilike-query
which is not the case for CrateDB.
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.
Thank you. I've just removed corresponding code. Please let me know if there should be an issue on the crate/crate tracker, in order to track any missing compatibility features.
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.
See #564 (comment) about the handling of % and _ in the matching string
da77c3a
to
689493b
Compare
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.
Thx!
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.
I confirmed that ilike
accepts an escape
parameter and if that is used today it renders as the SQL ESCAPE
clause which results on an UnsupportedFeatureException
being returned from CrateDB, if the change goes in as is there would be no error but we would be risking incorrect results, maybe we should raise some exception if the escape
parameter is used?
Very true, thx! I agree to throw an exception if |
@hlcianfagna: Well spotted, thank you very much. I agree to catch the |
689493b
to
279938a
Compare
1e361d5
to
73b5ab9
Compare
Can we find out since which version CrateDB supports the |
Support for |
Instead of using SA's generic implementation `lower() LIKE lower()`, use CrateDB's native one.
73b5ab9
to
596f5e0
Compare
Thank you @hlcianfagna. I've just added b93007d, in order to implement corresponding code branching based on the CrateDB version in use. May I ask for another review from you and @matriv? |
596f5e0
to
b93007d
Compare
About
At crate/sqlalchemy-cratedb#98, @hlcianfagna suggested to use CrateDB's native
ILIKE
operator instead of using SA's generic implementationlower() LIKE lower()
.Details
This patch brings in the corresponding visitor methods from the
PGDialect
to theCrateDialect
implementation.