Skip to content

Commit

Permalink
fix: don't order object keys alphabetically
Browse files Browse the repository at this point in the history
to simplify the codebase
  • Loading branch information
tekumara committed Jun 19, 2023
1 parent 583790c commit cbef428
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
12 changes: 1 addition & 11 deletions fakesnow/fakes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations

import os
import re
import tempfile
from string import Template
from types import TracebackType
from typing import Any, Iterable, Iterator, Literal, Optional, Sequence, Type, Union, cast
Expand Down Expand Up @@ -487,15 +485,7 @@ def write_pandas(
table_type: Literal["", "temp", "temporary", "transient"] = "",
**kwargs: Any,
) -> WritePandasResult:
# write out to parquet and read back in, so that columns with dict values are written as structs, and
# their keys are sorted alphanumerically like snowflake
# TODO: a more performant way of ordering the dict keys, or maybe don't order
with tempfile.TemporaryDirectory() as tmp_folder:
tmp_path = os.path.join(tmp_folder, "file0.txt")
df.to_parquet(tmp_path, compression=compression, **kwargs)
df_converted = pd.read_parquet(tmp_path)

count = conn._insert_df(df_converted, table_name, database, schema) # noqa: SLF001
count = conn._insert_df(df, table_name, database, schema) # noqa: SLF001

# mocks https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html#output
mock_copy_results = [("fakesnow/file0.txt", "LOADED", count, count, 1, 0, None, None, None, None)]
Expand Down
5 changes: 3 additions & 2 deletions tests/test_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,6 @@ def test_write_pandas_dict_column_as_varchar(conn: snowflake.connector.Snowflake

cur.execute("select * from example")

# returned values are valid json strings, with keys in alphabetical order
assert cur.fetchall() == [("abc", '{"count":1,"kind":"vc"}', '{"amount":2,"kind":"obj"}')]
# returned values are valid json strings
# TODO: order object keys alphabetically like snowflake does
assert cur.fetchall() == [("abc", '{"kind":"vc","count":1}', '{"kind":"obj","amount":2}')]

0 comments on commit cbef428

Please sign in to comment.