Skip to content

Commit

Permalink
feat: Support TRUNCATE TABLE description (#144)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Mannion <125105+tekumara@users.noreply.github.com>
  • Loading branch information
DanCardin and tekumara authored Nov 9, 2024
1 parent ab48d05 commit 234bbaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fakesnow/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ def _execute(self, transformed: exp.Expression, params: Sequence[Any] | dict[Any
(affected_count,) = self._duck_conn.fetchall()[0]
result_sql = SQL_DELETED_ROWS.substitute(count=affected_count)

elif cmd == "TRUNCATETABLE":
result_sql = SQL_SUCCESS

elif cmd in ("DESCRIBE TABLE", "DESCRIBE VIEW"):
# DESCRIBE TABLE/VIEW has already been run above to detect and error if the table exists
# We now rerun DESCRIBE TABLE/VIEW but transformed with columns to match Snowflake
Expand Down
11 changes: 11 additions & 0 deletions tests/test_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,3 +1523,14 @@ def test_json_extract_cast_as_varchar(dcur: snowflake.connector.cursor.DictCurso

dcur.execute("SELECT j:str::number as j_str_number, j:num::number as j_num_number FROM example")
assert dcur.fetchall() == [{"J_STR_NUMBER": 100, "J_NUM_NUMBER": 200}]


def test_truncate(dcur: snowflake.connector.cursor.DictCursor):
dcur.execute("CREATE TABLE example (i INTEGER)")
dcur.execute("INSERT INTO example VALUES (1)")

dcur.execute("TRUNCATE TABLE example")
assert dcur.fetchall() == [{"status": "Statement executed successfully."}]

dcur.execute("SELECT i FROM example")
assert dcur.fetchall() == []

0 comments on commit 234bbaf

Please # to comment.