cloudspannerecosystem / wrench

wrench - Schema management tool for Cloud Spanner -
MIT License
239 stars 46 forks source link

wrench 1.1.0 fails to parse `TIMESTAMP_SUB` #61

Closed youxkei closed 1 year ago

youxkei commented 2 years ago

Expected Behavior

wrench can apply DML including TIMESTAMP_SUB function.

Current Behavior

It seems that wrench 1.1.0 fails to parse DML including TIMESTAMP_SUB. wrench 1.0.4 can apply such DML correctly.

Steps to Reproduce

The following reproduction steps assumes bash or zsh.

# $PROJECT, $INSTANCE, $DATABASE should be set properly

# setup
$ wrench apply --project $PROJECT --instance $INSTANCE --database $DATABASE --ddl <(echo "CREATE TABLE ParsingTimestampSub (CreatedAt TIMESTAMP NOT NULL) PRIMARY KEY (CreatedAt);")

# OK case
$ wrench apply --project $PROJECT --instance $INSTANCE --database $DATABASE --dml <(echo "DELETE FROM ParsingTimestampSub WHERE CreatedAt < CURRENT_TIMESTAMP();")
0 rows affected.

# error case
$ wrench apply --project $PROJECT --instance $INSTANCE --database $DATABASE --dml <(echo "DELETE FROM ParsingTimestampSub WHERE CreatedAt < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 31 DAY);")
Error command: apply, version: unknown
        /proc/self/fd/11:1.94: got "31", want ")" or ","

# cleanup
$ wrench apply --project $PROJECT --instance $INSTANCE --database $DATABASE --ddl <(echo "DROP TABLE ParsingTimestampSub;")

Context (Environment)

110y commented 2 years ago

Ah, it might be due to we migrated the query parser for wrench from regex to spansql... Let me take a deeper look 👀

zchee commented 2 years ago

I'll also dig it.

dtest commented 2 years ago

I was having the same thing with TIMESTAMP_ADD. Looks like spanner 1.40.0 might fix this.

110y commented 2 years ago

@dtest Thank you for letting me know that! Let me try to fix this 🙏

kazegusuri commented 1 year ago

If you still have a problem, please reopen.