From 34027ada6a718603be2987b4084ce5e0ead6413c Mon Sep 17 00:00:00 2001 From: David Symonds Date: Thu, 28 Jan 2021 22:32:02 +1100 Subject: [PATCH] feat(spanner/spansql): add complete set of string functions (#3625) This doesn't implement them, but only declares them for accurate parsing. Fixes #3618. --- spanner/spansql/keywords.go | 59 ++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/spanner/spansql/keywords.go b/spanner/spansql/keywords.go index 7296b486155..a2dd1db92bf 100644 --- a/spanner/spansql/keywords.go +++ b/spanner/spansql/keywords.go @@ -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", }