spyql icon indicating copy to clipboard operation
spyql copied to clipboard

LIKE clause

Open ricardocchaves opened this issue 2 years ago • 3 comments

Adds a LIKE function to the WHERE clause for easier matching. Closes #17

Some notes

  • Right now it can match not only with strings but also with everything else, as the values are stringified before matching. Let me know if this is not intended and if it should be for strings only.
  • It only supports the % wildcard operator.
  • Let me know if the commit messages should follow a specific format

Future work

Either in the scope of this PR or in a future one, it is still missing other basic matching functions, like _ for single character matching or [] to specify a range.

ricardocchaves avatar Mar 01 '22 23:03 ricardocchaves

How can I get a syntax error like the following:

$ python spyql 'SELECT * from range(3) WHERE'
ERROR	could not compile FROM clause
  File "<from>", line 1
    range(3) WHERE
                 ^
SyntaxError: unexpected EOF while parsing

But for LIKE? Should I change this or can it be kept as is? Desired output / behavior:

$ python spyql 'SELECT * from range(3) WHERE col1 LIKE'
ERROR	could not compile WHERE clause
  File "<from>", line 1
    col1 LIKE
            ^
SyntaxError: unexpected EOF while parsing

Current:

$ python spyql 'SELECT * from range(3) WHERE col1 LIKE'
ERROR	col1 LIKE
SyntaxError: unexpected EOF while parsing

ricardocchaves avatar Mar 01 '22 23:03 ricardocchaves

Codecov Report

Merging #67 (0e0a830) into master (c379afa) will increase coverage by 0.07%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage   95.91%   95.98%   +0.07%     
==========================================
  Files          10       10              
  Lines        1076     1096      +20     
==========================================
+ Hits         1032     1052      +20     
  Misses         44       44              
Impacted Files Coverage Δ
spyql/cli.py 99.06% <100.00%> (+0.08%) :arrow_up:
spyql/quotes_handler.py 97.29% <100.00%> (+0.15%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c379afa...0e0a830. Read the comment docs.

codecov[bot] avatar Mar 01 '22 23:03 codecov[bot]

As discussed offline:

  • I'll look into escaping regex characters that may appear innocently in the string
  • I'll implement the like function that takes two strings (whether they're constants, columns, etc.) and returns boolean. Will look into that stack overflow URL, overriding operators.

ricardocchaves avatar Mar 04 '22 15:03 ricardocchaves

Archiving due to lack of activity. Happy to reopen when you are ready!

dcmoura avatar Dec 09 '22 09:12 dcmoura