Skip to content

Commit

Permalink
rm duplicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkinulas committed Apr 5, 2024
1 parent 3559816 commit 1d1101e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 141 deletions.
2 changes: 1 addition & 1 deletion fakesnow/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _execute(
.transform(transforms.timestamp_ntz_ns)
.transform(transforms.float_to_double)
.transform(transforms.integer_precision)
# TODO(selman): Broken, fails on CTAS queries with CASTs;
# TODO(selman): Broken, fails on CTAS queries with CASTs;
# CREATE TABLE SOME_TABLE AS (
# SELECT
# R1 AS C1,
Expand Down
141 changes: 1 addition & 140 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
json_extract_eq_string_literal,
json_extract_in_string_literals,
json_extract_precedence,
object_agg,
object_construct,
random,
regex_replace,
Expand All @@ -52,7 +53,6 @@
try_to_decimal,
upper_case_unquoted_identifiers,
values_columns,
object_agg,
)


Expand Down Expand Up @@ -831,145 +831,6 @@ def test_trim_cast_varchar() -> None:
== "SELECT TRIM(CAST(col AS TEXT)) FROM table1"
)


def test__get_to_number_args() -> None:
e = sqlglot.parse_one("to_number('100')", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (None, None, None)

e = sqlglot.parse_one("to_number('100', 10)", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (None, exp.Literal(this="10", is_string=False), None)

e = sqlglot.parse_one("to_number('100', 10,2)", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (
None,
exp.Literal(this="10", is_string=False),
exp.Literal(this="2", is_string=False),
)

e = sqlglot.parse_one("to_number('100', 'TM9')", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (exp.Literal(this="TM9", is_string=True), None, None)

e = sqlglot.parse_one("to_number('100', 'TM9', 10)", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (
exp.Literal(this="TM9", is_string=True),
exp.Literal(this="10", is_string=False),
None,
)

e = sqlglot.parse_one("to_number('100', 'TM9', 10, 2)", read="snowflake")
assert isinstance(e, exp.ToNumber)
assert _get_to_number_args(e) == (
exp.Literal(this="TM9", is_string=True),
exp.Literal(this="10", is_string=False),
exp.Literal(this="2", is_string=False),
)


def test_to_number() -> None:
assert (
sqlglot.parse_one("SELECT to_number('100')", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(38, 0))"
)

assert (
sqlglot.parse_one("SELECT to_number('100', 10)", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 0))"
)

assert (
sqlglot.parse_one("SELECT to_number('100', 10,2)", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 2))"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_number('100', 'TM9')", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_number('100', 'TM9', 10)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_number('100', 'TM9', 10, 2)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)


def test_to_number_decimal() -> None:
assert (
sqlglot.parse_one("SELECT to_decimal('100')", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(38, 0))"
)

assert (
sqlglot.parse_one("SELECT to_decimal('100', 10)", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 0))"
)

assert (
sqlglot.parse_one("SELECT to_decimal('100', 10,2)", read="snowflake")
.transform(to_decimal)
.sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 2))"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_decimal('100', 'TM9')", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_decimal('100', 'TM9', 10)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_decimal('100', 'TM9', 10, 2)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)


def test_to_number_numeric() -> None:
assert (
sqlglot.parse_one("SELECT to_numeric('100')", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(38, 0))"
)

assert (
sqlglot.parse_one("SELECT to_numeric('100', 10)", read="snowflake").transform(to_decimal).sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 0))"
)

assert (
sqlglot.parse_one("SELECT to_numeric('100', 10,2)", read="snowflake")
.transform(to_decimal)
.sql(dialect="duckdb")
== "SELECT CAST('100' AS DECIMAL(10, 2))"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_numeric('100', 'TM9')", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_numeric('100', 'TM9', 10)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)

with pytest.raises(NotImplementedError):
sqlglot.parse_one("SELECT to_numeric('100', 'TM9', 10, 2)", read="snowflake").transform(to_decimal).sql(
dialect="duckdb"
)


def test_upper_case_unquoted_identifiers() -> None:
assert (
sqlglot.parse_one("select name, name as fname from table1").transform(upper_case_unquoted_identifiers).sql()
Expand Down

0 comments on commit 1d1101e

Please sign in to comment.