Skip to content

Commit

Permalink
Fix: bigquery table with hyphen number
Browse files Browse the repository at this point in the history
  • Loading branch information
tobymao committed Jun 9, 2023
1 parent c6a540c commit 824fcb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sqlglot/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,12 @@ def _advance(self, i: int = 1, alnum: bool = False) -> None:
def _text(self) -> str:
return self.sql[self._start : self._current]

def peek(self, i: int = 0) -> str:
i = self._current + i
if i < self.size:
return self.sql[i]
return ""

def _add(self, token_type: TokenType, text: t.Optional[str] = None) -> None:
self._prev_token_line = self._line
self.tokens.append(
Expand Down Expand Up @@ -987,8 +993,12 @@ def _scan_number(self) -> None:
if self._peek.isdigit():
self._advance()
elif self._peek == "." and not decimal:
decimal = True
self._advance()
after = self.peek(1)
if after.isdigit() or not after.strip():
decimal = True
self._advance()
else:
return self._add(TokenType.VAR)
elif self._peek in ("-", "+") and scientific == 1:
scientific += 1
self._advance()
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class TestBigQuery(Validator):
dialect = "bigquery"

def test_bigquery(self):
self.validate_identity("SELECT * FROM x-0.a")
self.validate_identity("SELECT * FROM pivot CROSS JOIN foo")
self.validate_identity("SAFE_CAST(x AS STRING)")
self.validate_identity("SELECT * FROM a-b-c.mydataset.mytable")
Expand Down
3 changes: 3 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,6 @@ def test_parse_properties(self):
self.assertEqual(
parse_one("create materialized table x").sql(), "CREATE MATERIALIZED TABLE x"
)

def test_parse_floats(self):
self.assertTrue(parse_one("1. ").is_number)

0 comments on commit 824fcb2

Please sign in to comment.