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

spanner/spansql: Database option version_retention_period is not parsed correctly if there are tables after ALTER DATABASE statement #5970

Closed
gecko655 opened this issue May 2, 2022 · 0 comments · Fixed by #5971
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p3 Desirable enhancement or fix. May not be included in next release.

Comments

@gecko655
Copy link
Contributor

gecko655 commented May 2, 2022

Client

Cloud Spanner

Environment

Go playground

Go Environment

(This is the environment of my PC, not Go playground)

❯ go version
go version go1.17.5 darwin/arm64

❯ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/[UserName]/Library/Caches/go-build"
GOENV="/Users/[UserName]/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/[UserName]/.asdf/installs/golang/1.17.5/packages/pkg/mod"
GOOS="darwin"
GOPATH="/Users/[UserName]/.asdf/installs/golang/1.17.5/packages"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/[UserName]/.asdf/installs/golang/1.17.5/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/[UserName]/.asdf/installs/golang/1.17.5/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/[UserName]/git/google-cloud-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_c/7hkzyhtj5mxc38jm7661stc00000gq/T/go-build755299587=/tmp/go-build -gno-record-gcc-switches -fno-common"

Code

package main

import (
	"fmt"

	"cloud.google.com/go/spanner/spansql"
	"github.com/k0kubun/pp/v3"
)

func main() {
	pp.ColoringEnabled = false
	ddl, _ := spansql.ParseDDL("test", "ALTER DATABASE `test` SET OPTIONS (optimizer_version=4, version_retention_period = '7d', enable_key_visualizer=true);\n"+
		"\n"+
		"CREATE TABLE `users` (\n"+
		"    `UserId` STRING(36) NOT NULL,\n"+
		") PRIMARY KEY (`UserId`);")
	pp.Println(ddl)
	fmt.Println(ddl.List[0].SQL())
}

https://go.dev/play/p/I5rWmNCRvda

Expected behavior

version_retention_period should be parsed to 7d

Actual behavior

version_retention_period is actually parsed to UserId (See more details: https://go.dev/play/p/I5rWmNCRvda )

Parsed DDL is "ALTER DATABASE test SET OPTIONS (optimizer_version=4, version_retention_period='UserId', enable_key_visualizer=true)"

Additional context

This behavior is not observed if there is no table after "ALTER DATABASE" statement.
In short, the following query is parsed correctly.

spansql.ParseDDL("test", "ALTER DATABASE `test` SET OPTIONS (optimizer_version=4, version_retention_period = '7d', enable_key_visualizer=true);

Suspecting pointer passing implementation around here:

retentionPeriod = &tok.string

@gecko655 gecko655 added the triage me I really want to be triaged. label May 2, 2022
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label May 2, 2022
gecko655 added a commit to gecko655/google-cloud-go that referenced this issue May 2, 2022
gecko655 added a commit to gecko655/google-cloud-go that referenced this issue May 2, 2022
gecko655 added a commit to gecko655/google-cloud-go that referenced this issue May 2, 2022
@rahul2393 rahul2393 added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed triage me I really want to be triaged. labels May 5, 2022
@gecko655 gecko655 changed the title spanner/spansql: Database option version_retention_period is not parsed correctly if there are more than 1 tables spanner/spansql: Database option version_retention_period is not parsed correctly if there are tables after ALTER DATABASE statement May 7, 2022
rahul2393 added a commit that referenced this issue May 9, 2022
refs: #5970

Co-authored-by: rahul2393 <rahulyadavsep92@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p3 Desirable enhancement or fix. May not be included in next release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants