googlesql

package module
v0.5.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README ¶

go-googlesql

Go GoDoc

Go bindings for GoogleSQL

GoogleSQL can parse queries used with Cloud Spanner and BigQuery. The Go bindings are implemented with cgo.

Library consumers / integrators: follow Installation and docs/prebuilt-cgo.md. You do not need the maintainer-only tooling (GoogleSQL updater, bind generator, Bazel) unless you are changing upstream pins or generated CGO.

Features

  • No need to install GoogleSQL as a separate system library

  • Portable single binaries despite CGO

    • You can still produce a static binary with CGO_ENABLED=1 by passing --ldflags '-extldflags "-static"' at build time.
  • Full access to the GoogleSQL parser API

    • The GoogleSQL parser is not distributed as a standalone public library; it is available through go-googlesql.
  • Analyzer APIs

Status

The following GoogleSQL packages are supported in go-googlesql. Additional coverage will be added over time.

Package Supported
parser yes
public partial
analyzer yes
scripting no
reference_impl no

Prerequisites

go-googlesql uses cgo, so CGO_ENABLED=1 is required to build.
clang++ is recommended; set CXX=clang++ when building.

Environment Name Value
CGO_ENABLED 1 ( required )
CXX clang++ ( recommended )

Build modes (quick reference)

Supported direction: googlesql + googlesql_unified_prebuilt, Bazel-built libgooglesql.a + libprotobuf_cgo.a, and link-only CGO binds. See docs/link-only-cgo-migration.md.

Mode Build tags Bazel needed? Notes
GoogleSQL CGO (default) googlesql,googlesql_unified_prebuilt,googlesql_prebuilts_mod,googlesql_prebuilts_platform_pkg Yes to produce archives under lib/; no if you use release tarballs + promote-to-mod Mod platform layout: prebuilts under lib/$GOOS-$GOARCH/; linker TU in lib/.../prebuilt.go. See docs/prebuilt-cgo.md.
Maintainer (internal paths only) googlesql,googlesql_unified_prebuilt Same Use task generate:ccall-prebuilt-internal and task test:local-internal-prebuilts.

Contributor quick path (prebuilts): clone → unpack release assets (or run task prebuilt:protobuf / task prebuilt:googlesql-unified as in docs/prebuilt-cgo.md; Bazel writes under internal/ccall/... — run go run ./cmd/googlesql-prebuilts promote-to-mod if you need the default lib/ layout) → task test:local. Install Task if you do not have the task CLI. CI cache layout for Bazel: docs/ci-bazel-cache.md.

Installation

This module uses CGO and prebuilt static archives (.a files). You do not compile the full GoogleSQL C++ tree from source in normal use — you link Bazel-built archives. Full detail: docs/prebuilt-cgo.md. Step-by-step install paths: docs/install-prebuilts.md.

Add the dependency

go get github.com/vantaboard/go-googlesql

go get alone is not enough for a working CGO link: you still need the prebuilt libraries on disk for your GOOS/GOARCH (see below).

Install prebuilts (required for default builds)

Pick one path so lib/${GOOS}-${GOARCH}/ contains libprotobuf_cgo.a, libgooglesql_*.a (including libgooglesql_parser_tm.a), and related files:

  1. From nothing (no git clone) — downloads the tagged source tree + release tarball for your machine:

    curl -fsSL https://raw.githubusercontent.com/vantaboard/go-googlesql/main/scripts/install-from-nothing.sh | bash -s -- vX.Y.Z
    

    Produces ./go-googlesql-vX.Y.Z/. Needs curl, tar, go, and a vX.Y.Z tag that has GitHub Release assets.

  2. Git clone + installer — clone this repo, git checkout vX.Y.Z, then from the repo root:

    ./scripts/install-prebuilts.sh
    

    Or task install:prebuilts. Set GO_GOOGLESQL_VERSION=vX.Y.Z if you are not exactly on that tag.

  3. Manual — Download the default prebuilts .tar.gz for your platform from the same release, extract at the repo root, then run go run ./cmd/googlesql-prebuilts promote-to-mod if needed (docs/prebuilt-cgo.md).

After any of these, cd into the tree (or point your replace at it) and build with the mod_platform tags and CGO_* settings documented in docs/prebuilt-cgo.md.

Downstream modules

If another module imports github.com/vantaboard/go-googlesql/..., you still only compile Go + CGO glue at build time; the heavy native code is linked from those .a files — not rebuilt with Bazel in your project. You must keep replace (or CI) pointed at a checkout with a complete lib/<platform>/ tree, and use the same tags / CGO_* contract. See Downstream modules in docs/install-prebuilts.md and Downstream repositories in docs/prebuilt-cgo.md.

Notes

Prebuilt archives (primary path): For supported platforms, release tags are intended to ship smaller libgooglesql_*.a files inside nested lib/<goos>-<goarch>/ modules where possible. libgooglesql_parser_tm.a is too large for git and is gitignored; use an installer or release tarball for a full tree (docs/platform-prebuilts-delivery.md).

