snowflake-cli 3.7.2__py3-none-any.whl → 3.8.0__py3-none-any.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 (56) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/_app/snow_connector.py +14 -0
  3. snowflake/cli/_app/telemetry.py +11 -0
  4. snowflake/cli/_plugins/connection/commands.py +4 -2
  5. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +1 -1
  6. snowflake/cli/_plugins/nativeapp/entities/application_package.py +20 -7
  7. snowflake/cli/_plugins/nativeapp/sf_sql_facade.py +5 -3
  8. snowflake/cli/_plugins/project/commands.py +16 -6
  9. snowflake/cli/_plugins/snowpark/common.py +31 -0
  10. snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +3 -0
  11. snowflake/cli/_plugins/snowpark/snowpark_entity.py +21 -1
  12. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +23 -1
  13. snowflake/cli/_plugins/spcs/common.py +7 -0
  14. snowflake/cli/_plugins/spcs/image_repository/commands.py +7 -2
  15. snowflake/cli/_plugins/spcs/image_repository/manager.py +6 -2
  16. snowflake/cli/_plugins/spcs/services/commands.py +2 -2
  17. snowflake/cli/_plugins/spcs/services/manager.py +36 -1
  18. snowflake/cli/_plugins/sql/commands.py +57 -6
  19. snowflake/cli/_plugins/sql/lexer/__init__.py +7 -0
  20. snowflake/cli/_plugins/sql/lexer/completer.py +12 -0
  21. snowflake/cli/_plugins/sql/lexer/functions.py +421 -0
  22. snowflake/cli/_plugins/sql/lexer/keywords.py +529 -0
  23. snowflake/cli/_plugins/sql/lexer/lexer.py +56 -0
  24. snowflake/cli/_plugins/sql/lexer/types.py +37 -0
  25. snowflake/cli/_plugins/sql/manager.py +43 -9
  26. snowflake/cli/_plugins/sql/repl.py +221 -0
  27. snowflake/cli/_plugins/sql/snowsql_commands.py +331 -0
  28. snowflake/cli/_plugins/sql/statement_reader.py +296 -0
  29. snowflake/cli/_plugins/streamlit/commands.py +30 -15
  30. snowflake/cli/_plugins/streamlit/manager.py +0 -183
  31. snowflake/cli/_plugins/streamlit/streamlit_entity.py +163 -23
  32. snowflake/cli/api/artifacts/upload.py +5 -0
  33. snowflake/cli/api/artifacts/utils.py +0 -2
  34. snowflake/cli/api/cli_global_context.py +7 -3
  35. snowflake/cli/api/commands/decorators.py +70 -0
  36. snowflake/cli/api/commands/flags.py +95 -3
  37. snowflake/cli/api/config.py +10 -0
  38. snowflake/cli/api/connections.py +10 -0
  39. snowflake/cli/api/console/abc.py +8 -2
  40. snowflake/cli/api/console/console.py +16 -0
  41. snowflake/cli/api/console/enum.py +1 -1
  42. snowflake/cli/api/entities/common.py +99 -10
  43. snowflake/cli/api/entities/utils.py +1 -0
  44. snowflake/cli/api/feature_flags.py +6 -0
  45. snowflake/cli/api/project/project_paths.py +5 -0
  46. snowflake/cli/api/rendering/sql_templates.py +2 -1
  47. snowflake/cli/api/sql_execution.py +16 -4
  48. snowflake/cli/api/utils/path_utils.py +15 -0
  49. snowflake/cli/api/utils/python_api_utils.py +12 -0
  50. {snowflake_cli-3.7.2.dist-info → snowflake_cli-3.8.0.dist-info}/METADATA +10 -6
  51. {snowflake_cli-3.7.2.dist-info → snowflake_cli-3.8.0.dist-info}/RECORD +54 -46
  52. snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -28
  53. snowflake/cli/_plugins/sql/source_reader.py +0 -230
  54. {snowflake_cli-3.7.2.dist-info → snowflake_cli-3.8.0.dist-info}/WHEEL +0 -0
  55. {snowflake_cli-3.7.2.dist-info → snowflake_cli-3.8.0.dist-info}/entry_points.txt +0 -0
  56. {snowflake_cli-3.7.2.dist-info → snowflake_cli-3.8.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,529 @@
1
+ KEYWORDS = (
2
+ "ABORT",
3
+ "ACCESS",
4
+ "ACCOUNT",
5
+ "ACCOUNTS",
6
+ "ACTION",
7
+ "ACTIVATE",
8
+ "ADD",
9
+ "ADMIN",
10
+ "AFTER",
11
+ "ALL",
12
+ "ALTER",
13
+ "AND",
14
+ "ANY",
15
+ "API",
16
+ "APPEND_ONLY",
17
+ "APPLICATION",
18
+ "APPLICATIONS",
19
+ "APPLY",
20
+ "ARRAY",
21
+ "AS",
22
+ "ASC",
23
+ "AT",
24
+ "AUDITING",
25
+ "AUTHORIZATION",
26
+ "AUTHORIZATIONS",
27
+ "AUTOINCREMENT",
28
+ "BEFORE",
29
+ "BEGIN",
30
+ "BERNOULLI",
31
+ "BETWEEN",
32
+ "BIGINT",
33
+ "BINARY",
34
+ "BIT",
35
+ "BLOCK",
36
+ "BODY",
37
+ "BOOLEAN",
38
+ "BREAK",
39
+ "BUILD",
40
+ "BUILTIN",
41
+ "BY",
42
+ "BYTE",
43
+ "BYTEINT",
44
+ "CACHE",
45
+ "CALL",
46
+ "CALLED",
47
+ "CALLER",
48
+ "CASCADE",
49
+ "CASE",
50
+ "CAST",
51
+ "CATEGORIES",
52
+ "CHANGE",
53
+ "CHANGES",
54
+ "CHAR",
55
+ "CHARACTER",
56
+ "CHECK",
57
+ "CHILD",
58
+ "CLEAREPCACHE",
59
+ "CLICKLAG",
60
+ "CLONE",
61
+ "CLOSE",
62
+ "CLUSTER",
63
+ "CLUSTERING",
64
+ "CLUSTERS",
65
+ "COLLATE",
66
+ "COLUMN",
67
+ "COLUMNS",
68
+ "COMMENT",
69
+ "COMMIT",
70
+ "COMPACT",
71
+ "COMPRESSION",
72
+ "CONNECT",
73
+ "CONNECTION",
74
+ "CONNECTIONS",
75
+ "CONNECT_BY_ROOT",
76
+ "CONSTRAINT",
77
+ "CONSTRAINTS",
78
+ "CONSUMER",
79
+ "CONSUMERS",
80
+ "CONTINUE",
81
+ "COPY",
82
+ "CP",
83
+ "CREATE",
84
+ "CREDENTIALS",
85
+ "CROSS",
86
+ "CUBE",
87
+ "CURRENT",
88
+ "D",
89
+ "DATA",
90
+ "DATABASE",
91
+ "DATABASES",
92
+ "DATE",
93
+ "DATETIME",
94
+ "DATE_PART",
95
+ "DEC",
96
+ "DECIMAL",
97
+ "DECLARE",
98
+ "DEFAULT",
99
+ "DEFERRABLE",
100
+ "DEFERRED",
101
+ "DEFRAGMENT",
102
+ "DELEGATED",
103
+ "DELETE",
104
+ "DELIMITED",
105
+ "DELTA",
106
+ "DEPLOYMENT",
107
+ "DEPLOYMENTS",
108
+ "DESC",
109
+ "DESCRIBE",
110
+ "DIRECTORY",
111
+ "DISABLE",
112
+ "DISCONNECT",
113
+ "DISTINCT",
114
+ "DIV",
115
+ "DO",
116
+ "DOUBLE",
117
+ "DROP",
118
+ "DUAL",
119
+ "ELSE",
120
+ "ELSEIF",
121
+ "EMITNULL",
122
+ "ENABLE",
123
+ "END",
124
+ "ENFORCED",
125
+ "ERROR",
126
+ "ESCAPE",
127
+ "EXCEPT",
128
+ "EXCEPTION",
129
+ "EXCHANGE",
130
+ "EXCHANGES",
131
+ "EXCLUSIVE",
132
+ "EXECUTE",
133
+ "EXECUTE_SDL",
134
+ "EXECUTION",
135
+ "EXISTS",
136
+ "EXIT",
137
+ "EXPLAIN",
138
+ "EXPORTED",
139
+ "EXTERNAL",
140
+ "EXTRACT",
141
+ "FAIL",
142
+ "FAILOVER",
143
+ "FALSE",
144
+ "FETCH",
145
+ "FIELDS",
146
+ "FILE",
147
+ "FILES",
148
+ "FIRST",
149
+ "FIRST_VALUE",
150
+ "FLOAT",
151
+ "FN",
152
+ "FOLLOWING",
153
+ "FOR",
154
+ "FORALL",
155
+ "FORCE",
156
+ "FOREIGN",
157
+ "FORMAT",
158
+ "FORMATS",
159
+ "FREE",
160
+ "FROM",
161
+ "FULL",
162
+ "FUNCTION",
163
+ "FUNCTIONS",
164
+ "FUTURE",
165
+ "GET",
166
+ "GLOBAL",
167
+ "GOTO",
168
+ "GRANT",
169
+ "GRANTS",
170
+ "GROUP",
171
+ "GROUPING",
172
+ "GSCLUSTER",
173
+ "GSCLUSTERS",
174
+ "GSINSTANCE",
175
+ "GSINSTANCES",
176
+ "GSMAPPINGS",
177
+ "GSPACKAGES",
178
+ "HAVING",
179
+ "HELP",
180
+ "HIBERNATE",
181
+ "HINTS",
182
+ "HISTORY",
183
+ "IDENTIFIED",
184
+ "IDENTIFIER",
185
+ "IDENTITY",
186
+ "IF",
187
+ "IGNORE",
188
+ "ILIKE",
189
+ "ILIKE",
190
+ "IMMEDIATE",
191
+ "IMMUTABLE",
192
+ "IMPORT",
193
+ "IMPORTED",
194
+ "IN",
195
+ "INBOUND",
196
+ "INBOUND_FDN",
197
+ "INCIDENT",
198
+ "INCIDENTS",
199
+ "INCOMING",
200
+ "INCREMENT",
201
+ "INDEX",
202
+ "INDEXES",
203
+ "INFO",
204
+ "INFORMATION",
205
+ "INITIALLY",
206
+ "INNER",
207
+ "INPUT",
208
+ "INSERT",
209
+ "INSERT",
210
+ "INSERT_ONLY",
211
+ "INT",
212
+ "INTEGER",
213
+ "INTEGRATION",
214
+ "INTEGRATIONS",
215
+ "INTERLEAVED",
216
+ "INTERSECT",
217
+ "INTERVAL",
218
+ "INTO",
219
+ "IS",
220
+ "ISSUE",
221
+ "ISSUES",
222
+ "ITERATE",
223
+ "JOBS",
224
+ "JOIN",
225
+ "KEEP",
226
+ "KEY",
227
+ "KEYS",
228
+ "KIND",
229
+ "LAG",
230
+ "LANGUAGE",
231
+ "LAST",
232
+ "LAST_VALUE",
233
+ "LATERAL",
234
+ "LEAD",
235
+ "LEAVE",
236
+ "LEFT",
237
+ "LIKE",
238
+ "LIKE",
239
+ "LIMIT",
240
+ "LINEAR",
241
+ "LINK",
242
+ "LIST",
243
+ "LISTING",
244
+ "LISTINGS",
245
+ "LOAD",
246
+ "LOCAL",
247
+ "LOCATION",
248
+ "LOCK",
249
+ "LOCKS",
250
+ "LOOP",
251
+ "LS",
252
+ "MANAGE",
253
+ "MANAGED",
254
+ "MAP",
255
+ "MASKING",
256
+ "MATCH",
257
+ "MATCHED",
258
+ "MATERIALIZED",
259
+ "MEMBERS",
260
+ "MERGE",
261
+ "METASTORE",
262
+ "METASTORES",
263
+ "MINUS",
264
+ "MODIFY",
265
+ "MONITOR",
266
+ "MONITORS",
267
+ "NAME",
268
+ "NATURAL",
269
+ "NETWORK",
270
+ "NEXT",
271
+ "NO",
272
+ "NORELY",
273
+ "NOT",
274
+ "NOTIFICATION",
275
+ "NOTIFICATIONS",
276
+ "NOTIFY",
277
+ "NOVALIDATE",
278
+ "NTH_VALUE",
279
+ "NULL",
280
+ "NULLS",
281
+ "NUMBER",
282
+ "NUMERIC",
283
+ "OBJECT",
284
+ "OBJECTS",
285
+ "OF",
286
+ "OFFSET",
287
+ "OJ",
288
+ "ON",
289
+ "ONLY",
290
+ "OPEN",
291
+ "OPERATE",
292
+ "OPERATION",
293
+ "OPTION",
294
+ "OR",
295
+ "ORDER",
296
+ "ORGANIZATION",
297
+ "ORGANIZATIONS",
298
+ "OUT",
299
+ "OUTBOUND",
300
+ "OUTBOUND_FDN",
301
+ "OUTER",
302
+ "OUTGOING",
303
+ "OVER",
304
+ "OVERWRITE",
305
+ "OWNER",
306
+ "OWNERSHIP",
307
+ "PACREAD",
308
+ "PACWRITE",
309
+ "PARAMETER",
310
+ "PARAMETERS",
311
+ "PARTIAL",
312
+ "PARTITION",
313
+ "PASSWORD",
314
+ "PERCENT",
315
+ "PIPE",
316
+ "PIPES",
317
+ "PIVOT",
318
+ "PLAN",
319
+ "PLUS",
320
+ "POLICIES",
321
+ "POLICY",
322
+ "POOL",
323
+ "POSITION",
324
+ "PRECEDING",
325
+ "PRECISION",
326
+ "PRESERVE",
327
+ "PRIMARY",
328
+ "PRIOR",
329
+ "PRIVILEGES",
330
+ "PROCEDURE",
331
+ "PROCEDURES",
332
+ "PROVIDER",
333
+ "PROVIDERS",
334
+ "PROVISION",
335
+ "PROVISIONINGREQUESTS",
336
+ "PROVISIONINGSERVERS",
337
+ "PUBLIC",
338
+ "PULL",
339
+ "PURGE",
340
+ "PUT",
341
+ "QUALIFY",
342
+ "QUERIES",
343
+ "QUIESCE",
344
+ "RAISE",
345
+ "RANGE",
346
+ "READ",
347
+ "READS",
348
+ "REAL",
349
+ "REBUILD",
350
+ "RECLUSTER",
351
+ "RECURSIVE",
352
+ "REFERENCE",
353
+ "REFERENCES",
354
+ "REFERENCE_USAGE",
355
+ "REFRESH",
356
+ "REGEXP",
357
+ "REGIONS",
358
+ "RELEASE",
359
+ "RELY",
360
+ "REMOVE",
361
+ "RENAME",
362
+ "REPEAT",
363
+ "REPEATABLE",
364
+ "REPLACE",
365
+ "REPLACE_FAIL",
366
+ "REPLICA",
367
+ "REPLICATION",
368
+ "REQUESTS",
369
+ "RESET",
370
+ "RESOURCE",
371
+ "RESPECT",
372
+ "RESTART",
373
+ "RESTORE",
374
+ "RESTRICT",
375
+ "RESULT",
376
+ "RESUME",
377
+ "RETURN",
378
+ "RETURNS",
379
+ "REVERSE",
380
+ "REVOKE",
381
+ "REWRITE",
382
+ "RIGHT",
383
+ "RLIKE",
384
+ "RLIKE",
385
+ "RM",
386
+ "ROLE",
387
+ "ROLES",
388
+ "ROLLBACK",
389
+ "ROLLUP",
390
+ "ROW",
391
+ "ROWS",
392
+ "RULE",
393
+ "SAMPLE",
394
+ "SCHEMA",
395
+ "SCHEMAS",
396
+ "SEARCH",
397
+ "SECURE",
398
+ "SECURITY",
399
+ "SEED",
400
+ "SELECT",
401
+ "SEMI",
402
+ "SEQUENCE",
403
+ "SEQUENCES",
404
+ "SERVER",
405
+ "SERVERS",
406
+ "SESSION",
407
+ "SESSIONIZE",
408
+ "SET",
409
+ "SETLOGLEVEL",
410
+ "SETS",
411
+ "SETUP",
412
+ "SFC",
413
+ "SHARE",
414
+ "SHARED",
415
+ "SHARES",
416
+ "SHOW",
417
+ "SHUTDOWN",
418
+ "SIMPLE",
419
+ "SMALLINT",
420
+ "SOME",
421
+ "SORT",
422
+ "STAGE",
423
+ "STAGES",
424
+ "START",
425
+ "STARTS",
426
+ "STATEMENT",
427
+ "STATISTICS",
428
+ "STOP",
429
+ "STORAGE",
430
+ "STORED",
431
+ "STREAM",
432
+ "STREAMS",
433
+ "STRICT",
434
+ "STRING",
435
+ "STRUCT",
436
+ "SUBSCRIPTION",
437
+ "SUBSCRIPTIONS",
438
+ "SUPPORT",
439
+ "SUSPEND",
440
+ "SUSPENDED",
441
+ "SUSPEND_IMMEDIATE",
442
+ "SWAP",
443
+ "SWITCH",
444
+ "SYNC",
445
+ "SYNONYM",
446
+ "SYSTEM",
447
+ "T",
448
+ "TABLE",
449
+ "TABLES",
450
+ "TABLESAMPLE",
451
+ "TASK",
452
+ "TASKS",
453
+ "TEMP",
454
+ "TEMPLATE",
455
+ "TEMPORARY",
456
+ "TERSE",
457
+ "TEXT",
458
+ "THEN",
459
+ "TIME",
460
+ "TIMECOLUMN",
461
+ "TIMEOUT",
462
+ "TIMESTAMP",
463
+ "TIMESTAMPLTZ",
464
+ "TIMESTAMPNTZ",
465
+ "TIMESTAMPTZ",
466
+ "TIMESTAMP_LTZ",
467
+ "TIMESTAMP_NTZ",
468
+ "TIMESTAMP_TZ",
469
+ "TINYINT",
470
+ "TO",
471
+ "TOP",
472
+ "TRANSACTION",
473
+ "TRANSACTIONS",
474
+ "TRANSIENT",
475
+ "TRIGGER",
476
+ "TRIGGERS",
477
+ "TRUE",
478
+ "TRUNCATE",
479
+ "TRY_CAST",
480
+ "TS",
481
+ "TYPE",
482
+ "TYPES",
483
+ "UNBOUNDED",
484
+ "UNDO",
485
+ "UNDROP",
486
+ "UNION",
487
+ "UNIQUE",
488
+ "UNLOCK",
489
+ "UNPIVOT",
490
+ "UNSET",
491
+ "UNTIL",
492
+ "UPDATE",
493
+ "UPGRADE",
494
+ "USAGE",
495
+ "USE",
496
+ "USER",
497
+ "USERS",
498
+ "USE_ANY_ROLE",
499
+ "USING",
500
+ "UTC",
501
+ "UTCTIMESTAMP",
502
+ "VALIDATE",
503
+ "VALUES",
504
+ "VARBINARY",
505
+ "VARCHAR",
506
+ "VARIABLES",
507
+ "VARIANT",
508
+ "VARYING",
509
+ "VERSION",
510
+ "VIEW",
511
+ "VIEWS",
512
+ "VOLATILE",
513
+ "VOLUME",
514
+ "VOLUMES",
515
+ "WAREHOUSE",
516
+ "WAREHOUSES",
517
+ "WARN",
518
+ "WHEN",
519
+ "WHENEVER",
520
+ "WHERE",
521
+ "WHILE",
522
+ "WITH",
523
+ "WITHIN",
524
+ "WITHOUT",
525
+ "WMSQUEUEDOPS",
526
+ "WORK",
527
+ "WRITE",
528
+ "ZONE",
529
+ )
@@ -0,0 +1,56 @@
1
+ import re
2
+
3
+ from pygments.lexer import bygroups, include
4
+ from pygments.lexers.sql import RegexLexer
5
+ from pygments.token import (
6
+ Comment,
7
+ Keyword,
8
+ Name,
9
+ Number,
10
+ Operator,
11
+ Punctuation,
12
+ String,
13
+ Text,
14
+ )
15
+ from snowflake.cli._plugins.sql.lexer.functions import FUNCTIONS
16
+ from snowflake.cli._plugins.sql.lexer.keywords import KEYWORDS
17
+ from snowflake.cli._plugins.sql.lexer.types import TYPES
18
+
19
+
20
+ class CliLexer(RegexLexer):
21
+ name = "Snowflake-CLI"
22
+ aliases = ("cli", "snowflake-cli")
23
+ mimetype = ("text/x-snowflake-cli",)
24
+ flags = re.IGNORECASE
25
+ tokens = {
26
+ "comments": [
27
+ (r"--.*?$", Comment.Single),
28
+ (r"/\*", Comment.Multiline, "multiline-comments"),
29
+ ],
30
+ "multiline-comments": [
31
+ (r"\*/", Comment.Multiline, "#pop"),
32
+ (r"[^/*]+", Comment.Multiline),
33
+ (r"[/*]", Comment.Multiline),
34
+ ],
35
+ "root": [
36
+ include("comments"),
37
+ (r"\s+", Text),
38
+ (r"[0-9]+", Number.Integer),
39
+ (r"[0-9]*\.[0-9]+(e[+-][0-9]+)", Number.Float),
40
+ (r"'(\\\\|\\'|''|[^'])*'", String.Single),
41
+ (r'"(\\\\|\\"|""|[^"])*"', String.Double),
42
+ (r"`(\\\\|\\`|``|[^`])*`", String.Symbol),
43
+ (r"[+*/<>=~!@#%^&$|`?-]", Operator),
44
+ (
45
+ r"\b({0})(\b\s*)(\()?".format("|".join(TYPES)),
46
+ bygroups(Keyword.Type, Text, Punctuation),
47
+ ),
48
+ (r"\b({0})\b".format("|".join(KEYWORDS + FUNCTIONS)), Keyword),
49
+ (r"\b(auto_increment|engine|charset|tables)\b", Keyword.Pseudo),
50
+ (r"(true|false|null)", Name.Constant),
51
+ (r"([a-z_]\w*)(\s*)(\()", bygroups(Name.Function, Text, Punctuation)),
52
+ (r"[a-z_]\w*", Name),
53
+ (r"\$[a-z0-9]*[._]*[a-z0-9]*", Name.Variable),
54
+ (r"[;:()\[\],.]", Punctuation),
55
+ ],
56
+ }
@@ -0,0 +1,37 @@
1
+ TYPES = (
2
+ "ARRAY",
3
+ "BIGINT",
4
+ "BINARY",
5
+ "BIT",
6
+ "BOOLEAN",
7
+ "BYTEINT",
8
+ "CHAR",
9
+ "CHARACTER",
10
+ "DATE",
11
+ "DATETIME",
12
+ "DEC",
13
+ "DECIMAL",
14
+ "DOUBLE",
15
+ "FLOAT",
16
+ "INT",
17
+ "INTEGER",
18
+ "NUMBER",
19
+ "NUMERIC",
20
+ "OBJECT",
21
+ "REAL",
22
+ "SMALLINT",
23
+ "STRING",
24
+ "TEXT",
25
+ "TIME",
26
+ "TIMESTAMP",
27
+ "TIMESTAMPLTZ",
28
+ "TIMESTAMPNTZ",
29
+ "TIMESTAMPTZ",
30
+ "TIMESTAMP_LTZ",
31
+ "TIMESTAMP_NTZ",
32
+ "TIMESTAMP_TZ",
33
+ "TINYINT",
34
+ "VARBINARY",
35
+ "VARCHAR",
36
+ "VARIANT",
37
+ )
@@ -20,20 +20,24 @@ from functools import partial
20
20
  from pathlib import Path
21
21
  from typing import Dict, Iterable, List, Tuple
22
22
 
23
+ from snowflake.cli._app.printing import print_result
23
24
  from snowflake.cli._plugins.sql.snowsql_templating import transpile_snowsql_templates
24
- from snowflake.cli._plugins.sql.source_reader import (
25
+ from snowflake.cli._plugins.sql.statement_reader import (
26
+ CompiledStatement,
25
27
  compile_statements,
26
28
  files_reader,
27
29
  query_reader,
28
30
  )
31
+ from snowflake.cli.api.cli_global_context import get_cli_context
29
32
  from snowflake.cli.api.console import cli_console
30
33
  from snowflake.cli.api.exceptions import CliArgumentError, CliSqlError
34
+ from snowflake.cli.api.output.types import CollectionResult
31
35
  from snowflake.cli.api.rendering.sql_templates import snowflake_sql_jinja_render
32
36
  from snowflake.cli.api.secure_path import SecurePath
33
37
  from snowflake.cli.api.sql_execution import SqlExecutionMixin, VerboseCursor
34
38
  from snowflake.connector.cursor import SnowflakeCursor
35
39
 
36
- IsSingleStatement = bool
40
+ ExpectedResultsCount = int
37
41
 
38
42
  logger = logging.getLogger(__name__)
39
43
 
@@ -46,7 +50,8 @@ class SqlManager(SqlExecutionMixin):
46
50
  std_in: bool,
47
51
  data: Dict | None = None,
48
52
  retain_comments: bool = False,
49
- ) -> Tuple[IsSingleStatement, Iterable[SnowflakeCursor]]:
53
+ single_transaction: bool = False,
54
+ ) -> Tuple[ExpectedResultsCount, Iterable[SnowflakeCursor]]:
50
55
  """Reads, transforms and execute statements from input.
51
56
 
52
57
  Only one input can be consumed at a time.
@@ -71,8 +76,10 @@ class SqlManager(SqlExecutionMixin):
71
76
  else:
72
77
  raise CliArgumentError("Use either query, filename or input option.")
73
78
 
74
- errors, stmt_count, compiled_statements = compile_statements(stmt_reader)
75
- if not any((errors, stmt_count, compiled_statements)):
79
+ errors, expected_results_cnt, compiled_statements = compile_statements(
80
+ stmt_reader
81
+ )
82
+ if not any((errors, expected_results_cnt, compiled_statements)):
76
83
  raise CliArgumentError("Use either query, filename or input option.")
77
84
 
78
85
  if errors:
@@ -81,8 +88,35 @@ class SqlManager(SqlExecutionMixin):
81
88
  cli_console.warning(error)
82
89
  raise CliSqlError("SQL rendering error")
83
90
 
84
- is_single_statement = not (stmt_count > 1)
85
- return is_single_statement, self.execute_string(
86
- "\n".join(compiled_statements),
87
- cursor_class=VerboseCursor,
91
+ if single_transaction:
92
+ logger.info("disabling AUTOCOMMIT")
93
+ self.disable_autocommit()
94
+ compiled_statements = [
95
+ CompiledStatement(statement="BEGIN;"),
96
+ *compiled_statements,
97
+ CompiledStatement(statement="COMMIT;"),
98
+ ]
99
+ expected_results_cnt = len(compiled_statements)
100
+
101
+ cursor_class = SnowflakeCursor if get_cli_context().is_repl else VerboseCursor
102
+ return expected_results_cnt, self._execute_compiled_statements(
103
+ compiled_statements,
104
+ cursor_class=cursor_class,
88
105
  )
106
+
107
+ def _execute_compiled_statements(
108
+ self, compiled_statements: List[CompiledStatement], cursor_class
109
+ ) -> Iterable[SnowflakeCursor]:
110
+ for stmt in compiled_statements:
111
+ if stmt.execute_async:
112
+ cursor = self._conn.cursor(cursor_class=cursor_class)
113
+ cursor.execute(stmt.statement, _no_results=True)
114
+ # only log query ID for consistency with SnowSQL
115
+ logger.info("Async execution id: %s", cursor.sfqid)
116
+ print_result(CollectionResult([{"scheduled query ID": cursor.sfqid}]))
117
+ elif stmt.statement:
118
+ yield from self.execute_string(
119
+ stmt.statement, cursor_class=cursor_class
120
+ )
121
+ if stmt.command:
122
+ stmt.command.execute(self._conn)