Skip to content

Commit

Permalink
[String] Use direct string value from ZetaSQL (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Feb 28, 2024
1 parent ab00d52 commit a6df7f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ func ValueFromZetaSQLValue(v types.Value) (Value, error) {
return boolValueFromLiteral(v.SQLLiteral(0))
case types.FLOAT, types.DOUBLE:
return floatValueFromLiteral(v.SQLLiteral(0))
case types.STRING, types.ENUM:
case types.STRING:
return StringValue(v.StringValue()), nil
case types.ENUM:
return stringValueFromLiteral(v.SQLLiteral(0))
case types.BYTES:
return bytesValueFromLiteral(v.SQLLiteral(0))
Expand Down Expand Up @@ -206,9 +208,6 @@ func floatValueFromLiteral(lit string) (FloatValue, error) {
}

func stringValueFromLiteral(lit string) (StringValue, error) {
if strings.HasPrefix(lit, `'`) {
return StringValue(strings.Trim(lit, `'`)), nil
}
v, err := strconv.Unquote(lit)
if err != nil {
return "", fmt.Errorf("failed to unquote from string literal: %w", err)
Expand Down
9 changes: 9 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3716,6 +3716,15 @@ WITH markdown AS (
{"<h1>Another heading</h1>"},
},
},
// Regression tests for goccy/go-zetasqlite#178
{
name: "regexp_replace quoted",
query: `SELECT REGEXP_REPLACE('"quote123"', r'["\d]', '')`,
expectedRows: [][]interface{}{
{"quote"},
},
},

{
name: "regexp_replace null",
query: `SELECT REGEXP_REPLACE(NULL, r'\:\d\d\d', ''), REGEXP_REPLACE('abc', NULL, ''), REGEXP_REPLACE('abc', r'\:\d\d\d', NULL)`,
Expand Down

0 comments on commit a6df7f5

Please sign in to comment.