snowflake-connector-python 5.2.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. snowflake/connector/__init__.py +148 -0
  2. snowflake/connector/_common/__init__.py +0 -0
  3. snowflake/connector/_common/extras.py +134 -0
  4. snowflake/connector/_common/telemetry.py +221 -0
  5. snowflake/connector/_common/wif_util.py +92 -0
  6. snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
  7. snowflake/connector/_core/sf_core_python.pyi +79 -0
  8. snowflake/connector/_internal/__init__.py +6 -0
  9. snowflake/connector/_internal/_private_key_helper.py +31 -0
  10. snowflake/connector/_internal/api_client/__init__.py +93 -0
  11. snowflake/connector/_internal/api_client/bridge.py +41 -0
  12. snowflake/connector/_internal/api_client/client_api.py +976 -0
  13. snowflake/connector/_internal/arrow.py +47 -0
  14. snowflake/connector/_internal/arrow_context.py +240 -0
  15. snowflake/connector/_internal/arrow_stream_async.py +266 -0
  16. snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
  17. snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
  18. snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
  19. snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
  20. snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
  21. snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
  22. snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
  23. snowflake/connector/_internal/arrow_stream_utils.py +171 -0
  24. snowflake/connector/_internal/authenticator_type.py +53 -0
  25. snowflake/connector/_internal/backward_compatibility.py +245 -0
  26. snowflake/connector/_internal/binding_converters.py +741 -0
  27. snowflake/connector/_internal/config_utils.py +71 -0
  28. snowflake/connector/_internal/connection/__init__.py +39 -0
  29. snowflake/connector/_internal/connection/connection.py +616 -0
  30. snowflake/connector/_internal/connection/connection_types.py +13 -0
  31. snowflake/connector/_internal/connection/constants.py +25 -0
  32. snowflake/connector/_internal/connection/decorators.py +31 -0
  33. snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
  34. snowflake/connector/_internal/connection/queries.py +10 -0
  35. snowflake/connector/_internal/connection_config_mixin.py +755 -0
  36. snowflake/connector/_internal/cursor/__init__.py +25 -0
  37. snowflake/connector/_internal/cursor/base.py +732 -0
  38. snowflake/connector/_internal/cursor/cursor_types.py +13 -0
  39. snowflake/connector/_internal/cursor/decorators.py +56 -0
  40. snowflake/connector/_internal/cursor/query_result.py +202 -0
  41. snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
  42. snowflake/connector/_internal/cursor/result_metadata.py +255 -0
  43. snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
  44. snowflake/connector/_internal/decorators.py +539 -0
  45. snowflake/connector/_internal/error_kinds.py +111 -0
  46. snowflake/connector/_internal/errorcode.py +35 -0
  47. snowflake/connector/_internal/errorhandler.py +278 -0
  48. snowflake/connector/_internal/fips.py +28 -0
  49. snowflake/connector/_internal/logging/__init__.py +52 -0
  50. snowflake/connector/_internal/logging/config.py +134 -0
  51. snowflake/connector/_internal/logging/core_logger.py +218 -0
  52. snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
  53. snowflake/connector/_internal/logout_config_mapping.py +187 -0
  54. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
  55. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  56. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
  57. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
  58. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
  59. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  60. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  61. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  62. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
  63. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
  64. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
  65. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
  66. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
  67. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
  68. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
  69. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
  70. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
  71. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  72. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
  73. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  74. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
  75. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
  76. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
  77. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  78. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
  79. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  80. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  81. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  82. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
  83. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
  84. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
  85. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  86. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
  87. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  88. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
  89. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  90. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  91. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
  92. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
  93. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
  94. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
  95. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  96. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
  97. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  98. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
  99. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  100. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
  101. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
  102. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  103. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  104. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  105. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
  106. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
  107. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
  108. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
  109. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  110. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
  111. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
  112. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
  113. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  114. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
  115. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
  116. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  117. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  118. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  119. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
  120. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
  121. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
  122. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  123. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
  124. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
  125. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
  126. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  127. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  128. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
  129. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
  130. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  131. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  132. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  133. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  134. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  135. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
  136. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
  137. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
  138. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  139. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  140. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
  141. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
  142. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
  143. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
  144. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
  145. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
  146. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
  147. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
  148. snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
  149. snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
  150. snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
  151. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
  152. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
  153. snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
  154. snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
  155. snowflake/connector/_internal/result_batch.py +150 -0
  156. snowflake/connector/_internal/snowflake_restful.py +222 -0
  157. snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
  158. snowflake/connector/_internal/sqlstate.py +11 -0
  159. snowflake/connector/_internal/statement_utils.py +207 -0
  160. snowflake/connector/_internal/text_utils.py +112 -0
  161. snowflake/connector/_internal/type_codes.py +139 -0
  162. snowflake/connector/_internal/utils.py +65 -0
  163. snowflake/connector/_internal/write_pandas_operation.py +657 -0
  164. snowflake/connector/aio/README.md +168 -0
  165. snowflake/connector/aio/__init__.py +37 -0
  166. snowflake/connector/aio/connection/__init__.py +17 -0
  167. snowflake/connector/aio/connection/_connection.py +506 -0
  168. snowflake/connector/aio/cursor/__init__.py +35 -0
  169. snowflake/connector/aio/cursor/_base.py +1034 -0
  170. snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
  171. snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
  172. snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
  173. snowflake/connector/aio/pandas_tools.py +279 -0
  174. snowflake/connector/aio/result_batch.py +165 -0
  175. snowflake/connector/auth/__init__.py +0 -0
  176. snowflake/connector/auth/workload_identity.py +5 -0
  177. snowflake/connector/compat.py +22 -0
  178. snowflake/connector/config_manager.py +392 -0
  179. snowflake/connector/connection/__init__.py +30 -0
  180. snowflake/connector/connection/_connection.py +641 -0
  181. snowflake/connector/connection_config.py +517 -0
  182. snowflake/connector/constants.py +52 -0
  183. snowflake/connector/cursor/__init__.py +37 -0
  184. snowflake/connector/cursor/_base.py +1169 -0
  185. snowflake/connector/cursor/_chunked_download_reader.py +75 -0
  186. snowflake/connector/cursor/_dict_cursor.py +78 -0
  187. snowflake/connector/cursor/_result_set_wrapper.py +35 -0
  188. snowflake/connector/cursor/_snowflake_cursor.py +72 -0
  189. snowflake/connector/description.py +7 -0
  190. snowflake/connector/errors.py +492 -0
  191. snowflake/connector/network.py +71 -0
  192. snowflake/connector/pandas_tools.py +191 -0
  193. snowflake/connector/py.typed +0 -0
  194. snowflake/connector/result_batch.py +216 -0
  195. snowflake/connector/telemetry.py +40 -0
  196. snowflake/connector/time_util.py +11 -0
  197. snowflake/connector/types.py +134 -0
  198. snowflake/connector/util_text.py +3 -0
  199. snowflake/connector/version.py +23 -0
  200. snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
  201. snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
  202. snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
  203. snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
  204. snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,112 @@
