-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrate to memefish * Update testdata * Do go mod tidy * Update to test comments in DDL * Update to reduce useless use of gsqlutils
- Loading branch information
Showing
10 changed files
with
83 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package spanner | ||
|
||
import ( | ||
"github.com/apstndb/gsqlutils" | ||
"github.com/cloudspannerecosystem/memefish" | ||
) | ||
|
||
// Directly use of memefish/gsqlutils is permitted only in this file. | ||
func toStatements(filename string, data []byte) ([]string, error) { | ||
rawStmts, err := memefish.SplitRawStatements(filename, string(data)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// need to strip comments because memefish.SplitRawStatements preserve comments, but UpdateDDL doesn't support comments. | ||
var result []string | ||
for _, rawStmt := range rawStmts { | ||
stripped, err := gsqlutils.SimpleStripComments("", rawStmt.Statement) | ||
if err != nil { | ||
return nil, err | ||
} | ||
result = append(result, stripped) | ||
} | ||
return result, nil | ||
} | ||
|
||
func isDML(statement string) bool { | ||
token, err := gsqlutils.FirstNonHintToken("", statement) | ||
if err != nil { | ||
return false | ||
} | ||
return token.IsKeywordLike("INSERT") | ||
} | ||
|
||
func isPartitionedDML(statement string) bool { | ||
// It is better than regular expression because PDML can be prefixed by statement hints. | ||
token, err := gsqlutils.FirstNonHintToken("", statement) | ||
if err != nil { | ||
return false | ||
} | ||
return token.IsKeywordLike("UPDATE") || token.IsKeywordLike("DELETE") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-- Comments must be permitted | ||
ALTER TABLE Singers ADD COLUMN Foo STRING(MAX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-- Comments must be ignored | ||
ALTER TABLE Singers ADD COLUMN LastName STRING(MAX); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-- Comments must be permitted | ||
UPDATE Singers SET LastName = "" WHERE LastName IS NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
-- Comments must be permitted | ||
CREATE TABLE SchemaMigrations ( | ||
Version INT64 NOT NULL, | ||
Dirty BOOL NOT NULL, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE SchemaMigrations ( | ||
Version INT64 NOT NULL, | ||
Dirty BOOL NOT NULL, | ||
) PRIMARY KEY(Version); | ||
|
||
CREATE TABLE Singers ( | ||
SingerID STRING(36) NOT NULL, | ||
FirstName STRING(1024), | ||
) PRIMARY KEY(SingerID); |