Skip to content

Commit

Permalink
Fix WithExpr (#260)
Browse files Browse the repository at this point in the history
* fix: Fix WithExpr to accept non-ident Expr

* Update testdata
  • Loading branch information
apstndb authored Jan 9, 2025
1 parent e693098 commit d885fe3
Show file tree
Hide file tree
Showing 4 changed files with 834 additions and 0 deletions.
4 changes: 4 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,10 @@ func (p *Parser) lookaheadWithExprVar() bool {
p.Lexer = lexer
}()

if p.Token.Kind != token.TokenIdent {
return false
}

p.parseIdent()
return p.Token.Kind == "AS"
}
Expand Down
12 changes: 12 additions & 0 deletions testdata/input/query/select_from_where_order_by_with.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- https://cloud.google.com/spanner/docs/full-text-search/ranked-search#score_multiple_columns
SELECT AlbumId
FROM Albums
WHERE SEARCH(Title_Tokens, @p1) AND SEARCH(Studio_Tokens, @p2)
ORDER BY WITH(
TitleScore AS SCORE(Title_Tokens, @p1) * @titleweight,
StudioScore AS SCORE(Studio_Tokens, @p2) * @studioweight,
DaysOld AS (UNIX_MICROS(CURRENT_TIMESTAMP()) - ReleaseTimestamp) / 8.64e+10,
FreshnessBoost AS (1 + @freshnessweight * GREATEST(0, 30 - DaysOld) / 30),
PopularityBoost AS (1 + IF(HasGrammy, @grammyweight, 0)),
(TitleScore + StudioScore) * FreshnessBoost * PopularityBoost)
LIMIT 2
Loading

0 comments on commit d885fe3

Please sign in to comment.