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

Add SplitRawStatements() #102

Merged

Conversation

apstndb
Copy link
Contributor

@apstndb apstndb commented Sep 20, 2024

It is known that statement separating without parsing syntax is needed for Cloud Spanner related OSSs.

cloudspannerecosystem/wrench#83
cloudspannerecosystem/yo#116

memefish is good place for statement separator, because the statement separator must know about lexical structure like strings and comments
and cloudspannerecosystem is reliable org.

Test cases should be added as

Note: I think it is no need to support custom separator like spanner-cli's \G.

Copy link
Collaborator

@makenowjust makenowjust left a comment

Choose a reason for hiding this comment

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

The concept and naming seem good, but I have one question.

errRe *regexp.Regexp
want []string
}{
{desc: "empty input", input: "", want: []string{""}},
Copy link
Collaborator

Choose a reason for hiding this comment

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

This spec seems inconsistent with other specs to me.

That is, SeparateRawStatements(";") returns []{""}, so I guess that SeparateRawStatements omits the last empty statement and SeparateRawStatements("") returns []{}, but this spec says it is NO.

At least, we should note this behavior in the doc.

Copy link
Contributor Author

@apstndb apstndb Sep 20, 2024

Choose a reason for hiding this comment

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

OK. I will write semantics to the go doc comment.

TL;DR

Every statements are terminated by ;, <eof>, or ;<eof> . So, empty input is interpreted as a single empty statement.

@apstndb apstndb marked this pull request as ready for review September 20, 2024 14:29
Copy link
Collaborator

@makenowjust makenowjust left a comment

Choose a reason for hiding this comment

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

I have a concern about naming.

separator.go Outdated
// filepath can be used in error message.
//
// [terminating semicolons]: https://cloud.google.com/spanner/docs/reference/standard-sql/lexical#terminating_semicolons
func SeparateRawStatements(filepath, s string) ([]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Split sounds better naming than Separate. Also, please use src instead of s because this is a public API.

Copy link
Contributor Author

@apstndb apstndb Sep 21, 2024

Choose a reason for hiding this comment

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

I think Split sounds better naming than Separate.

Would it be better to rename to splitter.go?

Also, please use src instead of s because this is a public API.

I believe s string is widely accepted in the Go community.
I prefer input over src because it's not a src and dest pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to rename to splitter.go?

Yes, I think split.go is more preferable because this file does not define Splitter.

I believe s string is widely accepted in the Go community.
I prefer input over src because it's not a src and dest pattern.

"go/parser".ParseFile use src. I know this type is any, and more specifically it is one of string, []byte, and io.Reader, but I think it is appropriate to name this argument src.

Copy link
Contributor Author

@apstndb apstndb Sep 21, 2024

Choose a reason for hiding this comment

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

Yes, I think split.go is more preferable because this file does not define Splitter.

+1

"go/parser".ParseFile use src. I know this type is any, and more specifically it is one of string, []byte, and io.Reader, but I think it is appropriate to name this argument src.

I think it is because go/parser is package for Go source files.

https://pkg.go.dev/go/parser

Package parser implements a parser for Go source files.

I don’t feel that calling .sql files as SQL source file is majority, and this function can be used for non-file input like stdin or --sql option.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is major to call a string to be parsed as source in the parsing context, and I believe it is not different in SQL implementations. However, I have no strong opinion. Okay, I accept the argument s.

Copy link
Collaborator

Choose a reason for hiding this comment

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

s sounds better than input.

@apstndb apstndb changed the title Add statement separator Add statement splitter Sep 21, 2024
@apstndb apstndb changed the title Add statement splitter Add statement splitter(separator) Sep 21, 2024
@apstndb apstndb changed the title Add statement splitter(separator) Add SplitRawStatements() Sep 21, 2024
@makenowjust makenowjust merged commit fe5ac17 into cloudspannerecosystem:main Sep 21, 2024
2 checks passed
@makenowjust
Copy link
Collaborator

Thank you @apstndb!

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