Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(snowflake): Support UUID type (#125642)

Tomás Farías Santana7de5b34762d0
diff --git a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
index 6ee45791735e..a28d8972ff7e 100644
--- a/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
+++ b/products/batch_exports/backend/temporal/destinations/snowflake_batch_export.py
@@ -17,7 +17,7 @@ import snowflake.connector
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from snowflake.connector.connection import SnowflakeConnection
-from snowflake.connector.constants import FIELD_ID_TO_NAME, QueryStatus
+from snowflake.connector.constants import QueryStatus
from snowflake.connector.cursor import ResultMetadata
from snowflake.connector.errorcode import ER_FAILED_TO_CONNECT_TO_DB, ER_RETRYABLE_CODE
from snowflake.connector.errors import HttpError, InterfaceError, OperationalError
@@ -25,6 +25,7 @@ from structlog.contextvars import bind_contextvars
from temporalio import activity, exceptions, workflow
from temporalio.common import RetryPolicy
+from posthog.dataclasses import frozen
from posthog.integrations import IntegrationManager, IntegrationNotFound
from posthog.models.integration import SnowflakeIntegration
from posthog.temporal.common.base import PostHogWorkflow
@@ -271,6 +272,7 @@ SnowflakeTypeName = typing.Literal[
"STRING",
"TEXT",
"BINARY",
+ "UUID",
# Semi-structured type
"VARIANT",
# The following are all aliases representing the same integer type
@@ -295,6 +297,7 @@ SnowflakeTypeName = typing.Literal[
"TIMESTAMP",
"TIMESTAMP_NTZ",
"TIMESTAMP_LTZ",
+ "TIMESTAMP_TZ",
"ARRAY",
]
@@ -306,6 +309,37 @@ class SnowflakeType(typing.NamedTuple):
scale: int | None = None
+@frozen
+class SnowflakeFieldDescriptor:
+ name: str
+ data_type: str
+ is_nullable: bool
+
+
+def _map_describe_table_to_descriptor(
+ row: collections.abc.Sequence[typing.Any] | collections.abc.Mapping[str, typing.Any],
+ metas: collections.abc.Sequence[ResultMetadata],
+) -> SnowflakeFieldDescriptor:
+ collect = {}
+
+ if isinstance(row, collections.abc.Mapping):
+ # Can happen with DictCursor, which we don't use at the moment.
+ it = zip((row[meta.name] for meta in metas), metas)
+ else:
+ it = zip(row, metas)
+
+ for field, meta in it:
+ match meta.name:
+ case "name":
+ collect["name"] = field
+ case "type":
+ collect["data_type"] = field
+ case "null?":
+ collect["is_nullable"] = field == "Y"
+
+ return SnowflakeFieldDescriptor(**collect)
+
+
SNOWFLAKE_MAX_NUMBER_PRECISION = 38
@@ -316,6 +350,28 @@ class SnowflakeDestinationField(typing.NamedTuple):
precision: int | None = None
scale: int | None = None
+ @classmethod
+ def from_field_descriptor(cls, fd: SnowflakeFieldDescriptor) -> typing.Self:
+ """Construct this field from the result of a Snowflake DESCRIBE query."""
+ type_name, _, parameters = fd.data_type.partition("(")
+ type_name = type_name.split(" COLLATE ", 1)[0].strip()
+
+ precision: int | None = None
+ scale: int | None = None
+
+ if type_name == "VARCHAR":
+ type_name = "TEXT"
+
+ elif type_name == "NUMBER":
+ precision, scale = (int(value) for value in parameters.split(")", 1)[0].split(","))
+ # Use FIXED to distinguish described NUMBER columns from explicit Arrow decimals.
+ type_name = "FIXED"
+
+ if type_name not in typing.get_args(SnowflakeTypeName):
+ raise ValueError(f"Unsupported type: '{fd.data_type}'")
+
+ return cls(fd.name, typing.cast(SnowflakeTypeName, type_name), fd.is_nullable, precision, scale)
+
def data_type_to_snowflake_type(data_type: pa.DataType) -> SnowflakeType:
"""Mapping of `pa.DataType` to corresponding `SnowflakeType`."""
@@ -331,6 +387,9 @@ def data_type_to_snowflake_type(data_type: pa.DataType) -> SnowflakeType:
elif pa.types.is_binary(data_type):
snowflake_type_name = "BINARY"
+ elif isinstance(data_type, pa.UuidType):
+ snowflake_type_name = "UUID"
+
elif pa.types.is_signed_integer(data_type) or pa.types.is_unsigned_integer(data_type):
# Snowflake's integer is weird: It supports all signed numbers with 38 digits:
# So the range is -10^38 + 1 to 10^38 - 1.
@@ -370,6 +429,8 @@ def snowflake_type_to_data_type(type: SnowflakeType) -> pa.DataType:
base_type: pa.DataType = pa.string()
case "BINARY":
base_type = pa.binary()
+ case "UUID":
+ base_type = pa.uuid()
case "INT" | "INTEGER" | "BIGINT" | "SMALLINT" | "TINYINT" | "BYTEINT" | "FIXED":
base_type = pa.int64()
case "BOOLEAN":
@@ -417,13 +478,11 @@ class SnowflakeField(Field):
# TODO: Maybe support more arrays?
snowflake_type = SnowflakeType(name="STRING", repeated=True)
elif field.type == "NUMBER" or (field.type == "FIXED" and field.scale):
- # Snowflake reports every 'NUMBER' column as 'FIXED'. A non-zero scale means
- # the column holds decimals, and reading it as 'INTEGER' would truncate them.
- # 'NUMBER' itself only comes from `to_destination_field`.
+ # Preserve explicit NUMBER fields as decimals even at scale zero.
+ # Nonzero-scale FIXED fields also need decimals to avoid truncating fractional values.
snowflake_type = SnowflakeType(name="NUMBER", repeated=False, precision=field.precision, scale=field.scale)
elif field.type == "FIXED":
- # This isn't documented as a type. I know it is 'INTEGER', not sure why the
- # snowflake library invented 'FIXED'.
+ # Treat zero-scale NUMBER columns discovered by DESCRIBE as integers.
snowflake_type = SnowflakeType(name="INTEGER", repeated=False)
else:
snowflake_type = SnowflakeType(name=field.type, repeated=False)
@@ -928,19 +987,18 @@ class SnowflakeClient:
from the table, or the fields we require have types we do not support.
"""
try:
- result = await self.execute_async_query(f"""
- SELECT * FROM "{table.name}" LIMIT 0
- """)
+ result = await self.execute_async_query(f"DESCRIBE TABLE {_quote_snowflake_identifier(table.name)}")
assert result is not None
- _, metadata = result
+ rows, description = result
except snowflake.connector.errors.ProgrammingError as e:
if "does not exist" in str(e):
raise SnowflakeTableNotFoundError(table.name)
else:
raise
+ field_descriptors = [_map_describe_table_to_descriptor(row, description) for row in rows]
if table.is_mutable():
- existing = {field_metadata.name.lower() for field_metadata in metadata}
+ existing = {fd.name.lower() for fd in field_descriptors}
missing_primary_key_fields = set(table.primary_key) - existing
if missing_primary_key_fields:
raise SnowflakeIncompatibleSchemaError(
@@ -963,15 +1021,9 @@ class SnowflakeClient:
record_batch_field_names = {field.name.lower() for field in table.fields}
fields = (
- SnowflakeDestinationField(
- field_metadata.name,
- FIELD_ID_TO_NAME[field_metadata.type_code], # type: ignore[arg-type]
- field_metadata.is_nullable,
- field_metadata.precision,
- field_metadata.scale,
- )
- for field_metadata in metadata
- if field_metadata.name.lower() in record_batch_field_names
+ SnowflakeDestinationField.from_field_descriptor(fd)
+ for fd in field_descriptors
+ if fd.name.lower() in record_batch_field_names
)
try:
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
index 013be2ec6513..338150008d2f 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client.py
@@ -8,6 +8,7 @@ import os
import uuid
import asyncio
import datetime as dt
+from collections.abc import AsyncIterator
import pytest
@@ -26,6 +27,11 @@ from products.batch_exports.backend.temporal.destinations.snowflake_batch_export
SnowflakeType,
SnowflakeWarehouseUsageError,
)
+from products.batch_exports.backend.temporal.pipeline.transformer import (
+ ParquetStreamTransformer,
+ PipelineTransformer,
+ SchemaTransformer,
+)
from products.batch_exports.backend.tests.temporal.destinations.snowflake.utils import SKIP_IF_MISSING_REQUIRED_ENV_VARS
pytestmark = [
@@ -158,6 +164,7 @@ async def test_table(snowflake_client, database, schema, table_name):
SnowflakeField("id", SnowflakeType("INTEGER", False), pa.int64(), True),
SnowflakeField("text", SnowflakeType("TEXT", False), pa.string(), True),
SnowflakeField("amount", SnowflakeType("NUMBER", False, 38, 2), pa.decimal128(38, 2), True),
+ SnowflakeField.from_arrow_field(pa.field("native_uuid", pa.uuid())),
),
parents=(database, schema),
)
@@ -295,9 +302,29 @@ async def test_copy_loaded_files_to_snowflake_table_only_works_on_stage_prefix(
text = ["Flamingo", "Parrot", "Dog", "Horse", "Brittle stars", "Centipede"]
n_legs = pa.array(ids)
animals = pa.array(text)
- table = pa.Table.from_arrays([n_legs, animals], names=["id", "text"])
+ uuid_values = [
+ "00112233-4455-4677-8899-aabbccddeeff",
+ None,
+ "ffffffff-ffff-ffff-ffff-ffffffffffff",
+ "00000000-0000-0000-0000-000000000000",
+ "01900000-1234-7abc-8def-0123456789ab",
+ "00112233-4455-4677-8899-aabbccddeeff",
+ ]
+ uuids = pa.array([uuid.UUID(value).bytes if value is not None else None for value in uuid_values], type=pa.uuid())
+ table = pa.Table.from_arrays([n_legs, animals, uuids], names=["id", "text", "native_uuid"])
+
+ async def record_batches() -> AsyncIterator[pa.RecordBatch]:
+ for batch in table.to_batches(max_chunksize=2):
+ yield batch
+
+ destination = await snowflake_client.get_table(test_table)
+ assert destination["native_uuid"].data_type == pa.uuid()
+ transformer = PipelineTransformer(
+ transformers=(SchemaTransformer(table=destination), ParquetStreamTransformer(compression="zstd"))
+ )
file_like = NamedBytesIO(b"", name="test_file")
- pq.write_table(table, file_like)
+ async for chunk in transformer.iter(record_batches()):
+ file_like.write(chunk.data)
file_like.seek(0)
await snowflake_client.put_file_to_snowflake_table_stage(file_like, test_table)
@@ -327,6 +354,9 @@ async def test_copy_loaded_files_to_snowflake_table_only_works_on_stage_prefix(
assert sorted(data["id"]) == sorted(ids)
assert sorted(data["text"]) == sorted(text)
+ uuid_column = next(index for index, field in enumerate(metadata) if field.name == "native_uuid")
+ text_column = next(index for index, field in enumerate(metadata) if field.name == "text")
+ assert {row[text_column]: row[uuid_column] for row in rows} == dict(zip(text, uuid_values))
# Check that first prefix file should still be there
result = await snowflake_client.execute_async_query(
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client_schema.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client_schema.py
new file mode 100644
index 000000000000..b91e879ab0dd
--- /dev/null
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_client_schema.py
@@ -0,0 +1,108 @@
+from collections.abc import AsyncIterator
+
+import pytest
+from unittest.mock import AsyncMock, patch
+
+import pyarrow as pa
+import pyarrow.parquet as pq
+
+from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
+ SnowflakeClient,
+ SnowflakeIncompatibleSchemaError,
+ SnowflakeTable,
+)
+from products.batch_exports.backend.temporal.pipeline.transformer import ParquetStreamTransformer, SchemaTransformer
+from products.batch_exports.backend.tests.temporal.destinations.snowflake.utils import DESCRIBE_TABLE_METADATA
+
+
+def client() -> SnowflakeClient:
+ return SnowflakeClient(
+ user="test_user",
+ account="test_account",
+ warehouse="test_warehouse",
+ database="test_db",
+ schema="public",
+ password="test_password",
+ )
+
+
[email protected]("missing_key", [None, "id", "version"])
[email protected]("as_mapping", [False, True])
+async def test_get_table_validates_keys_and_filters_columns(
+ client: SnowflakeClient, missing_key: str | None, as_mapping: bool
+) -> None:
+ table = SnowflakeTable.from_arrow_schema(
+ pa.schema([pa.field("id", pa.int64()), pa.field("version", pa.int64()), pa.field("missing", pa.string())]), # type: ignore[arg-type]
+ name='test"table',
+ table_schema="public",
+ database="test_db",
+ primary_key=("id",),
+ version_key=("version",),
+ )
+ rows = [
+ ("ID", "NUMBER(38,0)", "COLUMN", "N"),
+ ("VERSION", "NUMBER(38,0)", "COLUMN", "Y"),
+ ("extra", "GEOGRAPHY", "COLUMN", "Y"),
+ ]
+ rows = [row for row in rows if row[0].lower() != missing_key]
+ result_rows = (
+ [{meta.name: value for meta, value in reversed(list(zip(DESCRIBE_TABLE_METADATA, row)))} for row in rows]
+ if as_mapping
+ else rows
+ )
+ with patch.object(
+ client, "execute_async_query", new=AsyncMock(return_value=(result_rows, DESCRIBE_TABLE_METADATA))
+ ) as execute:
+ if missing_key is not None:
+ with pytest.raises(SnowflakeIncompatibleSchemaError, match=f"'{missing_key}'"):
+ await client.get_table(table)
+ else:
+ result = await client.get_table(table)
+ assert [field.name for field in result.fields] == ["ID", "VERSION"]
+ assert result["id"].data_type == pa.int64()
+ assert result["id"].nullable is False
+ assert result["version"].data_type == pa.int64()
+ assert result["version"].nullable is True
+ execute.assert_awaited_once_with('DESCRIBE TABLE "test""table"')
+
+
[email protected]("destination_type", ["UUID", "VARCHAR(16777216)"])
+async def test_get_table_distinguishes_uuid_from_text_and_preserves_uuid_buffers(
+ client: SnowflakeClient, destination_type: str
+) -> None:
+ batch = pa.record_batch(
+ [pa.array([bytes.fromhex("00112233445546778899aabbccddeeff"), None], type=pa.uuid())],
+ names=["Id"],
+ )
+ table = SnowflakeTable.from_arrow_schema(
+ batch.schema, name="test_table", table_schema="public", database="test_db", primary_key=(), version_key=()
+ )
+ with patch.object(
+ client,
+ "execute_async_query",
+ new=AsyncMock(return_value=([("Id", destination_type, "COLUMN", "Y")], DESCRIBE_TABLE_METADATA)),
+ ) as execute:
+ result = await client.get_table(table)
+ execute.assert_awaited_once_with('DESCRIBE TABLE "test_table"')
+
+ expected_type = pa.uuid() if destination_type == "UUID" else pa.string()
+ assert result["Id"].data_type == expected_type
+ assert result["Id"].snowflake_type_name == ("UUID" if destination_type == "UUID" else "TEXT")
+ transformed = SchemaTransformer(table=result).cast_record_batch(batch)
+ assert transformed.equals(batch)
+ source_buffer = batch.column(0).buffers()[1]
+ result_buffer = transformed.column(0).buffers()[1]
+ assert source_buffer is not None
+ assert result_buffer is not None
+ assert result_buffer.address == source_buffer.address
+
+ async def record_batches() -> AsyncIterator[pa.RecordBatch]:
+ yield transformed
+
+ chunks = [chunk.data async for chunk in ParquetStreamTransformer(compression="zstd").iter(record_batches())]
+ parquet = pq.ParquetFile(pa.BufferReader(b"".join(chunks)))
+ assert parquet.schema.column(0).logical_type.type == "UUID"
+ assert parquet.read().equals(pa.Table.from_batches([batch]))
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_field.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_field.py
index da3068ddda4b..f7672adc3e4a 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_field.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_field.py
@@ -1,15 +1,65 @@
+import pytest
+
import pyarrow as pa
from products.batch_exports.backend.temporal.destinations.snowflake_batch_export import (
SnowflakeDestinationField,
SnowflakeField,
+ SnowflakeFieldDescriptor,
)
+from products.batch_exports.backend.temporal.utils import JsonType
-def test_decimal_field_maps_to_number_and_reads_back_as_decimal() -> None:
- field = SnowflakeField.from_arrow_field(pa.field("amount", pa.decimal128(38, 2)))
+ "data_type,ddl,destination_field,description",
+ [
+ # Snowflake reports a 'NUMBER(38, 2)' column as 'FIXED' with precision 38 and scale 2.
+ (
+ pa.decimal128(38, 2),
+ "NUMBER(38, 2)",
+ SnowflakeDestinationField("value", "FIXED", True, 38, 2),
+ "NUMBER(38,2)",
+ ),
+ (pa.int64(), "INTEGER", SnowflakeDestinationField("value", "FIXED", False, 38, 0), "NUMBER(38,0)"),
+ (pa.uuid(), "UUID", SnowflakeDestinationField("value", "UUID", True), "UUID"),
+ (pa.binary(), "BINARY", SnowflakeDestinationField("value", "BINARY", False), "BINARY(8388608)"),
+ (pa.string(), "STRING", SnowflakeDestinationField("value", "TEXT", True), "VARCHAR(16777216) COLLATE 'en-ci'"),
+ (pa.float64(), "FLOAT", SnowflakeDestinationField("value", "FLOAT", True), "FLOAT"),
+ (pa.bool_(), "BOOLEAN", SnowflakeDestinationField("value", "BOOLEAN", False), "BOOLEAN"),
+ (pa.date32(), "DATE", SnowflakeDestinationField("value", "DATE", True), "DATE"),
+ (
+ pa.timestamp("ms", tz="UTC"),
+ "TIMESTAMP",
+ SnowflakeDestinationField("value", "TIMESTAMP_NTZ", True),
+ "TIMESTAMP_NTZ(9)",
+ ),
+ (
+ pa.timestamp("ms", tz="UTC"),
+ "TIMESTAMP",
+ SnowflakeDestinationField("value", "TIMESTAMP_LTZ", True),
+ "TIMESTAMP_LTZ(9)",
+ ),
+ (
+ pa.timestamp("ms", tz="UTC"),
+ "TIMESTAMP",
+ SnowflakeDestinationField("value", "TIMESTAMP_TZ", True),
+ "TIMESTAMP_TZ(9)",
+ ),
+ (pa.list_(pa.string()), "ARRAY", SnowflakeDestinationField("value", "ARRAY", True), "ARRAY"),
+ (JsonType(), "VARIANT", SnowflakeDestinationField("value", "VARIANT", True), "VARIANT"),
+ ],
+)
+def test_field_maps_to_snowflake_type_and_reads_back(
+ data_type: pa.DataType, ddl: str, destination_field: SnowflakeDestinationField, description: str
+) -> None:
+ field = SnowflakeField.from_arrow_field(pa.field("value", data_type, nullable=destination_field.is_nullable))
- assert field.snowflake_type_ddl == "NUMBER(38, 2)"
- # Snowflake reports a 'NUMBER(38, 2)' column as 'FIXED' with precision 38 and scale 2.
- assert SnowflakeField.from_destination_field(SnowflakeDestinationField("amount", "FIXED", True, 38, 2)) == field
+ assert field.snowflake_type_ddl == ddl
+ parsed = SnowflakeDestinationField.from_field_descriptor(
+ SnowflakeFieldDescriptor(name="value", data_type=description, is_nullable=destination_field.is_nullable)
+ )
+ assert parsed == destination_field
+ restored = SnowflakeField.from_destination_field(parsed)
+ assert restored == field
+ assert restored.nullable == field.nullable
assert SnowflakeField.from_destination_field(field.to_destination_field()) == field
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
index 3209826fa5e6..614d87d283ad 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/test_workflow.py
@@ -179,12 +179,12 @@ async def test_snowflake_export_workflow_exports_events(
assert all(query.startswith("PUT") for query in execute_calls[0:9])
- assert execute_async_calls[5].startswith(f'SELECT * FROM "{table_name}" LIMIT 0')
+ assert execute_async_calls[5].startswith(f'DESCRIBE TABLE "{table_name}"')
assert execute_async_calls[6].startswith(
f"""REMOVE '@%"{table_name}"/{snowflake_batch_export.id}/{data_interval_end_str}'"""
)
assert execute_async_calls[7].startswith(f'CREATE TABLE IF NOT EXISTS "{table_name}"')
- assert execute_async_calls[8].startswith(f'SELECT * FROM "{table_name}" LIMIT 0')
+ assert execute_async_calls[8].startswith(f'DESCRIBE TABLE "{table_name}"')
assert execute_async_calls[9].startswith(f'COPY INTO "{table_name}"')
assert execute_async_calls[10].startswith(
f"""REMOVE '@%"{table_name}"/{snowflake_batch_export.id}/{data_interval_end_str}'"""
diff --git a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
index 7379e502f195..4f67639a634f 100644
--- a/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
+++ b/products/batch_exports/backend/tests/temporal/destinations/snowflake/utils.py
@@ -15,6 +15,7 @@ import pytest
import responses
import snowflake.connector
from requests.models import PreparedRequest
+from snowflake.connector.cursor import ResultMetadata
from posthog.temporal.common.clickhouse import ClickHouseClient
@@ -104,29 +105,44 @@ class FakeMetadata(typing.NamedTuple):
scale: int | None = None
+DESCRIBE_TABLE_METADATA = [
+ ResultMetadata(
+ name=name,
+ type_code=2,
+ display_size=None,
+ internal_size=None,
+ precision=None,
+ scale=None,
+ is_nullable=True,
+ )
+ for name in ("name", "type", "kind", "null?")
+]
+
+
class FakeSnowflakeCursor:
"""A fake Snowflake cursor that can fail on PUT and COPY queries."""
- def __init__(self, *args, failure_mode: str | None = None, **kwargs):
+ def __init__(self, *args, queries: dict[str, str], failure_mode: str | None = None, **kwargs):
self._execute_calls: list[dict[str, t.Any]] = []
self._execute_async_calls: list[dict[str, t.Any]] = []
- self._sfqid = 1
+ self._sfqid = str(uuid4())
+ self._queries = queries
+ self._query = ""
self._fail = failure_mode
@property
def sfqid(self):
- current = self._sfqid
- self._sfqid += 1
- return current
+ return self._sfqid
def execute(self, query, params=None, file_stream=None):
self._execute_calls.append({"query": query, "params": params, "file_stream": file_stream})
def execute_async(self, query, params=None, file_stream=None):
self._execute_async_calls.append({"query": query, "params": params, "file_stream": file_stream})
+ self._queries[self.sfqid] = query
def get_results_from_sfqid(self, query_id):
- pass
+ self._query = self._queries[query_id]
def __enter__(self):
return self
@@ -159,6 +175,8 @@ class FakeSnowflakeCursor:
)
def fetchall(self):
+ if self._query.strip().startswith("DESCRIBE TABLE"):
+ return [("uuid", "VARCHAR(16777216)", "COLUMN", "N")]
if self._fail == "copy":
return [("test", "LOAD FAILED", 100, 99, 1, 1, "Some error on copy", 3)]
else:
@@ -166,6 +184,8 @@ class FakeSnowflakeCursor:
@property
def description(self):
+ if self._query.strip().startswith("DESCRIBE TABLE"):
+ return DESCRIBE_TABLE_METADATA
return [FakeMetadata("uuid", 2, False)]
@@ -177,11 +197,12 @@ class FakeSnowflakeConnection:
**kwargs,
):
self._cursors: list[FakeSnowflakeCursor] = []
+ self._queries: dict[str, str] = {}
self._is_running = True
self.failure_mode = failure_mode
def cursor(self) -> FakeSnowflakeCursor:
- cursor = FakeSnowflakeCursor(failure_mode=self.failure_mode)
+ cursor = FakeSnowflakeCursor(queries=self._queries, failure_mode=self.failure_mode)
self._cursors.append(cursor)
return cursor