Repository: tobymao/sqlglot

Issue:
[SNOWFLAKE] Use variables in sample function
**Before you file an issue**
- Make sure you specify the "read" dialect eg. parse_one(sql, read="spark") ✅ 
- Check if the issue still exists on main ✅ 

**Fully reproducible code snippet**
```python
from sqlglot import parse

query = """
set s = 50;
select
    user_id,
    value
from table_name
sample ($s) seed (0)
"""
parse(query, read='snowflake')
```
Code fragment above raises error:
```
Traceback (most recent call last):
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/__init__.py", line 87, in parse
    return dialect.parse(sql, **opts)
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/dialects/dialect.py", line 323, in parse
    return self.parser(**opts).parse(self.tokenize(sql), sql)
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 1007, in parse
    return self._parse(
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 1073, in _parse
    expressions.append(parse_method(self))
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 1263, in _parse_statement
    expression = self._parse_set_operations(expression) if expression else self._parse_select()
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 2241, in _parse_select
    from_ = self._parse_from()
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 2396, in _parse_from
    exp.From, comments=self._prev_comments, this=self._parse_table(joins=joins)
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 2763, in _parse_table
    table_sample = self._parse_table_sample()
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 2900, in _parse_table_sample
    self._match_r_paren()
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 5447, in _match_r_paren
    self.raise_error("Expecting )")
  File "/Project/.venv/lib/python3.8/site-packages/sqlglot/parser.py", line 1117, in raise_error
    raise error
sqlglot.errors.ParseError: Expecting ). Line 7, Col: 9.
  
set s = 50;
select
    user_id,
    value
from table_name
sample ($s) seed (0)
```

I check is that code is correct for snowflake and it worked, so i think it should be handled. 

PS: by the way, I wanted to write that I love sqlglot and this tool has helped me many times 😄 


Discussion:

Patch:
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 21c136bd..d2fcb7b8 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -605,6 +605,7 @@ class Parser(metaclass=_Parser):
         TokenType.NATIONAL_STRING: lambda self, token: self.expression(
             exp.National, this=token.text
         ),
+        TokenType.PARAMETER: lambda self, _: self._parse_parameter(),
         TokenType.RAW_STRING: lambda self, token: self.expression(exp.RawString, this=token.text),
         TokenType.HEREDOC_STRING: lambda self, token: self.expression(
             exp.RawString, this=token.text


Test patch:
diff --git a/tests/dialects/test_snowflake.py b/tests/dialects/test_snowflake.py
index 9ab0da8c..dc518438 100644
--- a/tests/dialects/test_snowflake.py
+++ b/tests/dialects/test_snowflake.py
@@ -13,6 +13,7 @@ class TestSnowflake(Validator):
         expr.selects[0].assert_is(exp.AggFunc)
         self.assertEqual(expr.sql(dialect="snowflake"), "SELECT APPROX_TOP_K(C4, 3, 5) FROM t")
 
+        self.validate_identity("SELECT user_id, value FROM table_name sample ($s) SEED (0)")
         self.validate_identity("SELECT ARRAY_UNIQUE_AGG(x)")
         self.validate_identity("SELECT OBJECT_CONSTRUCT()")
         self.validate_identity("SELECT DAYOFMONTH(CURRENT_TIMESTAMP())")