Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(spanner/spansql): only add comma after other option (#4551)
Co-authored-by: Hengfeng Li <hengfeng@google.com>
  • Loading branch information
olavloite and hengfengli committed Aug 5, 2021
1 parent 4952003 commit 3ac1e00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 2 additions & 3 deletions spanner/spansql/sql.go
Expand Up @@ -185,27 +185,26 @@ func (do DatabaseOptions) SQL() string {
hasOpt = true
if *do.OptimizerVersion == 0 {
str += "optimizer_version=null"

} else {
str += fmt.Sprintf("optimizer_version=%v", *do.OptimizerVersion)
}
}
if do.VersionRetentionPeriod != nil {
hasOpt = true
if hasOpt {
str += ", "
}
hasOpt = true
if *do.VersionRetentionPeriod == "" {
str += "version_retention_period=null"
} else {
str += fmt.Sprintf("version_retention_period='%s'", *do.VersionRetentionPeriod)
}
}
if do.EnableKeyVisualizer != nil {
hasOpt = true
if hasOpt {
str += ", "
}
hasOpt = true
if *do.EnableKeyVisualizer {
str += "enable_key_visualizer=true"
} else {
Expand Down
22 changes: 22 additions & 0 deletions spanner/spansql/sql_test.go
Expand Up @@ -288,6 +288,28 @@ func TestSQL(t *testing.T) {
"ALTER TABLE WithRowDeletionPolicy REPLACE ROW DELETION POLICY ( OLDER_THAN ( DelTimestamp, INTERVAL 30 DAY ))",
reparseDDL,
},
{
&AlterDatabase{
Name: "dbname",
Alteration: SetDatabaseOptions{Options: DatabaseOptions{
EnableKeyVisualizer: func(b bool) *bool { return &b }(true),
}},
Position: line(1),
},
"ALTER DATABASE dbname SET OPTIONS (enable_key_visualizer=true)",
reparseDDL,
},
{
&AlterDatabase{
Name: "dbname",
Alteration: SetDatabaseOptions{Options: DatabaseOptions{
OptimizerVersion: func(i int) *int { return &i }(2),
}},
Position: line(1),
},
"ALTER DATABASE dbname SET OPTIONS (optimizer_version=2)",
reparseDDL,
},
{
&AlterDatabase{
Name: "dbname",
Expand Down

0 comments on commit 3ac1e00

Please sign in to comment.