1
+ from __future__ import annotations
2
+
3
+ import re
4
+
5
+ from collections.abc import Iterator
6
+ from io import StringIO
7
+
8
+ from snowflake.connector._core import sf_core_python
9
+
10
+
11
+ _VALUES_CLAUSE_RE = re.compile(r"\bVALUES\s*\(", re.IGNORECASE)
12
+
13
+ # Matches only the tokens that affect parser state. Two-char tokens are
14
+ # listed first so the alternation is greedy and consumes them whole:
15
+ # $$ — dollar-quote delimiter
16
+ # '' — escaped single-quote inside a single-quoted string
17
+ # "" — escaped double-quote inside a double-quoted string
18
+ # ( ) ' " — individual state-change characters
19
+ # Everything between tokens is skipped at C speed by the regex engine,
20
+ # avoiding a Python-level loop over every character.
21
+ _SQL_TOKENS_RE = re.compile(r"\$\$|''|\"\"|[()'\"]")
22
+
23
+
24
+ def extract_values_clause(sql: str) -> str | None:
25
+ """Extract the VALUES clause from an INSERT SQL statement.
26
+
27
+ Uses a balanced-parentheses parser rather than a greedy regex so that
28
+ nested function calls (e.g. ``PARSE_JSON(%(col)s)``) and string literals
29
+ that contain parentheses are handled correctly.
30
+
31
+ Examples that a greedy regex gets wrong but this function handles:
32
+
33
+ * ``INSERT INTO t (raw) (SELECT PARSE_JSON(c) as raw FROM VALUES (%(raw)s))``
34
+ → returns ``(%(raw)s)`` (greedy regex returns ``(%(raw)s))``)
35
+ * ``INSERT INTO t (col) VALUES (PARSE_JSON(%(col)s))``
36
+ → returns ``(PARSE_JSON(%(col)s))``
37
+
38
+ Returns:
39
+ The VALUES clause including its outer parentheses, e.g. ``(%(col)s)``,
40
+ or ``None`` when no balanced VALUES clause can be found.
41
+ """
42
+ m = _VALUES_CLAUSE_RE.search(sql)
43
+ if not m:
44
+ return None
45
+
46
+ start = m.end() - 1 # position of the opening '('
47
+ depth = 0
48
+ in_single_quote = False
49
+ in_double_quote = False
50
+ in_dollar_quote = False
51
+
52
+ for tok in _SQL_TOKENS_RE.finditer(sql, start):
53
+ t = tok.group()
54
+
55
+ if in_dollar_quote:
56
+ if t == "$$":
57
+ in_dollar_quote = False
58
+ elif in_single_quote:
59
+ if t == "'":
60
+ in_single_quote = False
61
+ # t == "''" → escaped quote, stay in string (fall through, do nothing)
62
+ elif in_double_quote:
63
+ if t == '"':
64
+ in_double_quote = False
65
+ # t == '""' → escaped quote, stay in string (fall through, do nothing)
66
+ else:
67
+ if t == "(":
68
+ depth += 1
69
+ elif t == ")":
70
+ depth -= 1
71
+ if depth == 0:
72
+ return sql[start : tok.end()]
73
+ elif t == "'":
74
+ in_single_quote = True
75
+ elif t == '"':
76
+ in_double_quote = True
77
+ elif t == "$$":
78
+ in_dollar_quote = True
79
+
80
+ return None # unbalanced or no VALUES clause found
81
+
82
+
83
+ class SQLDelimiter:
84
+ """Delimiter read from ``sql_delimiter`` when :func:`split_statements` is called."""
85
+
86
+ def __str__(self) -> str:
87
+ return self.sql_delimiter
88
+
89
+ def __init__(self, sql_delimiter: str = ";") -> None:
90
+ self.sql_delimiter = sql_delimiter
91
+
92
+
93
+ def split_statements(
94
+ buf: StringIO,
95
+ remove_comments: bool = False,
96
+ delimiter: SQLDelimiter | None = None,
97
+ ) -> Iterator[tuple[str, bool | None]]:
98
+ """Yield SQL statements and ``!`` commands from ``buf``.
99
+
100
+ A delimiter inside a quote, ``$$`` body, or comment does not end a statement.
101
+ An unterminated quote, block comment, or dollar quote stays open through the
102
+ rest of the script. Each statement's delimiter is rewritten as ``;``. The
103
+ second item is ``True`` for ``PUT`` and ``GET``, ``False`` for other
104
+ statements and commands, and ``None`` when the text is empty or comment-only.
105
+ """
106
+ if delimiter is None:
107
+ delimiter = SQLDelimiter()
108
+ yield from sf_core_python.split_sql_script(
109
+ buf.read(),
110
+ delimiter.sql_delimiter,
111
+ remove_comments,
112
+ )
@@ -0,0 +1,139 @@
1
+ """
2
+ Type code mappings for Snowflake data types to PEP 249 DB API 2.0.
3
+
4
+ Maps Snowflake type names to integer type codes for cursor.description.
5
+ """
6
+
7
+ # Type code constants for PEP 249 compliance
8
+ # These match the indices from snowflake-connector-python for compatibility
9
+ FIXED = 0
10
+ REAL = 1
11
+ TEXT = 2
12
+ DATE = 3
13
+ TIMESTAMP = 4
14
+ VARIANT = 5
15
+ TIMESTAMP_LTZ = 6
16
+ TIMESTAMP_TZ = 7
17
+ TIMESTAMP_NTZ = 8
18
+ OBJECT = 9
19
+ ARRAY = 10
20
+ BINARY = 11
21
+ TIME = 12
22
+ BOOLEAN = 13
23
+ GEOGRAPHY = 14
24
+ GEOMETRY = 15
25
+ VECTOR = 16
26
+ MAP = 17
27
+ FILE = 18
28
+ INTERVAL_YEAR_MONTH = 19
29
+ INTERVAL_DAY_TIME = 20
30
+
31
+ # Mapping from Snowflake type name to type code
32
+ SNOWFLAKE_TYPE_TO_CODE = {
33
+ "FIXED": FIXED,
34
+ "NUMBER": FIXED,
35
+ "DECIMAL": FIXED,
36
+ "NUMERIC": FIXED,
37
+ "INT": FIXED,
38
+ "INTEGER": FIXED,
39
+ "BIGINT": FIXED,
40
+ "SMALLINT": FIXED,
41
+ "TINYINT": FIXED,
42
+ "BYTEINT": FIXED,
43
+ "DECFLOAT": FIXED,
44
+ "REAL": REAL,
45
+ "FLOAT": REAL,
46
+ "FLOAT4": REAL,
47
+ "FLOAT8": REAL,
48
+ "DOUBLE": REAL,
49
+ "DOUBLE PRECISION": REAL,
50
+ "TEXT": TEXT,
51
+ "VARCHAR": TEXT,
52
+ "CHAR": TEXT,
53
+ "CHARACTER": TEXT,
54
+ "STRING": TEXT,
55
+ "DATE": DATE,
56
+ "DATETIME": TIMESTAMP,
57
+ "TIMESTAMP": TIMESTAMP,
58
+ "TIMESTAMP_LTZ": TIMESTAMP_LTZ,
59
+ "TIMESTAMP_NTZ": TIMESTAMP_NTZ,
60
+ "TIMESTAMP_TZ": TIMESTAMP_TZ,
61
+ "TIME": TIME,
62
+ "VARIANT": VARIANT,
63
+ "OBJECT": OBJECT,
64
+ "ARRAY": ARRAY,
65
+ "BINARY": BINARY,
66
+ "VARBINARY": BINARY,
67
+ "BOOLEAN": BOOLEAN,
68
+ "GEOGRAPHY": GEOGRAPHY,
69
+ "GEOMETRY": GEOMETRY,
70
+ "VECTOR": VECTOR,
71
+ "MAP": MAP,
72
+ "FILE": FILE,
73
+ "INTERVAL_YEAR_MONTH": INTERVAL_YEAR_MONTH,
74
+ "INTERVAL_DAY_TIME": INTERVAL_DAY_TIME,
75
+ }
76
+
77
+ # Python type name to Snowflake type name mapping.
78
+ # Used by JsonBindingConverter to infer the Snowflake type from a Python value.
79
+ # Mirrors PYTHON_TO_SNOWFLAKE_TYPE from the reference connector's converter.py.
80
+ PYTHON_TO_SNOWFLAKE_TYPE = {
81
+ "int": "FIXED",
82
+ "long": "FIXED",
83
+ "float": "REAL",
84
+ "str": "TEXT",
85
+ "unicode": "TEXT",
86
+ "bool": "BOOLEAN",
87
+ "bytes": "BINARY",
88
+ "bytearray": "BINARY",
89
+ "datetime": "TIMESTAMP_NTZ",
90
+ "date": "DATE",
91
+ "time": "TIME",
92
+ "decimal": "FIXED",
93
+ "struct_time": "TIMESTAMP_NTZ",
94
+ "timedelta": "TIME",
95
+ "nonetype": "ANY",
96
+ }
97
+
98
+
99
+ def get_type_code(snowflake_type: str) -> int:
100
+ """
101
+ Get the type code for a Snowflake type name.
102
+
103
+ Args:
104
+ snowflake_type: Snowflake type name (e.g., "FIXED", "TEXT", "TIMESTAMP_NTZ")
105
+
106
+ Returns:
107
+ int: Type code for PEP 249 compliance
108
+ """
109
+ # Normalize type name: uppercase and strip leading/trailing whitespace (preserve internal spaces)
110
+ normalized_type = snowflake_type.upper().strip()
111
+ return SNOWFLAKE_TYPE_TO_CODE.get(normalized_type, TEXT) # Default to TEXT if unknown
112
+
113
+
114
+ # Reverse mapping: type code → canonical Snowflake type name.
115
+ # Re-exported by snowflake.connector.constants for backward compatibility with
116
+ # code written against the old snowflake-connector-python driver (e.g. dbt-snowflake).
117
+ FIELD_ID_TO_NAME: dict[int, str] = {
118
+ FIXED: "FIXED",
119
+ REAL: "REAL",
120
+ TEXT: "TEXT",
121
+ DATE: "DATE",
122
+ TIMESTAMP: "TIMESTAMP",
123
+ VARIANT: "VARIANT",
124
+ TIMESTAMP_LTZ: "TIMESTAMP_LTZ",
125
+ TIMESTAMP_TZ: "TIMESTAMP_TZ",
126
+ TIMESTAMP_NTZ: "TIMESTAMP_NTZ",
127
+ OBJECT: "OBJECT",
128
+ ARRAY: "ARRAY",
129
+ BINARY: "BINARY",
130
+ TIME: "TIME",
131
+ BOOLEAN: "BOOLEAN",
132
+ GEOGRAPHY: "GEOGRAPHY",
133
+ GEOMETRY: "GEOMETRY",
134
+ VECTOR: "VECTOR",
135
+ MAP: "MAP",
136
+ FILE: "FILE",
137
+ INTERVAL_YEAR_MONTH: "INTERVAL_YEAR_MONTH",
138
+ INTERVAL_DAY_TIME: "INTERVAL_DAY_TIME",
139
+ }
@@ -0,0 +1,65 @@
1
+ """General-purpose internal utilities shared across subsystems."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import inspect
6
+
7
+ from collections.abc import Iterable, Sequence
8
+ from typing import Any, cast
9
+
10
+ from ..errors import ProgrammingError
11
+ from .errorcode import ER_INVALID_VALUE
12
+
13
+
14
+ _ExecutemanyRow = Sequence[Any] | dict[str, Any]
15
+
16
+
17
+ def get_application_path() -> str | None:
18
+ # Outermost frame of the calling thread, as in the old connector: reports threading.py from a
19
+ # worker thread and "<stdin>" from a REPL.
20
+ try:
21
+ return inspect.stack(context=0)[-1].filename
22
+ except Exception:
23
+ return None
24
+
25
+
26
+ def _resolve_alias(
27
+ canonical: object,
28
+ alias: object,
29
+ canonical_name: str,
30
+ alias_name: str,
31
+ ) -> object:
32
+ """Return the resolved value from a canonical/legacy-alias pair.
33
+
34
+ Raises ProgrammingError if both are provided.
35
+ """
36
+ if canonical is not None and alias is not None:
37
+ raise ProgrammingError(
38
+ msg=f"Cannot supply both '{canonical_name}' and '{alias_name}'; pass one only.",
39
+ errno=ER_INVALID_VALUE,
40
+ )
41
+ return alias if alias is not None else canonical
42
+
43
+
44
+ def _coerce_executemany_params(seq_of_parameters: object) -> Sequence[_ExecutemanyRow]:
45
+ """Return a random-access sequence of ``executemany`` parameter rows.
46
+
47
+ Array binding peeks at the first row, transposes every row, then may walk the
48
+ same collection again on the per-row fallback. Non-sequences (generators,
49
+ ``map``, one-shot iterators) are therefore materialized once. Lists and
50
+ tuples are left unchanged.
51
+ """
52
+ if seq_of_parameters is None:
53
+ return ()
54
+ if isinstance(seq_of_parameters, Sequence):
55
+ return seq_of_parameters
56
+ if not isinstance(seq_of_parameters, Iterable):
57
+ raise ProgrammingError(
58
+ msg=(
59
+ "executemany() seq_of_parameters must be an iterable of parameter "
60
+ f"sequences or dicts, got {type(seq_of_parameters).__name__}. "
61
+ "Pass a list, tuple, or other iterable of rows."
62
+ ),
63
+ errno=ER_INVALID_VALUE,
64
+ )
65
+ return cast("Sequence[_ExecutemanyRow]", list(seq_of_parameters))