cloudspannerecosystem / spanner-cli

Interactive command line tool for Cloud Spanner
Apache License 2.0
230 stars 28 forks source link

Feature Request: Support batch statements #161

Closed hesch closed 9 months ago

hesch commented 9 months ago

Currently batch statements are not supported and run into this error: ERROR: invalid statement. They are part of the JDBC session management commands and include:

At first these could be implemented as a noop (to be compatible with the JDBC driver) and later implemented in the same way the JDBC driver does.

yfuruyama commented 9 months ago

Hi @hesch, could you elaborate on what is START BATCH DDL and RUN BATCH? I'd like to know what kind of feature you're expecting with those statements.

hesch commented 9 months ago

I'm sorry for being unclear. I don't know the exact implementation details, but I use this to speed up schema creation. It would be nice, if I could run the same SQL-scripts on startup of my application through JDBC and manually via spanner-cli. The commands are documented here: https://cloud.google.com/spanner/docs/jdbc-session-mgmt-commands#batch_statements

I was not aware that these are JDBC commands. If this is out of scope for the project feel free to close the issue!

yfuruyama commented 9 months ago

Thank you for your explanation in detail. It looks like those two statements are JDBC-specific.

If you want to run multiple DDL statements in bulk with spanner-cli, you can use spanner-cli batch mode.

Batch mode automatically tied consecutive DDLs together to create a single batch, so multiple DDL statements will be passed to Cloud Spanner in a single RPC.

Could you try it and see if it works for your use case? Thank you!

hesch commented 9 months ago

Hi @yfuruyama, yes it works even without those statements. I just had to write a little sed script to remove all the commands not parseable by spanner-cli. So my use-case is working ^^

One question remains: Should spanner-cli just ignore those batch statements instead of throwing an error? Just to be compatible with the JDBC driver.

yfuruyama commented 9 months ago

@hesch Glad to hear that your use case worked :)

Currently spanner-cli shows the following error when unrecognized statements are used:

spanner> START BATCH DDL;
ERROR: invalid statement

spanner> RUN BATCH;
ERROR: invalid statement

I think this is fine because spanner-cli doesn't aim at having the similar syntax with the JDBC driver.

hesch commented 9 months ago

Ok, then I will close this, as it is not relevant anymore.

Thanks for your help!