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

feat(spanner/spansql): add complete set of string functions #3625

Merged
merged 1 commit into from Jan 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 45 additions & 14 deletions spanner/spansql/keywords.go
Expand Up @@ -127,25 +127,56 @@ var keywords = map[string]bool{

// funcs is the set of reserved keywords that are functions.
// https://cloud.google.com/spanner/docs/functions-and-operators
var funcs = map[string]bool{
var funcs = make(map[string]bool)

func init() {
for _, f := range allFuncs {
funcs[f] = true
}
}

var allFuncs = []string{
// TODO: many more

// Aggregate functions.
"ANY_VALUE": true,
"ARRAY_AGG": true,
"AVG": true,
"BIT_XOR": true,
"COUNT": true,
"MAX": true,
"MIN": true,
"SUM": true,
"ANY_VALUE",
"ARRAY_AGG",
"AVG",
"BIT_XOR",
"COUNT",
"MAX",
"MIN",
"SUM",

// Mathematical functions.
"ABS": true,
"ABS",

// Hash functions.
"SHA1": true,
"SHA1",

// String functions.
"CHAR_LENGTH": true,

// TODO: many more
"BYTE_LENGTH", "CHAR_LENGTH", "CHARACTER_LENGTH",
"CODE_POINTS_TO_BYTES", "CODE_POINTS_TO_STRING",
"CONCAT",
"ENDS_WITH",
"FORMAT",
"FROM_BASE32", "FROM_BASE64", "FROM_HEX",
"LENGTH",
"LOWER",
"LPAD",
"LTRIM",
"REGEXP_CONTAINS", "REGEXP_EXTRACT", "REGEXP_EXTRACT_ALL", "REGEXP_REPLACE",
"REPEAT",
"REPLACE",
"REVERSE",
"RPAD",
"RTRIM",
"SAFE_CONVERT_BYTES_TO_STRING",
"SPLIT",
"STARTS_WITH",
"STRPOS",
"SUBSTR",
"TO_BASE32", "TO_BASE64", "TO_CODE_POINTS", "TO_HEX",
"TRIM",
"UPPER",
}