snowflake-cli-labs 3.0.0rc5__py3-none-any.whl → 3.0.2__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 (244) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/METADATA +6 -96
  3. snowflake_cli_labs-3.0.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/_app/__init__.py +0 -22
  7. snowflake/cli/_app/__main__.py +0 -31
  8. snowflake/cli/_app/api_impl/__init__.py +0 -13
  9. snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
  10. snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  11. snowflake/cli/_app/cli_app.py +0 -252
  12. snowflake/cli/_app/commands_registration/__init__.py +0 -33
  13. snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
  14. snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
  15. snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
  16. snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
  17. snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
  18. snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
  19. snowflake/cli/_app/constants.py +0 -19
  20. snowflake/cli/_app/dev/__init__.py +0 -13
  21. snowflake/cli/_app/dev/commands_structure.py +0 -48
  22. snowflake/cli/_app/dev/docs/__init__.py +0 -13
  23. snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
  24. snowflake/cli/_app/dev/docs/generator.py +0 -35
  25. snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
  26. snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
  27. snowflake/cli/_app/dev/docs/template_utils.py +0 -23
  28. snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  29. snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
  30. snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
  31. snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
  32. snowflake/cli/_app/loggers.py +0 -199
  33. snowflake/cli/_app/main_typer.py +0 -62
  34. snowflake/cli/_app/printing.py +0 -181
  35. snowflake/cli/_app/secret.py +0 -9
  36. snowflake/cli/_app/snow_connector.py +0 -309
  37. snowflake/cli/_app/telemetry.py +0 -220
  38. snowflake/cli/_app/version_check.py +0 -74
  39. snowflake/cli/_plugins/__init__.py +0 -13
  40. snowflake/cli/_plugins/connection/__init__.py +0 -13
  41. snowflake/cli/_plugins/connection/commands.py +0 -353
  42. snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
  43. snowflake/cli/_plugins/connection/util.py +0 -195
  44. snowflake/cli/_plugins/cortex/__init__.py +0 -13
  45. snowflake/cli/_plugins/cortex/commands.py +0 -332
  46. snowflake/cli/_plugins/cortex/constants.py +0 -17
  47. snowflake/cli/_plugins/cortex/manager.py +0 -189
  48. snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
  49. snowflake/cli/_plugins/cortex/types.py +0 -22
  50. snowflake/cli/_plugins/git/__init__.py +0 -13
  51. snowflake/cli/_plugins/git/commands.py +0 -358
  52. snowflake/cli/_plugins/git/manager.py +0 -151
  53. snowflake/cli/_plugins/git/plugin_spec.py +0 -30
  54. snowflake/cli/_plugins/helpers/__init__.py +0 -13
  55. snowflake/cli/_plugins/helpers/commands.py +0 -90
  56. snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
  57. snowflake/cli/_plugins/init/__init__.py +0 -13
  58. snowflake/cli/_plugins/init/commands.py +0 -248
  59. snowflake/cli/_plugins/init/plugin_spec.py +0 -30
  60. snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
  61. snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
  62. snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
  63. snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
  64. snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
  65. snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
  66. snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
  67. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
  68. snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
  69. snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  70. snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  71. snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
  72. snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
  73. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
  74. snowflake/cli/_plugins/nativeapp/commands.py +0 -559
  75. snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
  76. snowflake/cli/_plugins/nativeapp/constants.py +0 -27
  77. snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
  78. snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
  79. snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
  80. snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
  81. snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
  82. snowflake/cli/_plugins/nativeapp/manager.py +0 -415
  83. snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
  84. snowflake/cli/_plugins/nativeapp/policy.py +0 -53
  85. snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
  86. snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
  87. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
  88. snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
  89. snowflake/cli/_plugins/nativeapp/utils.py +0 -98
  90. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
  91. snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
  92. snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
  93. snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
  94. snowflake/cli/_plugins/notebook/__init__.py +0 -13
  95. snowflake/cli/_plugins/notebook/commands.py +0 -86
  96. snowflake/cli/_plugins/notebook/exceptions.py +0 -20
  97. snowflake/cli/_plugins/notebook/manager.py +0 -71
  98. snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
  99. snowflake/cli/_plugins/notebook/types.py +0 -15
  100. snowflake/cli/_plugins/object/__init__.py +0 -13
  101. snowflake/cli/_plugins/object/command_aliases.py +0 -95
  102. snowflake/cli/_plugins/object/commands.py +0 -180
  103. snowflake/cli/_plugins/object/common.py +0 -85
  104. snowflake/cli/_plugins/object/manager.py +0 -118
  105. snowflake/cli/_plugins/object/plugin_spec.py +0 -30
  106. snowflake/cli/_plugins/snowpark/__init__.py +0 -13
  107. snowflake/cli/_plugins/snowpark/commands.py +0 -450
  108. snowflake/cli/_plugins/snowpark/common.py +0 -268
  109. snowflake/cli/_plugins/snowpark/models.py +0 -150
  110. snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
  111. snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
  112. snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
  113. snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
  114. snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
  115. snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
  116. snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
  117. snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
  118. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
  119. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
  120. snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
  121. snowflake/cli/_plugins/snowpark/zipper.py +0 -89
  122. snowflake/cli/_plugins/spcs/__init__.py +0 -33
  123. snowflake/cli/_plugins/spcs/common.py +0 -99
  124. snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
  125. snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
  126. snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
  127. snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
  128. snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
  129. snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
  130. snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
  131. snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
  132. snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
  133. snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
  134. snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
  135. snowflake/cli/_plugins/spcs/services/commands.py +0 -345
  136. snowflake/cli/_plugins/spcs/services/manager.py +0 -208
  137. snowflake/cli/_plugins/sql/__init__.py +0 -13
  138. snowflake/cli/_plugins/sql/commands.py +0 -86
  139. snowflake/cli/_plugins/sql/manager.py +0 -92
  140. snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
  141. snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
  142. snowflake/cli/_plugins/stage/__init__.py +0 -13
  143. snowflake/cli/_plugins/stage/commands.py +0 -264
  144. snowflake/cli/_plugins/stage/diff.py +0 -280
  145. snowflake/cli/_plugins/stage/manager.py +0 -582
  146. snowflake/cli/_plugins/stage/md5.py +0 -160
  147. snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
  148. snowflake/cli/_plugins/stage/utils.py +0 -54
  149. snowflake/cli/_plugins/streamlit/__init__.py +0 -13
  150. snowflake/cli/_plugins/streamlit/commands.py +0 -195
  151. snowflake/cli/_plugins/streamlit/manager.py +0 -220
  152. snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
  153. snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
  154. snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
  155. snowflake/cli/_plugins/workspace/__init__.py +0 -13
  156. snowflake/cli/_plugins/workspace/action_context.py +0 -18
  157. snowflake/cli/_plugins/workspace/commands.py +0 -306
  158. snowflake/cli/_plugins/workspace/manager.py +0 -74
  159. snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
  160. snowflake/cli/api/__init__.py +0 -48
  161. snowflake/cli/api/cli_global_context.py +0 -247
  162. snowflake/cli/api/commands/__init__.py +0 -13
  163. snowflake/cli/api/commands/alias.py +0 -23
  164. snowflake/cli/api/commands/common.py +0 -25
  165. snowflake/cli/api/commands/decorators.py +0 -369
  166. snowflake/cli/api/commands/execution_metadata.py +0 -40
  167. snowflake/cli/api/commands/experimental_behaviour.py +0 -18
  168. snowflake/cli/api/commands/flags.py +0 -561
  169. snowflake/cli/api/commands/overrideable_parameter.py +0 -143
  170. snowflake/cli/api/commands/snow_typer.py +0 -247
  171. snowflake/cli/api/commands/utils.py +0 -18
  172. snowflake/cli/api/config.py +0 -380
  173. snowflake/cli/api/connections.py +0 -216
  174. snowflake/cli/api/console/__init__.py +0 -17
  175. snowflake/cli/api/console/abc.py +0 -94
  176. snowflake/cli/api/console/console.py +0 -134
  177. snowflake/cli/api/console/enum.py +0 -17
  178. snowflake/cli/api/constants.py +0 -90
  179. snowflake/cli/api/entities/common.py +0 -56
  180. snowflake/cli/api/entities/utils.py +0 -370
  181. snowflake/cli/api/errno.py +0 -28
  182. snowflake/cli/api/exceptions.py +0 -190
  183. snowflake/cli/api/feature_flags.py +0 -54
  184. snowflake/cli/api/identifiers.py +0 -190
  185. snowflake/cli/api/metrics.py +0 -92
  186. snowflake/cli/api/output/__init__.py +0 -13
  187. snowflake/cli/api/output/formats.py +0 -20
  188. snowflake/cli/api/output/types.py +0 -118
  189. snowflake/cli/api/plugins/__init__.py +0 -13
  190. snowflake/cli/api/plugins/command/__init__.py +0 -72
  191. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  192. snowflake/cli/api/plugins/plugin_config.py +0 -32
  193. snowflake/cli/api/project/__init__.py +0 -13
  194. snowflake/cli/api/project/definition.py +0 -126
  195. snowflake/cli/api/project/definition_conversion.py +0 -400
  196. snowflake/cli/api/project/definition_manager.py +0 -145
  197. snowflake/cli/api/project/errors.py +0 -56
  198. snowflake/cli/api/project/project_verification.py +0 -23
  199. snowflake/cli/api/project/schemas/__init__.py +0 -13
  200. snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
  201. snowflake/cli/api/project/schemas/entities/common.py +0 -153
  202. snowflake/cli/api/project/schemas/entities/entities.py +0 -61
  203. snowflake/cli/api/project/schemas/project_definition.py +0 -330
  204. snowflake/cli/api/project/schemas/template.py +0 -77
  205. snowflake/cli/api/project/schemas/updatable_model.py +0 -202
  206. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  207. snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
  208. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  209. snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
  210. snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
  211. snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
  212. snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
  213. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  214. snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
  215. snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
  216. snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
  217. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  218. snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
  219. snowflake/cli/api/project/util.py +0 -278
  220. snowflake/cli/api/rendering/__init__.py +0 -13
  221. snowflake/cli/api/rendering/jinja.py +0 -118
  222. snowflake/cli/api/rendering/project_definition_templates.py +0 -43
  223. snowflake/cli/api/rendering/project_templates.py +0 -98
  224. snowflake/cli/api/rendering/sql_templates.py +0 -105
  225. snowflake/cli/api/rest_api.py +0 -178
  226. snowflake/cli/api/sanitizers.py +0 -43
  227. snowflake/cli/api/secure_path.py +0 -360
  228. snowflake/cli/api/secure_utils.py +0 -118
  229. snowflake/cli/api/sql_execution.py +0 -280
  230. snowflake/cli/api/utils/__init__.py +0 -13
  231. snowflake/cli/api/utils/cursor.py +0 -34
  232. snowflake/cli/api/utils/definition_rendering.py +0 -415
  233. snowflake/cli/api/utils/dict_utils.py +0 -73
  234. snowflake/cli/api/utils/error_handling.py +0 -23
  235. snowflake/cli/api/utils/graph.py +0 -97
  236. snowflake/cli/api/utils/models.py +0 -63
  237. snowflake/cli/api/utils/naming_utils.py +0 -13
  238. snowflake/cli/api/utils/path_utils.py +0 -36
  239. snowflake/cli/api/utils/templating_functions.py +0 -144
  240. snowflake/cli/api/utils/types.py +0 -35
  241. snowflake_cli_labs-3.0.0rc5.dist-info/RECORD +0 -242
  242. snowflake_cli_labs-3.0.0rc5.dist-info/entry_points.txt +0 -2
  243. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/WHEEL +0 -0
  244. {snowflake_cli_labs-3.0.0rc5.dist-info → snowflake_cli_labs-3.0.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,208 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import json
18
- from pathlib import Path
19
- from typing import List, Optional
20
-
21
- import yaml
22
- from snowflake.cli._plugins.object.common import Tag
23
- from snowflake.cli._plugins.spcs.common import (
24
- NoPropertiesProvidedError,
25
- handle_object_already_exists,
26
- strip_empty_lines,
27
- )
28
- from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB, ObjectType
29
- from snowflake.cli.api.secure_path import SecurePath
30
- from snowflake.cli.api.sql_execution import SqlExecutionMixin
31
- from snowflake.connector.cursor import SnowflakeCursor
32
- from snowflake.connector.errors import ProgrammingError
33
-
34
-
35
- class ServiceManager(SqlExecutionMixin):
36
- def create(
37
- self,
38
- service_name: str,
39
- compute_pool: str,
40
- spec_path: Path,
41
- min_instances: int,
42
- max_instances: int,
43
- auto_resume: bool,
44
- external_access_integrations: Optional[List[str]],
45
- query_warehouse: Optional[str],
46
- tags: Optional[List[Tag]],
47
- comment: Optional[str],
48
- if_not_exists: bool,
49
- ) -> SnowflakeCursor:
50
- spec = self._read_yaml(spec_path)
51
- create_statement = "CREATE SERVICE"
52
- if if_not_exists:
53
- create_statement = f"{create_statement} IF NOT EXISTS"
54
- query = f"""\
55
- {create_statement} {service_name}
56
- IN COMPUTE POOL {compute_pool}
57
- FROM SPECIFICATION $$
58
- {spec}
59
- $$
60
- MIN_INSTANCES = {min_instances}
61
- MAX_INSTANCES = {max_instances}
62
- AUTO_RESUME = {auto_resume}
63
- """.splitlines()
64
-
65
- if external_access_integrations:
66
- external_access_integration_list = ",".join(
67
- f"{e}" for e in external_access_integrations
68
- )
69
- query.append(
70
- f"EXTERNAL_ACCESS_INTEGRATIONS = ({external_access_integration_list})"
71
- )
72
-
73
- if query_warehouse:
74
- query.append(f"QUERY_WAREHOUSE = {query_warehouse}")
75
-
76
- if comment:
77
- query.append(f"COMMENT = {comment}")
78
-
79
- if tags:
80
- tag_list = ",".join(f"{t.name}={t.value_string_literal()}" for t in tags)
81
- query.append(f"WITH TAG ({tag_list})")
82
-
83
- try:
84
- return self._execute_query(strip_empty_lines(query))
85
- except ProgrammingError as e:
86
- handle_object_already_exists(e, ObjectType.SERVICE, service_name)
87
-
88
- def execute_job(
89
- self,
90
- job_service_name: str,
91
- compute_pool: str,
92
- spec_path: Path,
93
- external_access_integrations: Optional[List[str]],
94
- query_warehouse: Optional[str],
95
- comment: Optional[str],
96
- ) -> SnowflakeCursor:
97
- spec = self._read_yaml(spec_path)
98
- query = f"""\
99
- EXECUTE JOB SERVICE
100
- IN COMPUTE POOL {compute_pool}
101
- FROM SPECIFICATION $$
102
- {spec}
103
- $$
104
- NAME = {job_service_name}
105
- """.splitlines()
106
-
107
- if external_access_integrations:
108
- external_access_integration_list = ",".join(
109
- f"{e}" for e in external_access_integrations
110
- )
111
- query.append(
112
- f"EXTERNAL_ACCESS_INTEGRATIONS = ({external_access_integration_list})"
113
- )
114
-
115
- if query_warehouse:
116
- query.append(f"QUERY_WAREHOUSE = {query_warehouse}")
117
-
118
- if comment:
119
- query.append(f"COMMENT = {comment}")
120
-
121
- try:
122
- return self._execute_query(strip_empty_lines(query))
123
- except ProgrammingError as e:
124
- handle_object_already_exists(e, ObjectType.SERVICE, job_service_name)
125
-
126
- def _read_yaml(self, path: Path) -> str:
127
- # TODO(aivanou): Add validation towards schema
128
- with SecurePath(path).open("r", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB) as fh:
129
- data = yaml.safe_load(fh)
130
- return json.dumps(data)
131
-
132
- def status(self, service_name: str) -> SnowflakeCursor:
133
- return self._execute_query(f"CALL SYSTEM$GET_SERVICE_STATUS('{service_name}')")
134
-
135
- def logs(
136
- self, service_name: str, instance_id: str, container_name: str, num_lines: int
137
- ):
138
- return self._execute_query(
139
- f"call SYSTEM$GET_SERVICE_LOGS('{service_name}', '{instance_id}', '{container_name}', {num_lines});"
140
- )
141
-
142
- def upgrade_spec(self, service_name: str, spec_path: Path):
143
- spec = self._read_yaml(spec_path)
144
- query = f"alter service {service_name} from specification $$ {spec} $$"
145
- return self._execute_query(query)
146
-
147
- def list_endpoints(self, service_name: str) -> SnowflakeCursor:
148
- return self._execute_query(f"show endpoints in service {service_name}")
149
-
150
- def suspend(self, service_name: str):
151
- return self._execute_query(f"alter service {service_name} suspend")
152
-
153
- def resume(self, service_name: str):
154
- return self._execute_query(f"alter service {service_name} resume")
155
-
156
- def set_property(
157
- self,
158
- service_name: str,
159
- min_instances: Optional[int],
160
- max_instances: Optional[int],
161
- query_warehouse: Optional[str],
162
- auto_resume: Optional[bool],
163
- comment: Optional[str],
164
- ):
165
- property_pairs = [
166
- ("min_instances", min_instances),
167
- ("max_instances", max_instances),
168
- ("query_warehouse", query_warehouse),
169
- ("auto_resume", auto_resume),
170
- ("comment", comment),
171
- ]
172
-
173
- # Check if all provided properties are set to None (no properties are being set)
174
- if all([value is None for property_name, value in property_pairs]):
175
- raise NoPropertiesProvidedError(
176
- f"No properties specified for service '{service_name}'. Please provide at least one property to set."
177
- )
178
- query: List[str] = [f"alter service {service_name} set"]
179
- for property_name, value in property_pairs:
180
- if value is not None:
181
- query.append(f"{property_name} = {value}")
182
- return self._execute_query(strip_empty_lines(query))
183
-
184
- def unset_property(
185
- self,
186
- service_name: str,
187
- min_instances: bool,
188
- max_instances: bool,
189
- query_warehouse: bool,
190
- auto_resume: bool,
191
- comment: bool,
192
- ):
193
- property_pairs = [
194
- ("min_instances", min_instances),
195
- ("max_instances", max_instances),
196
- ("query_warehouse", query_warehouse),
197
- ("auto_resume", auto_resume),
198
- ("comment", comment),
199
- ]
200
-
201
- # Check if all properties provided are False (no properties are being unset)
202
- if not any([value for property_name, value in property_pairs]):
203
- raise NoPropertiesProvidedError(
204
- f"No properties specified for service '{service_name}'. Please provide at least one property to reset to its default value."
205
- )
206
- unset_list = [property_name for property_name, value in property_pairs if value]
207
- query = f"alter service {service_name} unset {','.join(unset_list)}"
208
- return self._execute_query(query)
@@ -1,13 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
@@ -1,86 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- from pathlib import Path
18
- from typing import List, Optional
19
-
20
- from snowflake.cli._plugins.sql.manager import SqlManager
21
- from snowflake.cli.api.commands.decorators import with_project_definition
22
- from snowflake.cli.api.commands.flags import (
23
- variables_option,
24
- )
25
- from snowflake.cli.api.commands.overrideable_parameter import OverrideableOption
26
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
27
- from snowflake.cli.api.commands.utils import parse_key_value_variables
28
- from snowflake.cli.api.output.types import CommandResult, MultipleResults, QueryResult
29
-
30
- # simple Typer with defaults because it won't become a command group as it contains only one command
31
- app = SnowTyperFactory()
32
-
33
- SOURCE_EXCLUSIVE_OPTIONS_NAMES = ["query", "files", "std_in"]
34
-
35
- SourceOption = OverrideableOption(
36
- mutually_exclusive=SOURCE_EXCLUSIVE_OPTIONS_NAMES, show_default=False
37
- )
38
-
39
-
40
- @app.command(name="sql", requires_connection=True, no_args_is_help=True)
41
- @with_project_definition(is_optional=True)
42
- def execute_sql(
43
- query: Optional[str] = SourceOption(
44
- default=None,
45
- param_decls=["--query", "-q"],
46
- help="Query to execute.",
47
- ),
48
- files: Optional[List[Path]] = SourceOption(
49
- default=[],
50
- param_decls=["--filename", "-f"],
51
- exists=True,
52
- file_okay=True,
53
- dir_okay=False,
54
- readable=True,
55
- help="File to execute.",
56
- ),
57
- std_in: Optional[bool] = SourceOption(
58
- default=False,
59
- param_decls=["--stdin", "-i"],
60
- help="Read the query from standard input. Use it when piping input to this command.",
61
- ),
62
- data_override: List[str] = variables_option(
63
- "String in format of key=value. If provided the SQL content will "
64
- "be treated as template and rendered using provided data.",
65
- ),
66
- **options,
67
- ) -> CommandResult:
68
- """
69
- Executes Snowflake query.
70
-
71
- Use either query, filename or input option.
72
-
73
- Query to execute can be specified using query option, filename option (all queries from file will be executed)
74
- or via stdin by piping output from other command. For example `cat my.sql | snow sql -i`.
75
-
76
- The command supports variable substitution that happens on client-side.
77
- """
78
-
79
- data = {}
80
- if data_override:
81
- data = {v.key: v.value for v in parse_key_value_variables(data_override)}
82
-
83
- single_statement, cursors = SqlManager().execute(query, files, std_in, data=data)
84
- if single_statement:
85
- return QueryResult(next(cursors))
86
- return MultipleResults((QueryResult(c) for c in cursors))
@@ -1,92 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import sys
18
- from io import StringIO
19
- from itertools import chain
20
- from pathlib import Path
21
- from typing import Dict, Iterable, List, Tuple
22
-
23
- from click import ClickException, UsageError
24
- from jinja2 import UndefinedError
25
- from snowflake.cli._plugins.sql.snowsql_templating import transpile_snowsql_templates
26
- from snowflake.cli.api.rendering.sql_templates import snowflake_sql_jinja_render
27
- from snowflake.cli.api.secure_path import UNLIMITED, SecurePath
28
- from snowflake.cli.api.sql_execution import SqlExecutionMixin, VerboseCursor
29
- from snowflake.connector.cursor import SnowflakeCursor
30
- from snowflake.connector.util_text import split_statements
31
-
32
- IsSingleStatement = bool
33
-
34
-
35
- class SqlManager(SqlExecutionMixin):
36
- def execute(
37
- self,
38
- query: str | None,
39
- files: List[Path] | None,
40
- std_in: bool,
41
- data: Dict | None = None,
42
- ) -> Tuple[IsSingleStatement, Iterable[SnowflakeCursor]]:
43
- inputs = [query, files, std_in]
44
- # Check if any two inputs were provided simultaneously
45
- if len([i for i in inputs if i]) > 1:
46
- raise UsageError(
47
- "Multiple input sources specified. Please specify only one."
48
- )
49
-
50
- if std_in:
51
- query = sys.stdin.read()
52
- if query:
53
- return self._execute_single_query(query=query, data=data)
54
-
55
- if files:
56
- # Multiple files
57
- results = []
58
- single_statement = False
59
- for file in files:
60
- query_from_file = SecurePath(file).read_text(
61
- file_size_limit_mb=UNLIMITED
62
- )
63
- single_statement, result = self._execute_single_query(
64
- query=query_from_file, data=data
65
- )
66
- results.append(result)
67
-
68
- # Use single_statement if there's only one, otherwise this is multi statement result
69
- single_statement = len(files) == 1 and single_statement
70
- return single_statement, chain.from_iterable(results)
71
-
72
- # At that point, no stdin, query or files were provided
73
- raise UsageError("Use either query, filename or input option.")
74
-
75
- def _execute_single_query(
76
- self, query: str, data: Dict | None = None
77
- ) -> Tuple[IsSingleStatement, Iterable[SnowflakeCursor]]:
78
- try:
79
- query = transpile_snowsql_templates(query)
80
- query = snowflake_sql_jinja_render(content=query, data=data)
81
- except UndefinedError as err:
82
- raise ClickException(f"SQL template rendering error: {err}")
83
-
84
- statements = tuple(
85
- statement
86
- for statement, _ in split_statements(StringIO(query), remove_comments=True)
87
- )
88
- single_statement = len(statements) == 1
89
-
90
- return single_statement, self._execute_string(
91
- "\n".join(statements), cursor_class=VerboseCursor
92
- )
@@ -1,30 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from snowflake.cli._plugins.sql import commands
16
- from snowflake.cli.api.plugins.command import (
17
- SNOWCLI_ROOT_COMMAND_PATH,
18
- CommandSpec,
19
- CommandType,
20
- plugin_hook_impl,
21
- )
22
-
23
-
24
- @plugin_hook_impl
25
- def command_spec():
26
- return CommandSpec(
27
- parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
28
- command_type=CommandType.SINGLE_COMMAND,
29
- typer_instance=commands.app.create_instance(),
30
- )
@@ -1,28 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- import string
16
-
17
-
18
- class _SnowSQLTemplate(string.Template):
19
- delimiter = "&"
20
-
21
-
22
- class _Mapper:
23
- def __getitem__(self, item):
24
- return "&{ " + item + " }"
25
-
26
-
27
- def transpile_snowsql_templates(text: str) -> str:
28
- return _SnowSQLTemplate(text).safe_substitute(_Mapper()) # type: ignore[arg-type]
@@ -1,13 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.