Fallback (cmd/googlesql-prebuilts): CGO_ENABLED=0 go run ./cmd/googlesql-prebuilts setup downloads the same assets (default -layout mod). **``-layout internal** keeps archives only under internal/ccall/.../lib/` (maintainer). Windows prebuilt release assets are not published yet (build from source or use WSL/Linux/macOS hosts until that pipeline exists).

From source without tarballs: task prebuilt:protobuf + task prebuilt:googlesql-unified (Bazel) is for maintainers changing the extract; first-time Bazel work can take a long time. Even with prebuilts, the first go build / go test compiles the Go side of CGO and can be slower than a pure-Go dependency — point GOCACHE at a stable directory (see Development below).

Development

direnv (recommended): Install direnv and run direnv allow in this checkout. .envrc sources scripts/go-googlesql-env.sh so your shell gets the same CGO_*, cache layout, GO_BUILD_P, and tags-related defaults as task (which also sources .envrc). On macOS, that env script also aligns MACOSX_DEPLOYMENT_TARGET=15.5 with CI/prebuilt objects. Optional per-machine overrides: .envrc.local (gitignored).

Nested lib/* Go modules: Copy go.work.dev to go.work for local resolution (replace each lib/* module to ./lib/..., same pattern as duckdb-go-bindings). Some clones also commit a go.work that lists nested modules with use; either approach works. Versioning and release tags (lib/linux-amd64/vX.Y.Z, etc.) are documented in docs/lib-modules-versioning.md.

Maintainer: commit prebuilts + tag: Run GitHub Actions Commit prebuilt libs (workflow_dispatch) to Bazel-build each platform, run populate-lib-mod-trees, and push a commit with updated lib/**/*.a ( libgooglesql_parser_tm.a is gitignored — ship it only on GitHub Release tarballs). Then use scripts/release.sh (or scripts/release-tag-lib-modules.sh) to publish nested-module tags and the root v* tag — see docs/platform-prebuilts-delivery.md.

Downstream / CI shells (no direnv): scripts/go-googlesql-stack-bootstrap.sh exports the same CGO_LDFLAGS_ALLOW, CGO_LDFLAGS, CGO_CXXFLAGS, caches, and GOOGLESQL_BUILD_TAGS as Taskfile.yml. Use it from sibling repos when running go test with replace to this checkout—see docs/prebuilt-cgo.md.

GoogleSQL upstream: The release tag is pinned in cmd/updater/googlesql.ref (meta-repo) when present; this repo keeps scripts/maint-pins/googlesql.ref in sync for CI. Run scripts/ensure-googlesql-workspace.sh to clone google/googlesql into ../googlesql/ (sibling of this repo in googlesql-workspace). Bazel scripts default to GOOGLESQL_BAZEL_ROOT=$PWD/../googlesql; set that to ../cmd/updater/googlesql only if you still use that layout. To copy sources and Bazel outputs into internal/ccall/, run make -C ../cmd/updater update from the meta-repo when cmd/updater exists (Docker build + cache export + updater). Policy: docs/googlesql-submodule-policy.md. Maintainer layout: docs/maintainer-tooling.md.

Fast path (stack work): task docker:build-dev in this repo → optional task docker:warm-cache → use the same GO_CACHE_ROOT (default ~/.cache/go-googlesql) when running task test:linux in sibling checkouts go-googlesqlite and the Vantaboard bigquery-emulator fork. Those READMEs document GO_CACHE_ROOT, ccache, mold (Linux), and optional warm-up for host and Docker workflows.

Sequential tests (multi-repo): If you work in go-googlesql, go-googlesqlite, and bigquery-emulator together, run heavy go test one repo at a time. Running full CGO test suites in parallel on one machine often exhausts memory.

Host go test memory cap (systemd): scripts/cgo-go.sh optionally wraps go build / go test in a user or system scope with GOOGLESQL_CGO_MEMORY_MAX (default 22G).

Reuse local compile cache: Point the same GO_CACHE_ROOT at all three checkouts so GOCACHE, GOMODCACHE, and CCACHE_DIR stay warm across go-googlesql, go-googlesqlite, and bigquery-emulator:

export GO_CACHE_ROOT=$HOME/.cache/go-googlesql
mkdir -p "$GO_CACHE_ROOT"

Then source .envrc (or scripts/go-googlesql-stack-bootstrap.sh) so GOCACHE, GOMODCACHE, CCACHE_DIR, CGO_LDFLAGS_ALLOW, and default GOOGLESQL_BUILD_TAGS (mod_platform stack) match Taskfile.yml.

GitHub Actions uses ccache clang / ccache clang++ with a persisted CCACHE_DIR so CI gets incremental C++ compiles across runs, similar in spirit to task build:local.

Mold (Linux): The go-googlesql:dev image installs mold and sets CGO_LDFLAGS=-fuse-ld=mold. On Linux hosts, if mold is on PATH, task build:local / task test:local pass the same flag for faster linking.

Rough cold vs warm timing: task profile:bottleneck runs two go test -c passes and prints ccache -s (install ccache locally for stats). Uses TESTPKG like other targets.

Default Bazel protobuf archive (Linux/macOS): task prebuilt:protobuf runs internal/ccall/go-protobuf/protobuf/extract_protobuf_cgo_lib.sh and produces libprotobuf_cgo.a.

Default build/test path: After task prebuilt:protobuf and task prebuilt:googlesql-unified (which initially write archives under internal/ccall/...), run go run ./cmd/googlesql-prebuilts promote-to-mod so task build:local / task test:local use the default mod_platform tag set and the lib/ layout documented in docs/prebuilt-cgo.md. task verify:prebuilt-protobuf and task verify:prebuilt-googlesql-unified auto-detect internal vs mod layout; task test:local-internal-prebuilts remains available for maintainer-only internal-path validation. task verify:protobuf-tier-b warns when vendored protobuf is still below the Bazel 29.x line (use task sync:protobuf-vendor-from-bazel + go run ./internal/cmd/vendorpatch + task regenerate:ccall-cpp-protos to align). Full details: docs/prebuilt-cgo.md, docs/native-build-pipeline.md, docs/link-only-cgo-migration.md. Generator config and updater workflows live at the googlesql-workspace root — see docs/maintainer-tooling.md. Install-prefix / pkg-config template: contrib/googlesql.pc.example. Set GOOGLESQL_PREBUILT_PREFIX when using a consolidated prefix (documented in the .pc example); protobuf prebuilts currently use fixed paths under go-protobuf/protobuf/lib/.

Downstream (go-googlesqlite, Vantaboard bigquery-emulator): Keep replace pointed at the same checkout where you ran task prebuilt:protobuf and task prebuilt:googlesql-unified, and pass the same -tags (plus matching CGO_* / Taskfile.yml-style CGO_LDFLAGS_ALLOW) when using the default protobuf prebuilt path; see docs/prebuilt-cgo.md. task verify:tier-b-cgo-policy prints supported prebuilt tag combinations (scripts/verify-tier-b-cgo-tag-policy.sh).

Unified GoogleSQL prebuilt (root slice): task prebuilt:googlesql-unified builds libgooglesql.a for parser + analyzer + catalog + simple_catalog + sql_formatter, in addition to the proto/base closure. CI (.github/workflows/go.yml): the prebuilts matrix runs Bazel (task verify:protobuf-tier-b, task verify:tier-b-cgo-policy, task prebuilt:protobuf, task verify:prebuilt-protobuf, task prebuilt:googlesql-unified, task verify:prebuilt-googlesql-unified) and uploads the default tarball per platform; the test matrix downloads that tarball, extracts it, runs go run ./cmd/googlesql-prebuilts promote-to-mod, then task verify:prebuilt-protobuf and task verify:prebuilt-googlesql-unified, then task test:local TESTPKG=./ (no Bazel on test runners). Local or manual checks (not required for that CI path): task build:googlesql-unified → task build:googlesql-unified-root → task test:googlesql-unified-root → task test:compile-root-unified → task smoke:googlesql-unified / bash scripts/smoke_link_googlesql_unified.sh — see docs/libgooglesql-unified.md. For experiments, GOOGLESQL_UNIFIED_BAZEL_TARGETS overrides the archive label list and GOOGLESQL_UNIFIED_GOPROXY overrides the extractor's Bazel module proxy. See also docs/link-only-cgo-migration.md and contrib/googlesql.pc.example / Dockerfile.prebaked for the longer-term consolidated install-prefix story.

Docker-based tests (recommended): Use task test (alias task test:linux) — this builds a slim go-googlesql:dev image (--target dev: Go + clang + ccache only; no module compile in the image build) and runs go test with your working tree and GO_CACHE_ROOT (default ~/.cache/go-googlesql) bind-mounted as gocache/, gomodcache/, and ccache/ (Clang object cache for CGO). After a cold cache or toolchain change, run task docker:warm-cache once: it runs go test -race with -run '^$' (matches no tests) so you pre-compile the same -race graph without executing tests; later task test:linux stays much faster. Set TESTPKG=./... to widen scope. go-googlesqlite and bigquery-emulator task test:linux use the same GO_CACHE_ROOT so the stack shares one warm cache. Host task build:local / task test:local use the default mod_platform tag set and prebuilt verifies (ensure lib/ layout or override tags for maintainer workflows). Rebuild go-googlesql:dev after Dockerfile changes (task docker:build-dev). The default docker build (release image) is separate from local test caches: pass --build-arg GO_GOOGLESQL_VERSION=vX.Y.Z so the Dockerfile can run cmd/googlesql-prebuilts setup for that release before go install -tags googlesql,googlesql_unified_prebuilt.

Downstream Docker images: bigquery-emulator accepts GO_GOOGLESQL_BASE (default: the Recidiviz base image). After building go-googlesql:dev, you can point the emulator at it, for example:

# in bigquery-emulator/ (that repo’s Makefile; not go-googlesql’s Taskfile)
make docker/build GO_GOOGLESQL_BASE=go-googlesql:dev

Editor Tips

Opening this repository in VS Code or Cursor can be expensive because the Go extension loads a large CGO-backed package graph.

  • Use a single-repo editor window when you only need this repository (avoids indexing sibling checkouts).
  • The repository includes .vscode/settings.json with conservative Go defaults for this module:
    • disables build, lint, and vet on save
    • default build tags match the mod_platform stack (scripts/go-googlesql-env.sh)
    • if you open the full googlesql-workspace, the workspace-root .vscode/settings.json excludes maintainer-only cmd/generator and cmd/updater by default (see docs/maintainer-tooling.md)
    • .cursorignore reduces Cursor indexing of generated-only paths in this consumer repo; maintainer-tool exclusions live at the workspace root
  • If you still see high memory use, disable the Go extension for this workspace when you are only reading generated binding code.

Synopsis

Parse SQL statement

package main

import (
  "github.com/vantaboard/go-googlesql"
  "github.com/vantaboard/go-googlesql/ast"
)

func main() {

  stmt, err := googlesql.ParseStatement("SELECT * FROM Samples WHERE id = 1", nil)
  if err != nil {
    panic(err)
  }

  // use type assertion and get concrete nodes.
  queryStmt := stmt.(*ast.QueryStatementNode)
}

To inspect concrete ast.Node types, traverse the tree with ast.Walk.

package main

import (
  "fmt"

  "github.com/vantaboard/go-googlesql"
  "github.com/vantaboard/go-googlesql/ast"
)

func main() {

  stmt, err := googlesql.ParseStatement("SELECT * FROM Samples WHERE id = 1", nil)
  if err != nil {
    panic(err)
  }

  // traverse all nodes of stmt.
  ast.Walk(stmt, func(n ast.Node) error {
    fmt.Printf("node: %T loc:%s\n", n, n.ParseLocationRange())
    return nil
  })
}

Analyze SQL statement

With table metadata, pass a Catalog into the analyzer API to parse SQL against your schema and obtain a normalized AST. To inspect concrete resolved_ast.Node types, traverse with resolved_ast.Walk.

package main

import (
  "fmt"

  "github.com/vantaboard/go-googlesql"
  "github.com/vantaboard/go-googlesql/resolved_ast"
  "github.com/vantaboard/go-googlesql/types"
)

func main() {
  const tableName = "Samples"
  catalog := types.NewSimpleCatalog("catalog")
  catalog.AddTable(
    types.NewSimpleTable(tableName, []types.Column{
      types.NewSimpleColumn(tableName, "id", types.Int64Type()),
      types.NewSimpleColumn(tableName, "name", types.StringType()),
    }),
  )
  catalog.AddGoogleSQLBuiltinFunctions()
  out, err := googlesql.AnalyzeStatement("SELECT * FROM Samples WHERE id = 1000", catalog, nil)
  if err != nil {
    panic(err)
  }

  // get statement node from googlesql.AnalyzerOutput.
  stmt := out.Statement()

  // traverse all nodes of stmt.
  if err := resolved_ast.Walk(stmt, func(n resolved_ast.Node) error {
    fmt.Printf("%T\n", n)
    return nil
  }); err != nil {
    panic(err)
  }
}

You can also call node.DebugString() on a resolved_ast.Node to dump its structure. That output helps you understand the resolved statement.

stmt := out.Statement()
fmt.Println(stmt.DebugString())

License

Apache-2.0 License

go-googlesql vendors source from the dependencies below, so the overall licensing reflects those components.

Documentation ¶

Overview ¶

This file is intended to fix a bug that occurs with Go's go mod vendor and cgo combination. Normally, directories containing only C/C++ language files are ignored by go mod vendor, but go:embed forces them to be copied. If we do not use embed.FS to perform the operation, the generated binaries will not reflect the embedded files. See detail issue: https://github.com/golang/go/issues/26366

Index ¶

Constants ¶

This section is empty.

Variables ¶

View Source
var (
	ErrParseStatement  = fmt.Errorf("failed to get statement node")
	ErrParseScript     = fmt.Errorf("failed to get script node")
	ErrParseType       = fmt.Errorf("failed to get type node")
	ErrParseExpression = fmt.Errorf("failed to get expression node")
	ErrRequiredCatalog = fmt.Errorf("catalog is required parameter to analyze sql")
)

Functions ¶

func AnalyzeType ¶

func AnalyzeType(typeName string, catalog types.Catalog, opt *AnalyzerOptions) ([]types.Type, error)

func FormatSQL ¶

func FormatSQL(sql string) (string, error)

FormatSQL formats GoogleSQL statements. Multiple statements separated by semi-colons are supported.

On return, the first return value is always populated with equivalent SQL. The returned error contains the concatenation of any errors that occurred while parsing the statements.

Any statements that fail to parse as valid GoogleSQL are returned unchanged. All valid statements will be reformatted.

CAVEATS: 1. This can only reformat SQL statements that can be parsed successfully. Statements that cannot be parsed are returned unchanged. 2. Comments are stripped in the formatted output.

func ParseExpression ¶

func ParseExpression(expr string, opt *ParserOptions) (ast.ExpressionNode, error)

ParseExpression parses <expression_string> as an expression and returns the expression node upon success.

This can return errors annotated with an ErrorLocation payload that indicates the input location of an error.

func ParseNextScriptStatement ¶

func ParseNextScriptStatement(loc *ParseResumeLocation, opt *ParserOptions) (ast.StatementNode, bool, error)

ParseNextScriptStatement similar to the ParseNextStatement function, but allows statements specific to scripting, in addition to SQL statements. Entire constructs such as IF...END IF, WHILE...END WHILE, and BEGIN...END are returned as a single statement, and may contain inner statements, which can be examined through the returned parse tree.

func ParseNextStatement ¶

func ParseNextStatement(loc *ParseResumeLocation, opt *ParserOptions) (ast.StatementNode, bool, error)

ParseNextStatement parses one statement from a string that may contain multiple statements. This can be called in a loop with the same <resume_location> to parse all statements from a string.

Returns the statement node upon success. The second return value will be true if parsing reached the end of the string.

Statements are separated by semicolons. A final semicolon is not required on the last statement. If only whitespace and comments follow the semicolon, The second return value will be set to true. Otherwise, it will be set to false. Script statements are not supported.

After a parse error, <resume_location> is not updated and parsing further statements is not supported.

This can return errors annotated with an ErrorLocation payload that indicates the input location of an error.

func ParseScript ¶

func ParseScript(script string, opt *ParserOptions, mode ErrorMessageMode) (ast.ScriptNode, error)

ParseScript parses <script_string> and returns the script node upon success.

A terminating semi-colon is optional for the last statement in the script, and mandatory for all other statements.

<error_message_mode> describes how errors should be represented.

func ParseStatement ¶

func ParseStatement(stmt string, opt *ParserOptions) (ast.StatementNode, error)

ParseStatement parses <statement_string> and returns the statement node upon success.

A semi-colon following the statement is optional.

Script statements are not supported.

This can return errors annotated with an ErrorLocation payload that indicates the input location of an error.

func ParseType ¶

func ParseType(typ string, opt *ParserOptions) (ast.TypeNode, error)

ParseType parses <type_string> as a type name and returns the type node upon success.

This can return errors annotated with an ErrorLocation payload that indicates the input location of an error.

func Unparse ¶

func Unparse(node ast.Node) string

Unparse a given AST back to a canonical SQL string and return it. Works for any AST node.

func ValidateAnalyzerOptions ¶

func ValidateAnalyzerOptions(opt *AnalyzerOptions) error

ValidateAnalyzerOptions verifies that the provided AnalyzerOptions have a valid combination of settings.

Types ¶

type AnalyzerOptions ¶

type AnalyzerOptions struct {
	// contains filtered or unexported fields
}

AnalyzerOptions contains options that affect analyzer behavior. The language options that control the language accepted are accessible via the Language() member.

func NewAnalyzerOptions ¶

func NewAnalyzerOptions() *AnalyzerOptions

func (*AnalyzerOptions) AddExpressionColumn ¶

func (o *AnalyzerOptions) AddExpressionColumn(name string, typ types.Type) error

AddExpressionColumn add columns that are visible when resolving standalone expressions. These are used only in AnalyzeExpression, and have no effect on other analyzer entrypoints.

AddExpressionColumn is used to add one or more columns resolvable by name.

SetInScopeExpressionColumn is used to add at most one expression column that can be resolved by name (if <name> is non-empty), and is also implicitly in scope so that fields on the value can be used directly, without qualifiers. Expression column names take precedence over in-scope field names.

SetLookupExpressionColumnCallback is used to add a callback function to resolve expression columns. The columns referenced in the expressions but not added in the above functions will be resolved using the callback function. The column name passed in the callback function is always in the lower case.

Column name lookups are case insensitive. Columns names in the output ExpressionColumnNode nodes will always be in lowercase.

For example, to support the expression

enabled = true AND cost > 0.0

those columns can be added using

analyzerOptions.AddExpressionColumn("enabled", types.BoolType());
analyzerOptions.AddExpressionColumn("cost", types.DoubleType());

To evaluate an expression in the scope of a particular proto, like

has_cost AND cost > 0 AND value.cost != 10

Note that an error will be produced if type is not supported according to the current language options.

func (*AnalyzerOptions) AddPositionalQueryParameter ¶

func (o *AnalyzerOptions) AddPositionalQueryParameter(typ types.Type) error

AddPositionalQueryParameter adds a positional query parameter.

GoogleSQL only uses the parameter Type and not the Value. Query analysis is not dependent on the value, and query engines may substitute a value after analysis.

For example, for the query

SELECT * FROM table WHERE CustomerId = ?

the parameter can be added using

analyzerOptions.AddPositionalQueryParameter(types.Int64Type());

Note that an error will be produced if type is not supported according to the current language options. At least as many positional parameters must be provided as there are ? in the query. When allow_undeclared_parameters is true, no positional parameters may be provided.

func (*AnalyzerOptions) AddQueryParameter ¶

func (o *AnalyzerOptions) AddQueryParameter(name string, typ types.Type) error

AddQueryParameter adds a named query parameter. Parameter name lookups are case insensitive. Paramater names in the output ParameterNode nodes will always be in lowercase.

GoogleSQL only uses the parameter Type and not the Value. Query analysis is not dependent on the value, and query engines may substitute a value after analysis.

For example, for the query

SELECT * FROM table WHERE CustomerId = @customer_id

the parameter can be added using

analyzerOptions.AddQueryParameter("customer_id", types.Int64Type());

Note that an error will be produced if type is not supported according to the current language options.

func (*AnalyzerOptions) AllowUndeclaredParameters ¶

func (o *AnalyzerOptions) AllowUndeclaredParameters() bool

func (*AnalyzerOptions) ClearPositionalQueyParameters ¶

func (o *AnalyzerOptions) ClearPositionalQueyParameters()

ClearPositionalQueyParameters clears <positional_query_parameters_>.

func (*AnalyzerOptions) ClearQueryParameters ¶

func (o *AnalyzerOptions) ClearQueryParameters()

ClearQueryParameters clears <query_parameters_>.

func (*AnalyzerOptions) CreateNewColumnForEachProjectedOutput ¶

func (o *AnalyzerOptions) CreateNewColumnForEachProjectedOutput() bool

func (*AnalyzerOptions) ErrorMessageMode ¶

func (o *AnalyzerOptions) ErrorMessageMode() ErrorMessageMode

func (*AnalyzerOptions) ExpressionColumns ¶

func (o *AnalyzerOptions) ExpressionColumns() QueryParametersMap

ExpressionColumns get the named expression columns added. This will include the in-scope expression column if one was set. This doesn't include the columns resolved using the LookupExpressionColumnCallback function.

func (*AnalyzerOptions) HasInScopeExpressionColumn ¶

func (o *AnalyzerOptions) HasInScopeExpressionColumn() bool

func (*AnalyzerOptions) InScopeExpressionColumnName ¶

func (o *AnalyzerOptions) InScopeExpressionColumnName() string

InScopeExpressionColumnName get the name and Type of the in-scope expression column. These return empty string and nil if there is no in-scope expression column.

func (*AnalyzerOptions) InScopeExpressionColumnType ¶

func (o *AnalyzerOptions) InScopeExpressionColumnType() types.Type

func (*AnalyzerOptions) Language ¶

func (o *AnalyzerOptions) Language() *LanguageOptions

Language options for the language.

func (*AnalyzerOptions) ParameterMode ¶

func (o *AnalyzerOptions) ParameterMode() ParameterMode

func (*AnalyzerOptions) ParseLocationRecordType ¶

func (o *AnalyzerOptions) ParseLocationRecordType() ParseLocationRecordType

func (*AnalyzerOptions) ParserOptions ¶

func (o *AnalyzerOptions) ParserOptions() *ParserOptions

func (*AnalyzerOptions) PositionalQueryParameters ¶

func (o *AnalyzerOptions) PositionalQueryParameters() []types.Type

PositionalQueryParameters defined positional parameters. Only used in positional parameter mode. Index 0 corresponds with the query parameter at position 1 and so on.

func (*AnalyzerOptions) PreserveColumnAliases ¶

func (o *AnalyzerOptions) PreserveColumnAliases() bool

func (*AnalyzerOptions) PruneUnusedColumns ¶

func (o *AnalyzerOptions) PruneUnusedColumns() bool

func (*AnalyzerOptions) QueryParameters ¶

func (o *AnalyzerOptions) QueryParameters() QueryParametersMap

func (*AnalyzerOptions) SetAllowUndeclaredParameters ¶

func (o *AnalyzerOptions) SetAllowUndeclaredParameters(v bool)

SetAllowUndeclaredParameters controls whether undeclared parameters are allowed. Undeclared parameters don't appear in QueryParameters(). Their type will be assigned by the analyzer in the output AST and returned in AnalyzerOutput.UndeclaredParameters() or AnalyzerOutput.UndeclaredPositionalParameters() depending on the parameter mode. When AllowUndeclaredParameters is true and the parameter mode is positional, no positional parameters may be provided in AnalyzerOptions.

func (*AnalyzerOptions) SetCreateNewColumnForEachProjectedOutput ¶

func (o *AnalyzerOptions) SetCreateNewColumnForEachProjectedOutput(v bool)

func (*AnalyzerOptions) SetErrorMessageMode ¶

func (o *AnalyzerOptions) SetErrorMessageMode(mode ErrorMessageMode)

func (*AnalyzerOptions) SetInScopeExpressionColumn ¶

func (o *AnalyzerOptions) SetInScopeExpressionColumn(name string, typ types.Type) error

func (*AnalyzerOptions) SetLanguage ¶

func (o *AnalyzerOptions) SetLanguage(options *LanguageOptions)

SetLanguage.

func (*AnalyzerOptions) SetParameterMode ¶

func (o *AnalyzerOptions) SetParameterMode(mode ParameterMode)

SetParameterMode controls whether positional parameters are allowed. The analyzer supports either named parameters or positional parameters but not both in the same query.

func (*AnalyzerOptions) SetParseLocationRecordType ¶

func (o *AnalyzerOptions) SetParseLocationRecordType(typ ParseLocationRecordType)

func (*AnalyzerOptions) SetPreserveColumnAliases ¶

func (o *AnalyzerOptions) SetPreserveColumnAliases(v bool)

SetPreserveColumnAliases controls whether to preserve aliases of aggregate columns and analytic function columns. This option has no effect on query semantics and just changes what names are used inside Columns.

If true, the analyzer uses column aliases as names of aggregate columns and analytic function columns if they exist, and falls back to using internal names such as "$agg1" otherwise. If false, the analyzer uses internal names unconditionally.

TODO: Make this the default and remove this option.

func (*AnalyzerOptions) SetPruneUnusedColumns ¶

func (o *AnalyzerOptions) SetPruneUnusedColumns(v bool)

func (*AnalyzerOptions) SetStatementContext ¶

func (o *AnalyzerOptions) SetStatementContext(ctx StatementContext)

func (*AnalyzerOptions) StatementContext ¶

func (o *AnalyzerOptions) StatementContext() StatementContext

type AnalyzerOutput ¶

type AnalyzerOutput struct {
	// contains filtered or unexported fields
}

func AnalyzeExpression ¶

func AnalyzeExpression(sql string, catalog types.Catalog, opt *AnalyzerOptions) (*AnalyzerOutput, error)

AnalyzeExpression analyze a GoogleSQL expression. The expression may include query parameters, subqueries, and any other valid expression syntax.

The Catalog provides functions and named data types as usual. If it includes Tables, those tables will be queryable in subqueries inside the expression.

Column names added to <options> with AddExpressionColumn will be usable in the expression, and will show up as ExpressionColumn nodes in the output.

Can return errors that point at a location in the input. This location can be reported in multiple ways depending on <options.error_message_mode()>.

func AnalyzeNextStatement ¶

func AnalyzeNextStatement(loc *ParseResumeLocation, catalog types.Catalog, opt *AnalyzerOptions) (*AnalyzerOutput, bool, error)

AnalyzeNextStatement analyze one statement from a string that may contain multiple statements. This can be called in a loop with the same <resume_location> to parse all statements from a string.

On successful return, <*at_end_of_input> is true if parsing reached the end of the string. <*output> contains the next statement found.

Statements are separated by semicolons. A final semicolon is not required on the last statement. If only whitespace and comments follow the semicolon, isEnd will be set.

This can return errors that point at a location in the input. How this location is reported is given by <opt.ErrorMessageMode()>.

After an error, <resume_location> may not be updated and analyzing further statements is not supported.

func AnalyzeStatement ¶

func AnalyzeStatement(sql string, catalog types.Catalog, opt *AnalyzerOptions) (*AnalyzerOutput, error)

AnalyzeStatement analyze a GoogleSQL statement.

This can return errors that point at a location in the input. How this location is reported is given by <opt.ErrorMessageMode()>.

func AnalyzeStatementFromParserAST ¶

func AnalyzeStatementFromParserAST(sql string, stmt ast.StatementNode, catalog types.Catalog, opt *AnalyzerOptions) (*AnalyzerOutput, error)

func (*AnalyzerOutput) AnalyzerOutputProperties ¶

func (o *AnalyzerOutput) AnalyzerOutputProperties() *AnalyzerOutputProperties

func (*AnalyzerOutput) DeprecationWarnings ¶

func (o *AnalyzerOutput) DeprecationWarnings() *DeprecationWarnings

func (*AnalyzerOutput) Expr ¶

func (*AnalyzerOutput) MaxColumnID ¶

func (o *AnalyzerOutput) MaxColumnID() int

func (*AnalyzerOutput) Statement ¶

func (o *AnalyzerOutput) Statement() resolved_ast.StatementNode

func (*AnalyzerOutput) UndeclaredParameters ¶

func (o *AnalyzerOutput) UndeclaredParameters() QueryParametersMap

func (*AnalyzerOutput) UndeclaredPositionalParameters ¶

func (o *AnalyzerOutput) UndeclaredPositionalParameters() []types.Type

type AnalyzerOutputProperties ¶

type AnalyzerOutputProperties struct {
	HasFlatten       bool
	HasAnonymization bool
}

type DeprecationWarnings ¶

type DeprecationWarnings struct {
}

type ErrorMessageMode ¶

type ErrorMessageMode int

ErrorMessageMode mode describing how errors should be constructed in the returned error.

const (
	// The error string does not contain a location.
	// An ErrorLocation proto will be attached to the error with
	// a location, when applicable.
	ErrorMessageWithPayload ErrorMessageMode = 0

	// The error string contains a suffix " [at <line>:<column>]" when an
	// error location is available.
	ErrorMessageOneLine ErrorMessageMode = 1

	// The error string matches ErrorMessageOneLine, and also contains
	// a second line with a substring of the input query, and a third line
	// with a caret ("^") pointing at the error location above.
	ErrorMessageMultiLineWithCaret ErrorMessageMode = 2
)

type LanguageFeature ¶

type LanguageFeature int

LanguageFeature the list of optional features that engines may or may not support. Features can be opted into in AnalyzerOptions.

There are three types of LanguageFeatures.

  • Cross-version - Optional features that can be enabled orthogonally to versioning. Some engines will never implement these features, and googlesql code will always support this switch.
  • Versioned - Features that describe behavior changes adopted as of some language version. Eventually, all engines should support these features, and switches in the googlesql code (and tests) should eventually be removed. All of these, and only these, show up in VERSION_CURRENT.
  • Experimental - Features not currently part of any language version.

All optional features are off by default. Some features have a negative meaning, so turning them on will remove a feature or enable an error.

const (

	// Enable analytic functions.
	FeatureAnalyticFunctions LanguageFeature = 1

	// Enable the TABLESAMPLE clause on scans.
	FeatureTablesample LanguageFeature = 2

	// If enabled, give an error on GROUP BY, DISTINCT or set operations (other
	// than UNION ALL) on floating point types. This feature is disabled in the
	// idealized GoogleSQL (i.e. LanguageOptions::EnableMaximumLanguageFeatures)
	// because enabling it turns off support for a feature that is normally on by default.
	FeatureDisallowGroupByFloat LanguageFeature = 3

	// If enabled, treats TIMESTAMP literal as 9 digits (nanos) precision.
	// Otherwise TIMESTAMP has 6 digits (micros) precision.
	// In general, a TIMESTAMP value has only 6 digits precision. This feature
	// will only affect how a timestamp literal string is interpreted into a
	// TIMESTAMP value. If enabled, a timestamp literal string can have up to 9
	// digits of subseconds(nanos). Otherwise, it can only have up to 6 digits of
	// subseconds (micros). 9 digits subsecond literal is not a valid timestamp
	// string in the later case.
	FeatureTimestampNanos LanguageFeature = 5

	// Enable support for JOINs in UPDATE statements.
	FeatureDMLUpdateWithJoin LanguageFeature = 6

	// Enable table-valued functions.
	FeatureTableValuedFunctions LanguageFeature = 8

	// This enables support for CREATE AGGREGATE FUNCTION.
	FeatureCreateAggregateFunction LanguageFeature = 9

	// This enables support for CREATE TABLE FUNCTION.
	FeatureCreateTableFunction LanguageFeature = 10

	// This enables support for GROUP BY ROLLUP.
	FeatureGroupByRollup LanguageFeature = 12

	// This enables support for creating and calling functions with templated
	// argument types, using CREATE FUNCTION, CREATE AGGREGATE FUNCTION, or CREATE
	// TABLE FUNCTION statements. For example, a function argument may be written
	// as "argument ANY TYPE" to match against any scalar value.
	FeatureTemplateFunctions LanguageFeature = 13

	// Enables support for PARTITION BY with CREATE TABLE and CREATE TABLE AS.
	FeatureCreateTablePartitionBy LanguageFeature = 14

	// Enables support for CLUSTER BY with CREATE TABLE and CREATE TABLE AS.
	FeatureCreateTableClusterBy LanguageFeature = 15

	// NUMERIC type support.
	FeatureNumericType LanguageFeature = 16

	// Enables support for NOT NULL annotation in CREATE TABLE.
	// See comment on FEATURE_CREATE_TABLE_FIELD_ANNOTATIONS
	FeatureCreateTableNotNull LanguageFeature = 17

	// Enables support for annotations (e.g., NOT NULL and OPTIONS()) for struct
	// fields and array elements in CREATE TABLE.
	// Does not affect table options or table column annotations.
	//
	// Example: Among the following queries
	// Q1: CREATE TABLE t (c STRUCT<a INT64> NOT NULL)
	// Q2: CREATE TABLE t (c STRUCT<a INT64 NOT NULL>)
	// Q3: CREATE TABLE t (c STRUCT<a INT64> OPTIONS(foo=1))
	// Q4: CREATE TABLE t (c STRUCT<a INT64 OPTIONS(foo=1)>)
	// Q5: CREATE TABLE t (c STRUCT<a INT64 NOT NULL OPTIONS(foo=1)>)
	//
	// Allowed queries                  FEATURE_CREATE_TABLE_FIELD_ANNOTATIONS
	//                                         =0               =1
	// FEATURE_CREATE_TABLE_NOT_NULL=0        {Q3}           {Q3, Q4}
	// FEATURE_CREATE_TABLE_NOT_NULL=1      {Q1, Q3}    {Q1, Q2, Q3, Q4, Q5}
	FeatureCreateTableFieldAnnotations LanguageFeature = 18

	// Enables support for column definition list in CREATE TABLE AS SELECT.
	// Example: CREATE TABLE t (x FLOAT64) AS SELECT 1 x
	// The features in the column definition list are controlled by
	// FEATURE_CREATE_TABLE_NOT_NULL and FEATURE_CREATE_TABLE_FIELD_ANNOTATIONS.
	FeatureCreateTableAsSelectColumnList LanguageFeature = 19

	// Indicates that an engine that supports primary keys does not allow any
	// primary key column to be NULL. Similarly, non-NULL primary key columns
	// cannot have any NULL array elements or struct/proto fields anywhere inside
	// them.
	//
	// Only interpreted by the compliance tests and the reference implementation
	// (not the analyzer). It exists so that engines can disable tests for this
	// atypical behavior without impacting their compliance ratios. It can never
	// be totally enforced in the analyzer because the analyzer cannot evaluate
	// expressions.
	//
	// TODO: When this feature is enabled, the reference implementation
	// forbids NULL primary key columns, but it allows NULL array elements and
	// NULL struct/proto fields. Change this behavior if we ever want to write
	// compliance tests for these cases.
	FeatureDisallowNullPrimaryKeys LanguageFeature = 20

	// Indicates that an engine that supports primary keys does not allow any
	// primary key column to be modified with UPDATE.
	//
	// Only interpreted by the compliance tests and the reference implementation
	// (not the analyzer) for now. It exists so that engines can disable tests for
	// this atypical behavior without impacting their compliance ratios.
	//
	// TODO: Consider exposing information about primary keys to the
	// analyzer and enforcing this feature there.
	FeatureDisallowPrimaryKeyUpdates LanguageFeature = 21

	// Enables support for the TABLESAMPLE clause applied to table-valued function
	// calls. For more information about table-valued functions.
	FeatureTablesampleFromTableValuedFunctions LanguageFeature = 22

	// Enable encryption- and decryption-related functions.
	FeatureEncryption LanguageFeature = 23

	// Differentially private anonymization functions, syntax, and semantics.
	FeatureAnonymization LanguageFeature = 24

	// Geography type support.
	FeatureGeography LanguageFeature = 25

	// Enables support for stratified TABLESAMPLE.
	// For more information about stratified sampling.
	FeatureStratifiedReservoirTablesample LanguageFeature = 26

	// Enables foreign keys.
	FeatureForeignKeys LanguageFeature = 27

	// Enables BETWEEN function signatures for UINT64/INT64 comparisons.
	FeatureBetweenUint64Int64 LanguageFeature = 28

	// Enables check constraint.
	FeatureCheckConstraint LanguageFeature = 29

	// Enables statement parameters and system variables in the GRANTEE list of
	// GRANT, REVOKE, CREATE ROW POLICY, and ALTER ROW POLICY statements.
	// TODO: The behavior of this feature is intended to become
	// mandatory.  This is a temporary feature, that preserves existing
	// behavior prior to engine migrations.  Once all engines have migrated,
	// this feature will be deprecated/removed and the new behavior will be mandatory.
	FeatureParametersInGranteeList LanguageFeature = 30

	// Enables support for named arguments in function calls using a syntax like
	// this: 'SELECT function(argname => 'value', otherarg => 42)'. Function
	// arguments with associated names in the signature options may specify values
	// by providing the argument name followed by an equals sign and greater than
	// sign (=>) followed by a value for the argument. Function calls may include
	// a mix of positional arguments and named arguments. The resolver will
	// compare provided arguments against function signatures and handle signature
	// matching appropriately.
	FeatureNamedArguments LanguageFeature = 31

	// Enables support for the old syntax for the DDL for ROW ACCESS POLICY,
	// previously called ROW POLICY.
	//
	// When this feature is enabled, either the legacy or new syntax can be used
	// for CREATE/DROP ROW [ACCESS] POLICY.  Note, however, that when using the
	// new syntax the GRANT TO clause is required (the GRANT TO clause is optional
	// when the feature is off).
	//
	// When it is not enabled, the new syntax must be used for CREATE ROW ACCESS
	// POLICY and DROP ALL ROW ACCESS POLICIES. The new syntax is always required
	// for ALTER ROW ACCESS POLICY and DROP ROW ACCESS POLICY: at the time of this
	// writing, these statements are new/not in use.
	//
	// This is a temporary feature that preserves legacy engine behavior that will
	// be deprecated, and the new syntax will become mandatory (b/135116351). For
	// more details on syntax changes.
	FeatureAllowLegacyRowAccessPolicySyntax LanguageFeature = 32

	// Enables support for PARTITION BY with CREATE MATERIALIZED VIEW.
	FeatureCreateMaterializedViewPartitionBy LanguageFeature = 33

	// Enables support for CLUSTER BY with CREATE MATERIALIZED VIEW.
	FeatureCreateMaterializedViewClusterBy LanguageFeature = 34

	// Enables support for column definition list in CREATE EXTERNAL TABLE.
	// Example: CREATE EXTERNAL TABLE t (x FLOAT64)
	FeatureCreateExternalTableWithTableElementList LanguageFeature = 35

	// Enables using NOT ENFORCED in primary keys.
	FeatureUnenforcedPrimaryKeys LanguageFeature = 40

	// BIGNUMERIC data type.
	FeatureBignumericType LanguageFeature = 41

	// Extended types (TYPE_EXTENDED).
	FeatureExtendedTypes LanguageFeature = 42

	// JSON data type.
	FeatureJsonType LanguageFeature = 43

	// If true, JSON values are not parsed and validated.
	FeatureJsonNoValidation LanguageFeature = 44

	// If true, JSON string documents will be parsed using the proto JSON parse
	// rules that are more relaxed than the JSON RFC (for example allowing single
	// quotes in the documents).
	FeatureJsonLegacyParse LanguageFeature = 46

	// Enables support for WITH PARTITION COLUMNS in CREATE EXTERNAL TABLE.
	// Example:
	// CREATE EXTERNAL TABLE t WITH PARTITION COLUMNS (x int64)
	FeatureCreateExternalTableWithPartitionColumns LanguageFeature = 47

	// INTERVAL data type.
	FeatureIntervalType LanguageFeature = 49

	// If enabled, JSON parsing fails for JSON documents containing number values
	// that cannot fit into the range of numbers supported by uint64, int64 or
	// double.
	// For unsigned integers, the valid range is [0, 2^64-1]
	// For signed integers, the valid range is [-2^63, 2^63-1].
	// For floating point values, the valid range contains all numbers that can
	// round-trip from string -> double -> string. The round-tripped string
	// doesn't need to match the input string exactly, but must hold the same
	// number value (i.e. "1e+3" -> double -> "1000" is a valid round-trip).
	// If precision loss occurs as a result of the round-trip, the number is not
	// considered valid (i.e. 0.142857142857142857142857142857142857 -> double ->
	// 14285714285714285 is not valid).
	// NOTE: FEATURE_JSON_LEGACY_PARSE does not work with
	// FEATURE_JSON_STRICT_NUMBER_PARSING
	FeatureJsonStrictNumberParsing LanguageFeature = 52

	// When enabled, (table) function argument names will hide column names in
	// expression resolution and relational table function argument names will
	// hide table names from the catalog. This changes name resolution and is
	// a backward compatibility breaking change.
	//
	// Related bugs: b/118904900 (scalar arguments) b/165763119 (table arguments)
	FeatureFunctionArgumentNamesHideLocalNames LanguageFeature = 55

	// Enables support for the following parameterized types.
	// - STRING(L) / BYTES(L)
	// - NUMERIC(P) / NUMERIC(P, S)
	// - BIGNUMERIC(P) / BIGNUMERIC(P, S)
	FeatureParameterizedTypes LanguageFeature = 56

	// Enables support for CREATE TABLE LIKE
	// Example:
	// CREATE TABLE t1 LIKE t2
	FeatureCreateTableLike LanguageFeature = 57

	// Enable support for JSON_EXTRACT_STRING_ARRAY, JSON_VALUE_ARRAY and
	// JSON_QUERY_ARRAY.
	FeatureJsonArrayFunctions LanguageFeature = 58

	// Enables explicit column list for CREATE VIEW.
	// Example:
	// CREATE VIEW v(a, b) AS SELECT ...
	FeatureCreateViewWithColumnList LanguageFeature = 59

	// Enables support for CREATE TABLE CLONE
	// Example:
	// CREATE TABLE t1 CLONE t2
	FeatureCreateTableClone LanguageFeature = 60

	// Enables support for CLONE DATA INTO
	// Example: CLONE DATA INTO ds.tbl;
	FeatureCloneData LanguageFeature = 61

	// Enables support for ALTER COLUMN SET DATA TYPE.
	FeatureAlterColumnSetDataType LanguageFeature = 62

	// Enables support for CREATE SNAPSHOT TABLE.
	FeatureCreateSnapshotTable LanguageFeature = 63

	// Enables support for defining argument defaults in function calls using
	// syntax like:
	//   CREATE FUNCTION foo (a INT64 DEFAULT 5) AS (a);
	// In effect, the argument with a default becomes optional when the function
	// is called, like:
	//   SELECT foo();
	FeatureFunctionArgumentsWithDefaults LanguageFeature = 64

	// Enables support for WITH CONNECTION in CREATE EXTERNAL TABLE.
	// Example:
	// CREATE EXTERNAL TABLE t WITH CONNECTION `project.region.connection_1`
	FeatureCreateExternalTableWithConnection LanguageFeature = 65

	// Enables support for CREATE TABLE COPY
	// Example:
	// CREATE TABLE t1 COPY t2
	FeatureCreateTableCopy LanguageFeature = 66

	// Enables support for ALTER TABLE RENAME COLUMN.
	FeatureAlterTableRenameColumn LanguageFeature = 67

	// Enables STRING(JSON), INT64(JSON), BOOL(JSON), DOUBLE(JSON),
	// JSON_TYPE(JSON) functions.
	FeatureJsonValueExtractionFunctions LanguageFeature = 68

	// Enables LAX_BOOL(JSON), LAX_INT64(JSON), LAX_FLOAT64(JSON), and
	// LAX_STRING(JSON) functions.
	FeatureJsonLaxValueExtractionFunctions LanguageFeature = 81

	// Enables JSON_ARRAY, JSON_OBJECT(STRING, ANY, ...), and
	// JSON_OBJECT(ARRAY<STRING>, ARRAY<ANY>).
	FeatureJsonConstructorFunctions LanguageFeature = 93

	// Enables JSON_REMOVE, JSON_SET, JSON_STRIP_NULLS, JSON_ARRAY_INSERT,
	// JSON_ARRAY_APPEND.
	FeatureJsonMutatorFunctions LanguageFeature = 98

	// Enables JSON_KEYS(JSON[, INT64 max_depth][, mode=>STRING]).
	FeatureJsonKeysFunction LanguageFeature = 118

	// Disallows "unicode", "unicode:ci", "unicode:cs" in ORDER BY ... COLLATE and
	// other collation features. "unicode" is a legacy feature, and the desired
	// behavior is to allow only "binary" and valid icu language tags.
	// Enabling this feature must produce an error if 'unicode' is specified as
	// a collation name.
	FeatureDisallowLegacyUnicodeCollation LanguageFeature = 69

	FeatureAllowMissingPathExpressionInAlterDDL LanguageFeature = 70

	// Enable ORDER BY COLLATE.
	FeatureV11OrderByCollate LanguageFeature = 11001

	// Enable WITH clause on subqueries.  Without this, WITH is allowed
	// only at the top level.  The WITH subqueries still cannot be
	// correlated subqueries.
	FeatureV11WithOnSubquery LanguageFeature = 11002

	// Enable the SELECT * EXCEPT and SELECT * REPLACE features.
	FeatureV11SelectStarExceptReplace LanguageFeature = 11003

	// Enable the ORDER BY in aggregate functions.
	FeatureV11OrderByInAggregate LanguageFeature = 11004

	// Enable casting between different array types.
	FeatureV11CastDifferentArrayTypes LanguageFeature = 11005

	// Enable comparing array equality.
	FeatureV11ArrayEquality LanguageFeature = 11006

	// Enable LIMIT in aggregate functions.
	FeatureV11LimitInAggregate LanguageFeature = 11007

	// Enable HAVING modifier in aggregate functions.
	FeatureV11HavingInAggregate LanguageFeature = 11008

	// Enable IGNORE/RESPECT NULLS modifier in analytic functions.
	FeatureV11NullHandlingModifierInAnalytic LanguageFeature = 11009

	// Enable IGNORE/RESPECT NULLS modifier in aggregate functions.
	FeatureV11NullHandlingModifierInAggregate LanguageFeature = 11010

	// Enable FOR SYSTEM_TIME AS OF (time travel).
	FeatureV11ForSystemTimeAsOf LanguageFeature = 11011

	// Enable TIME and DATETIME types and related functions.
	FeatureV12CivilTime LanguageFeature = 12001

	// Enable SAFE mode function calls.  e.g. SAFE.FUNC(...) for FUNC(...).
	FeatureV12SafeFunctionCall LanguageFeature = 12002

	// Enable support for GROUP BY STRUCT.
	FeatureV12GroupByStruct LanguageFeature = 12003

	// Enable use of proto extensions with NEW.
	FeatureV12ProtoExtensionsWithNew LanguageFeature = 12004

	// Enable support for GROUP BY ARRAY.
	FeatureV12GroupByArray LanguageFeature = 12005

	// Enable use of proto extensions with UPDATE ... SET.
	FeatureV12ProtoExtensionsWithSet LanguageFeature = 12006

	// Allows nested DML statements to refer to names defined in the parent
	// scopes. Without this, a nested DML statement can only refer to names
	// created in the local statement - i.e. the array element.
	// Examples that are allowed only with this option:
	//   UPDATE Table t SET (UPDATE t.ArrayColumn elem SET elem = t.OtherColumn)
	//   UPDATE Table t SET (DELETE t.ArrayColumn elem WHERE elem = t.OtherColumn)
	//   UPDATE Table t SET (INSERT t.ArrayColumn VALUES (t.OtherColumn))
	//   UPDATE Table t SET (INSERT t.ArrayColumn SELECT t.OtherColumn)
	FeatureV12CorrelatedRefsInNestedDML LanguageFeature = 12007

	// Enable use of WEEK(<Weekday>) with the functions that support it.
	FeatureV12WeekWithWeekday LanguageFeature = 12008

	// Enable use of array element [] syntax in targets with UPDATE ... SET.
	// For example, allow UPDATE T SET a.b[OFFSET(0)].c = 5.
	FeatureV12ArrayElementsWithSet LanguageFeature = 12009

	// Enable nested updates/deletes of the form
	// UPDATE/DELETE ... WITH OFFSET AS ... .
	FeatureV12NestedUpdateDeleteWithOffset LanguageFeature = 12010

	// Enable Generated Columns on CREATE and ALTER TABLE statements.
	FeatureV12GeneratedColumns LanguageFeature = 12011

	// Enables support for the PROTO_DEFAULT_IF_NULL() function.
	FeatureV13ProtoDefaultIfNull LanguageFeature = 13001

	// Enables support for proto field pseudo-accessors in the EXTRACT function.
	// For example, EXTRACT(FIELD(x) from foo) will extract the value of the field
	// x defined in message foo. EXTRACT(HAS(x) from foo) will return a boolean
	// denoting if x is set in foo or NULL if foo is NULL. EXTRACT(RAW(x) from
	// foo) will get the value of x on the wire (i.e., without applying any
	// FieldFormat.Format annotations or automatic conversions). If the field is
	// missing, the default is always returned, which is NULL for message fields
	// and the field default (either the explicit default or the default default)
	// for primitive fields. If the containing message is NULL, NULL is returned.
	FeatureV13ExtractFromProto LanguageFeature = 13002

	// If enabled, the analyzer will return an error when attempting to check
	// if a proto3 scalar field has been explicitly set (e.g.,
	// proto3.has_scalar_field and EXTRACT(HAS(scalar_field) from proto3)).
	// This feature is deprecated and should not be used, since proto3 now
	// supports scalar field presence testing. Eventually we will remove this
	// feature and the underlying code.
	FeatureDeprecatedDisallowProto3HasScalarField LanguageFeature = 13003

	// Enable array ordering (and non-equality comparisons).  This enables
	// arrays in the ORDER BY of a query, as well as in aggregate and analytic
	// function arguments.  Also enables inequality comparisons between arrays
	// (<, <=, >, >=).  This flag enables arrays for MIN/MAX,
	// although semantics over array inputs are surprising sometimes.
	//
	// Note: there is a separate flag for GREATEST/LEAST, as not all engines are
	//       ready to implement them for arrays.
	FeatureV13ArrayOrdering LanguageFeature = 13004

	// Allow omitting column and value lists in INSERT statement and INSERT clause
	// of MERGE statement.
	FeatureV13OmitInsertColumnList LanguageFeature = 13005

	// If enabled, the 'use_defaults' and 'use_field_defaults' annotations are
	// ignored for proto3 scalar fields. This results in the default value always
	// being returned for proto3 scalar fields that are not explicitly set,
	// including when they are annotated with 'use_defaults=false' or their parent
	// message is annotated with 'use_field_defaults=false'. This aligns with
	// proto3 semantics as proto3 does not expose whether scalar fields are set or
	// not.
	FeatureV13IgnoreProto3UseDefaults LanguageFeature = 13006

	// Enables support for the REPLACE_FIELDS() function. REPLACE_FIELDS(p,
	// <value> AS <field_path>) returns the proto obtained by setting p.field_path
	// = value. If value is NULL, this unsets field_path or returns an error if
	// the last component of field_path is a required field. Multiple fields can
	// be modified: REPLACE_FIELDS(p, <value_1> AS <field_path_1>, ..., <value_n>
	// AS <field_path_n>). REPLACE_FIELDS() can also be used to modify structs
	// using the similar syntax: REPLACE_FIELDS(s, <value> AS
	// <struct_field_path>).
	FeatureV13ReplaceFields LanguageFeature = 13007

	// Enable NULLS FIRST/NULLS LAST in ORDER BY expressions.
	FeatureV13NullsFirstLastInOrderBy LanguageFeature = 13008

	// Allows dashes in the first part of multi-part table name. This is to
	// accommodate GCP project names which use dashes instead of underscores, e.g.
	// crafty-tractor-287. So fully qualified table name which includes project
	// name normally has to be quoted in the query, i.e. SELECT * FROM
	// `crafty-tractor-287`.dataset.table This feature allows it to be used
	// unquoted, i.e. SELECT * FROM crafty-tractor-287.dataset.table
	FeatureV13AllowDashesInTableName LanguageFeature = 13009

	// CONCAT allows arguments of different types, automatically coerced to
	// STRING for FN_CONCAT_STRING signature. Only types which have CAST to
	// STRING defined are allowed, and BYTES is explicitly excluded (since BYTES
	// should match FN_CONCAT_BYTES signature).
	FeatureV13ConcatMixedTypes LanguageFeature = 13010

	// Enable WITH RECURSIVE
	FeatureV13WithRecursive LanguageFeature = 13011

	// Support maps in protocol buffers.
	FeatureV13ProtoMaps LanguageFeature = 13012

	// Enables support for the ENUM_VALUE_DESCRIPTOR_PROTO() function.
	FeatureV13EnumValueDescriptorProto LanguageFeature = 13013

	// Allows DECIMAL as an alias of NUMERIC type, and BIGDECIMAL as an alias
	// of BIGNUMERIC type. By itself, this feature does not enable NUMERIC type
	// or BIGNUMERIC, which are controlled by FEATURE_NUMERIC_TYPE and
	// FEATURE_BIGNUMERIC_TYPE.
	FeatureV13DecimalAlias LanguageFeature = 13014

	// Support UNNEST and FLATTEN on paths through arrays.
	FeatureV13UnnestAndFlattenArrays LanguageFeature = 13015

	// Allows consecutive ON/USING clauses for JOINs, such as
	//    t1 JOIN t2 JOIN t3 ON cond1 USING (col2)
	FeatureV13AllowConsecutiveOn LanguageFeature = 13016

	// Enables support for optional parameters position and occurrence in
	// REGEXP_EXTRACT. In addition, allows alias REGEXP_SUBSTR.
	FeatureV13AllowRegexpExtractOptionals LanguageFeature = 13017

	// Additional signatures for DATE, TIMESTAMP, TIME, DATETIME and STRING
	// constructor functions.
	FeatureV13DateTimeConstructors LanguageFeature = 13018

	// Enables DATE +/- INT64 arithmetics.
	FeatureV13DateArithmetics LanguageFeature = 13019

	// Enable support for additional string functions.
	FeatureV13AdditionalStringFunctions LanguageFeature = 13020

	// Enable support for aggregate functions with WITH GROUP_ROWS syntax.
	FeatureV13WithGroupRows LanguageFeature = 13021

	// Additional signatures for [DATE|DATETIME|TIMESTAMP]_[ADD|SUB|DIFF|TRUNC]
	// functions.
	FeatureV13ExtendedDateTimeSignatures LanguageFeature = 13022

	// Additional signatures for ST_GeogFromText/FromGeoJson/From* functions.
	FeatureV13ExtendedGeographyParsers LanguageFeature = 13023

	// Inline lambda function argument.
	FeatureV13InlineLambdaArgument LanguageFeature = 13024

	// PIVOT clause.
	FeatureV13Pivot LanguageFeature = 13025

	// This flag enables propagation of annotation during query analysis. See
	// public/types/annotation.h for the introduction of annotation framework.
	// Engines must turn on this flag before turning on any built-in annotation
	// feature or passing in engine defined AnnotationSpec.
	FeatureV13AnnotationFramework LanguageFeature = 13026

	// Enables collation annotation support.
	FeatureV13CollationSupport LanguageFeature = 13027

	// IS [NOT] DISTINCT FROM.
	FeatureV13IsDistinct LanguageFeature = 13028

	// If true, FORMAT clause is supported in CAST().
	// Fully implemented:
	//   BYTES <=> STRING
	//   DATE/DATETIME/TIME/TIMESTAMP => STRING
	//
	// Under development:
	//   STRING => DATE/DATETIME/TIME/TIMESTAMP
	//   NUMBER => STRING
	FeatureV13FormatInCast LanguageFeature = 13029

	// UNPIVOT clause.
	FeatureV13Unpivot LanguageFeature = 13030

	// If true, dml returning is supported.
	FeatureV13DMLReturning LanguageFeature = 13031

	// Enables support for the FILTER_FIELDS() function.
	//    FILTER_FIELDS(p, <-|+><field_path>, ...)
	// returns the proto obtained by keeping p.field_path whose
	// sign is '+' and remove p.field_path whose sign is '-'.
	FeatureV13FilterFields LanguageFeature = 13032

	// QUALIFY clause.
	FeatureV13Qualify LanguageFeature = 13033

	// Enable support for REPEAT...UNTIL...END REPEAT statement.
	FeatureV13Repeat LanguageFeature = 13034

	// Enables column DEFAULT clause in CREATE and ALTER TABLE statements.
	FeatureV13ColumnDefaultValue LanguageFeature = 13035

	// Enable support for FOR...IN...DO...END FOR statement.
	FeatureV13ForIn LanguageFeature = 13036

	// Enables support for initializing KLLs with weights as an additional
	// parameter. Support for this feature in addition to the weighting
	// functionality also requires support for named arguments as the weight
	// argument must be named.
	FeatureKllWights LanguageFeature = 13037

	// LIKE ANY/SOME/ALL support.
	FeatureV13LikeAnySomeAll LanguageFeature = 13038

	// Enable support for CASE...WHEN...THEN...END CASE statement.
	FeatureV13CaseStmt LanguageFeature = 13039

	// Support for table names that start with slash and contain slashes, dashes,
	// and colons before the first dot: /span/test/my-grp:db.Table.
	FeatureV13AllowSlashPaths LanguageFeature = 13040

	// Enable the TYPEOF(expr) debugging and exploration function.
	FeatureV13TypeofFunction LanguageFeature = 13041

	// Enable support for SCRIPT LABELS (e.g. L1: BEGIN...END).
	FeatureV13ScriptLabel LanguageFeature = 13042

	// Enable support for remote function (e.g. CREATE FUNCTION ... REMOTE ...).
	FeatureV13RemoteFunction LanguageFeature = 13043

	// If Array ordering is enabled, this flag enables arrays for GREATEST/LEAST.
	FeatureV13ArrayGreatestLeast LanguageFeature = 13044

	// SQL macros (DEFINE MACRO, ...). Required for parser/tokenizer when a macro catalog is present.
	FeatureV14SqlMacros LanguageFeature = 14012

	// Enable GROUP BY ALL (non-standard grouping: all non-aggregated SELECT list columns).
	FeatureV14GroupByAll LanguageFeature = 14039

	// Enable GoogleSQL MODULES.  For an engine to fully opt into this feature,
	// they must enable this feature flag and add support for the related
	// StatementKinds: ImportStmtNode and ModuleStmtNode.
	FeatureExperimentalModules LanguageFeature = 999002

	// These are not real features. They are just for unit testing the handling of
	// various LanguageFeatureOptions.
	FeatureTestIdeallyEnabledButInDevelopment LanguageFeature = 999991

	FeatureTestIdeallyDisabled LanguageFeature = 999992

	FeatureTestIdeallyDisabledAndInDevelopment LanguageFeature = 999993
)

type LanguageOptions ¶

type LanguageOptions struct {
	// contains filtered or unexported fields
}

LanguageOptions contains options controlling the language that should be accepted, and the desired semantics. This is used for libraries where behavior differs by language version, flags, or other options.

func NewLanguageOptions ¶

func NewLanguageOptions() *LanguageOptions

NewLanguageOptions creates a new LanguageOptions instance.

func (*LanguageOptions) AddSupportedStatementKind ¶

func (o *LanguageOptions) AddSupportedStatementKind(kind resolved_ast.Kind)

AddSupportedStatementKind adds <kind> to the set of supported statement kinds.

func (*LanguageOptions) BuiltinFunctionOptions ¶

func (o *LanguageOptions) BuiltinFunctionOptions() *types.BuiltinFunctionOptions

func (*LanguageOptions) DisableAllLanguageFeatures ¶

func (o *LanguageOptions) DisableAllLanguageFeatures()

DisableAllLanguageFeatures.

func (*LanguageOptions) EnableAllReservableKeywords ¶

func (o *LanguageOptions) EnableAllReservableKeywords(reserved bool)

EnableAllReservableKeywords similar to EnableReservableKeyword(), but applies to all reservable keywords.

func (*LanguageOptions) EnableLanguageFeature ¶

func (o *LanguageOptions) EnableLanguageFeature(feature LanguageFeature)

EnableLanguageFeature enables support for the specified <feature>.

func (*LanguageOptions) EnableMaximumLanguageFeatures ¶

func (o *LanguageOptions) EnableMaximumLanguageFeatures()

EnableMaximumLanguageFeatures enable all optional features and reservable keywords that are enabled in the idealized GoogleSQL and are released to users.

func (*LanguageOptions) EnableMaximumLanguageFeaturesForDevelopment ¶

func (o *LanguageOptions) EnableMaximumLanguageFeaturesForDevelopment()

Enable all optional features and reservable keywords that are enabled in the idealized GoogleSQL, including features that are still under development. For internal GoogleSQL use only.

func (*LanguageOptions) EnableReservableKeyword ¶

func (o *LanguageOptions) EnableReservableKeyword(keyword string, reserved bool) error

EnableReservableKeyword indicates whether or not <keyword> should be considered "reserved". reservable keywords are nonreserved by default. When nonreserved, they still exist as keywords, but may also be used in queries as identifiers, without backticks.

Returns an error if <keyword> is not reservable.

<keyword> is case-insensitive.

func (*LanguageOptions) EnabledLanguageFeatures ¶

func (o *LanguageOptions) EnabledLanguageFeatures() []LanguageFeature

EnabledLanguageFeatures.

func (*LanguageOptions) EnabledLanguageFeaturesAsString ¶

func (o *LanguageOptions) EnabledLanguageFeaturesAsString() string

EnabledLanguageFeaturesAsString returns a comma-separated string listing enabled LanguageFeatures.

func (*LanguageOptions) ErrorOnDeprecatedSyntax ¶

func (o *LanguageOptions) ErrorOnDeprecatedSyntax() bool

ErrorOnDeprecatedSyntax.

func (*LanguageOptions) GenericEntityTypeSupported ¶

func (o *LanguageOptions) GenericEntityTypeSupported(typ string) bool

GenericEntityTypeSupported.

func (*LanguageOptions) IsReservedKeyword ¶

func (o *LanguageOptions) IsReservedKeyword(keyword string) bool

IsReservedKeyword returns true if <keyword> is reserved.

reservable keywords are non-reserved by default, but can be made reserved by calling EnableReservableKeyword().

For non-reservable keywords, the return value simply indicates the fixed behavior as to whether the keyword is reserved or not (e.g. true for SELECT, false for DECIMAL).

For non-keywords, the return value is false.

<keyword> is case-insensitive.

func (*LanguageOptions) LanguageFeatureEnabled ¶

func (o *LanguageOptions) LanguageFeatureEnabled(feature LanguageFeature) bool

LanguageFeatureEnabled teturns whether or not <feature> is enabled.

func (*LanguageOptions) NameReolutionMode ¶

func (o *LanguageOptions) NameReolutionMode() NameResolutionMode

NameReolutionMode.

func (*LanguageOptions) ProductMode ¶

func (o *LanguageOptions) ProductMode() types.ProductMode

ProductMode returns current ProductMode.

func (*LanguageOptions) SetEnabledLanguageFeatures ¶

func (o *LanguageOptions) SetEnabledLanguageFeatures(features []LanguageFeature)

func (*LanguageOptions) SetErrorOnDeprecatedSyntax ¶

func (o *LanguageOptions) SetErrorOnDeprecatedSyntax(value bool)

SetErrorOnDeprecatedSyntax.

func (*LanguageOptions) SetLanguageVersion ¶

func (o *LanguageOptions) SetLanguageVersion(version LanguageVersion)

SetLanguageVersion set the GoogleSQL LanguageVersion. This is equivalent to enabling the set of LanguageFeatures defined as part of that version, and disabling all other LanguageFeatures. The LanguageVersion itself is not stored.

Calling this cancels out any previous calls to EnableLanguageFeature, so EnableLanguageFeature would normally be called after SetLanguageVersion.

func (*LanguageOptions) SetNameResolutionMode ¶

func (o *LanguageOptions) SetNameResolutionMode(mode NameResolutionMode)

SetNameReolutionMode.

func (*LanguageOptions) SetProductMode ¶

func (o *LanguageOptions) SetProductMode(mode types.ProductMode)

SetProductMode set ProductMode.

func (*LanguageOptions) SetSupportedGenericEntityTypes ¶

func (o *LanguageOptions) SetSupportedGenericEntityTypes(entityTypes []string)

SetSupportedGenericEntityTypes.

func (*LanguageOptions) SetSupportedStatementKinds ¶

func (o *LanguageOptions) SetSupportedStatementKinds(kinds []resolved_ast.Kind)

SetSupportedStatementKinds the provided set of resolved_ast.Kind indicates the statements supported by the caller. The potentially supported statements are the subclasses of StatementNode. An empty set indicates no restrictions. If GoogleSQL encounters a statement kind that is not supported during analysis, it immediately returns an error.

By default, the set includes only resolved_ast.QueryStmt, so callers must explicitly opt in to support other statements.

func (*LanguageOptions) SetSupportsAllStatementKinds ¶

func (o *LanguageOptions) SetSupportsAllStatementKinds()

SetSupportsAllStatementKinds equivalent to SetSupportedStatementKinds({}).

func (*LanguageOptions) SupportsProtoTypes ¶

func (o *LanguageOptions) SupportsProtoTypes() bool

SupportsProtoTypes.

func (*LanguageOptions) SupportsStatementKind ¶

func (o *LanguageOptions) SupportsStatementKind(kind resolved_ast.Kind) bool

SupportsStatementKind returns true if 'kind' is supported.

Note: The "supported statement kind" mechanism does not support script statements, as script statements do not exist in the resolved tree, so no resolved_ast.Kind enumeration for them exists. Script statements are gated through language features (see LanguageFeatureEnabled()).

type LanguageVersion ¶

type LanguageVersion int

LanguageVersion GoogleSQL language versions.

A language version defines a stable set of features and required semantics. LanguageVersion VersionXY implicitly includes the LanguageFeatures below named FeatureVXY*.

The features and behavior supported by an engine can be expressed as a LanguageVersion plus a set of LanguageFeatures added on top of that version.

New version numbers will be introduced periodically, and will normally include the new features that have been specified up to that point. Engines should move their version number forwards over time rather than accumulating large sets of LanguageFeatures.

const (
	VersionCurrent LanguageVersion = 1

	// Version 1.0, frozen January 2015.
	Version10 LanguageVersion = 10000

	// Version 1.1, frozen February 2017.
	Version11 LanguageVersion = 11000

	// Version 1.2, frozen January 2018.
	Version12 LanguageVersion = 12000

	// Version 1.3.  New features are being added here.
	Version13 LanguageVersion = 13000
)

type NameResolutionMode ¶

type NameResolutionMode int

This can be used to select strict name resolution mode.

In strict mode, implicit column names cannot be used unqualified. This ensures that existing queries will not be broken if additional elements are added to the schema in the future.

For example,

SELECT c1, c2 FROM table1, table2;

is not legal in strict mode because another column could be added to one of these tables, making the query ambiguous. The query must be written with aliases in strict mode:

SELECT t1.c1, t2.c2 FROM table1 t1, table t2;

SELECT * is also not allowed in strict mode because the number of output columns may change.

const (
	NameResolutionDefault NameResolutionMode = 0
	NameResolutionStrict  NameResolutionMode = 1
)

type NodeMap ¶

type NodeMap struct {
	// contains filtered or unexported fields
}

func NewNodeMap ¶

func NewNodeMap(resolvedNode resolved_ast.Node, node ast.Node) *NodeMap

func (*NodeMap) FindNodeFromResolvedNode ¶

func (m *NodeMap) FindNodeFromResolvedNode(n resolved_ast.Node) []ast.Node

func (*NodeMap) FindResolvedNodeFromNode ¶

func (m *NodeMap) FindResolvedNodeFromNode(n ast.Node) []resolved_ast.Node

type ParameterMode ¶

type ParameterMode int

ParameterMode mode describing how parameters are defined and referenced.

const (
	// Parameters are defined by name (the default) and referenced using the
	// syntax @param_name.
	ParameterNamed ParameterMode = 0

	// Parameters are defined positionally and referenced with ?. For example, if
	// two parameters are bound, the first occurrence of ? in the query string
	// refers to the first parameter and the second occurrence to the second
	// parameter.
	ParameterPositional ParameterMode = 1

	// No parameters are allowed in the query.
	ParameterNone ParameterMode = 2
)

type ParseLocationRecordType ¶

type ParseLocationRecordType int

ParseLocationRecordType the option controlling what kind of parse location is recorded in a resolved AST node.

const (
	// Parse locations are not recorded.
	ParseLocationRecordNone ParseLocationRecordType = 0

	// Parse locations cover the entire range of the related node, e.g., the full
	// function call text associated with a FunctionCallNode, or the full
	// expression text associated with a CastNode.
	ParseLocationRecordFullNodeScope ParseLocationRecordType = 1

	// Parse locations of nodes cover a related object name in the text, as
	// convenient for code search, e.g., just the function name associated with a
	// FunctionCallNode, or the target Type text associated with a CastNode.
	ParseLocationRecordCodeSearch ParseLocationRecordType = 2
)

type ParseResumeLocation ¶

type ParseResumeLocation struct {
	// contains filtered or unexported fields
}

ParseResumeLocation stores the parser input and a location, and is used as a restart token in repeated calls to operations that parse multiple items from one input string. Each successive call updates this location object so the next call knows where to start.

func NewParseResumeLocation ¶

func NewParseResumeLocation(src string) *ParseResumeLocation

NewParseResumeLocation creates ParseResumeLocation instance.

type ParserOptions ¶

type ParserOptions struct {
	// contains filtered or unexported fields
}

func NewParserOptions ¶

func NewParserOptions() *ParserOptions

func (*ParserOptions) LanguageOptions ¶

func (o *ParserOptions) LanguageOptions() *LanguageOptions

func (*ParserOptions) SetLanguageOptions ¶

func (o *ParserOptions) SetLanguageOptions(opt *LanguageOptions)

type QueryParametersMap ¶

type QueryParametersMap map[string]types.Type

type StatementContext ¶

type StatementContext int

StatementContext identifies whether statements are resolved in module context (i.e., as a statement contained in a module), or in normal/default context (outside of a module).

const (
	StatementContextDefault StatementContext = 0
	StatementContextModule  StatementContext = 1
)

type TableNameSet ¶

type TableNameSet struct{}

func ExtractTableNamesFromNextStatement ¶

func ExtractTableNamesFromNextStatement(loc *ParseResumeLocation) (*TableNameSet, bool, error)

func ExtractTableNamesFromScript ¶

func ExtractTableNamesFromScript(sql string) (*TableNameSet, error)

func ExtractTableNamesFromStatement ¶

func ExtractTableNamesFromStatement(sql string) (*TableNameSet, error)

Directories ¶

Path Synopsis
cmd
googlesql-prebuilts command
Command googlesql-prebuilts downloads default unified-prebuilt release tarballs and extracts them into a go-googlesql checkout.
Command googlesql-prebuilts downloads default unified-prebuilt release tarballs and extracts them into a go-googlesql checkout.
Package exportinc derives export.inc from bind.cc: the include prelude is everything after "// include headers" through the line before #include "bridge.h" (excluding blank lines and "//#" snippet lines), matching how CGO pulls headers without bridge symbols.
Package exportinc derives export.inc from bind.cc: the include prelude is everything after "// include headers" through the line before #include "bridge.h" (excluding blank lines and "//#" snippet lines), matching how CGO pulls headers without bridge symbols.
internal
ccall/go-googlesql-unified/googlesqlunified
Package googlesqlunified is the single CGO owner for libgooglesql_*.a (unified GoogleSQL static libs).
Package googlesqlunified is the single CGO owner for libgooglesql_*.a (unified GoogleSQL static libs).
cmd/exportincgen command
exportincgen synchronizes internal/ccall/**/export.inc with the include prelude in bind.cc.
exportincgen synchronizes internal/ccall/**/export.inc with the include prelude in bind.cc.
cmd/vendorpatch command
Command vendorpatch applies mechanical post-copy patches to vendored trees under internal/ccall: protobuf amalgamation (port_def/port_undef) then optional git patches (see docs/protobuf-vendoring.md).
Command vendorpatch applies mechanical post-copy patches to vendored trees under internal/ccall: protobuf amalgamation (port_def/port_undef) then optional git patches (see docs/protobuf-vendoring.md).
prebuiltsfetch
Package prebuiltsfetch builds GitHub Release URLs and verifies default prebuilt tarballs.
Package prebuiltsfetch builds GitHub Release URLs and verifies default prebuilt tarballs.
prebuiltsinstall
Package prebuiltsinstall extracts default prebuilt tarball layouts into a repo root.
Package prebuiltsinstall extracts default prebuilt tarball layouts into a repo root.
vendorpatch
Package vendorpatch applies go-googlesql-specific mechanical patches to vendored third-party trees (see docs/protobuf-vendoring.md).
Package vendorpatch applies go-googlesql-specific mechanical patches to vendored third-party trees (see docs/protobuf-vendoring.md).
lib
darwin-amd64 module
darwin-arm64 module
linux-amd64 module
linux-arm64 module
windows-amd64 module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL