snowflake-cli-labs 3.0.0rc4__py3-none-any.whl → 3.0.1__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.
- README.md +21 -0
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/METADATA +6 -96
- snowflake_cli_labs-3.0.1.dist-info/RECORD +5 -0
- snowflake/cli/__about__.py +0 -17
- snowflake/cli/__init__.py +0 -13
- snowflake/cli/_app/__init__.py +0 -22
- snowflake/cli/_app/__main__.py +0 -31
- snowflake/cli/_app/api_impl/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
- snowflake/cli/_app/cli_app.py +0 -252
- snowflake/cli/_app/commands_registration/__init__.py +0 -33
- snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
- snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
- snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
- snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
- snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
- snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
- snowflake/cli/_app/constants.py +0 -19
- snowflake/cli/_app/dev/__init__.py +0 -13
- snowflake/cli/_app/dev/commands_structure.py +0 -48
- snowflake/cli/_app/dev/docs/__init__.py +0 -13
- snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
- snowflake/cli/_app/dev/docs/generator.py +0 -35
- snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
- snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
- snowflake/cli/_app/dev/docs/template_utils.py +0 -23
- snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
- snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
- snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
- snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
- snowflake/cli/_app/loggers.py +0 -199
- snowflake/cli/_app/main_typer.py +0 -62
- snowflake/cli/_app/printing.py +0 -181
- snowflake/cli/_app/secret.py +0 -9
- snowflake/cli/_app/snow_connector.py +0 -309
- snowflake/cli/_app/telemetry.py +0 -220
- snowflake/cli/_app/version_check.py +0 -74
- snowflake/cli/_plugins/__init__.py +0 -13
- snowflake/cli/_plugins/connection/__init__.py +0 -13
- snowflake/cli/_plugins/connection/commands.py +0 -353
- snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
- snowflake/cli/_plugins/connection/util.py +0 -195
- snowflake/cli/_plugins/cortex/__init__.py +0 -13
- snowflake/cli/_plugins/cortex/commands.py +0 -332
- snowflake/cli/_plugins/cortex/constants.py +0 -17
- snowflake/cli/_plugins/cortex/manager.py +0 -189
- snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
- snowflake/cli/_plugins/cortex/types.py +0 -22
- snowflake/cli/_plugins/git/__init__.py +0 -13
- snowflake/cli/_plugins/git/commands.py +0 -358
- snowflake/cli/_plugins/git/manager.py +0 -151
- snowflake/cli/_plugins/git/plugin_spec.py +0 -30
- snowflake/cli/_plugins/helpers/__init__.py +0 -13
- snowflake/cli/_plugins/helpers/commands.py +0 -61
- snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
- snowflake/cli/_plugins/init/__init__.py +0 -13
- snowflake/cli/_plugins/init/commands.py +0 -248
- snowflake/cli/_plugins/init/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
- snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
- snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
- snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
- snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
- snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
- snowflake/cli/_plugins/nativeapp/commands.py +0 -559
- snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
- snowflake/cli/_plugins/nativeapp/constants.py +0 -27
- snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
- snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
- snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
- snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
- snowflake/cli/_plugins/nativeapp/manager.py +0 -415
- snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/policy.py +0 -53
- snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
- snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
- snowflake/cli/_plugins/nativeapp/utils.py +0 -98
- snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
- snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
- snowflake/cli/_plugins/notebook/__init__.py +0 -13
- snowflake/cli/_plugins/notebook/commands.py +0 -86
- snowflake/cli/_plugins/notebook/exceptions.py +0 -20
- snowflake/cli/_plugins/notebook/manager.py +0 -71
- snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
- snowflake/cli/_plugins/notebook/types.py +0 -15
- snowflake/cli/_plugins/object/__init__.py +0 -13
- snowflake/cli/_plugins/object/command_aliases.py +0 -95
- snowflake/cli/_plugins/object/commands.py +0 -180
- snowflake/cli/_plugins/object/common.py +0 -85
- snowflake/cli/_plugins/object/manager.py +0 -118
- snowflake/cli/_plugins/object/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/commands.py +0 -450
- snowflake/cli/_plugins/snowpark/common.py +0 -268
- snowflake/cli/_plugins/snowpark/models.py +0 -150
- snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
- snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
- snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
- snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
- snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
- snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
- snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
- snowflake/cli/_plugins/snowpark/zipper.py +0 -89
- snowflake/cli/_plugins/spcs/__init__.py +0 -33
- snowflake/cli/_plugins/spcs/common.py +0 -99
- snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
- snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
- snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
- snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
- snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
- snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
- snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
- snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/services/commands.py +0 -345
- snowflake/cli/_plugins/spcs/services/manager.py +0 -208
- snowflake/cli/_plugins/sql/__init__.py +0 -13
- snowflake/cli/_plugins/sql/commands.py +0 -86
- snowflake/cli/_plugins/sql/manager.py +0 -92
- snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
- snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
- snowflake/cli/_plugins/stage/__init__.py +0 -13
- snowflake/cli/_plugins/stage/commands.py +0 -264
- snowflake/cli/_plugins/stage/diff.py +0 -280
- snowflake/cli/_plugins/stage/manager.py +0 -582
- snowflake/cli/_plugins/stage/md5.py +0 -160
- snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
- snowflake/cli/_plugins/stage/utils.py +0 -54
- snowflake/cli/_plugins/streamlit/__init__.py +0 -13
- snowflake/cli/_plugins/streamlit/commands.py +0 -195
- snowflake/cli/_plugins/streamlit/manager.py +0 -220
- snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
- snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
- snowflake/cli/_plugins/workspace/__init__.py +0 -13
- snowflake/cli/_plugins/workspace/action_context.py +0 -18
- snowflake/cli/_plugins/workspace/commands.py +0 -306
- snowflake/cli/_plugins/workspace/manager.py +0 -74
- snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
- snowflake/cli/api/__init__.py +0 -48
- snowflake/cli/api/cli_global_context.py +0 -247
- snowflake/cli/api/commands/__init__.py +0 -13
- snowflake/cli/api/commands/alias.py +0 -23
- snowflake/cli/api/commands/common.py +0 -25
- snowflake/cli/api/commands/decorators.py +0 -369
- snowflake/cli/api/commands/execution_metadata.py +0 -40
- snowflake/cli/api/commands/experimental_behaviour.py +0 -18
- snowflake/cli/api/commands/flags.py +0 -561
- snowflake/cli/api/commands/overrideable_parameter.py +0 -143
- snowflake/cli/api/commands/snow_typer.py +0 -247
- snowflake/cli/api/commands/utils.py +0 -18
- snowflake/cli/api/config.py +0 -380
- snowflake/cli/api/connections.py +0 -216
- snowflake/cli/api/console/__init__.py +0 -17
- snowflake/cli/api/console/abc.py +0 -94
- snowflake/cli/api/console/console.py +0 -134
- snowflake/cli/api/console/enum.py +0 -17
- snowflake/cli/api/constants.py +0 -90
- snowflake/cli/api/entities/common.py +0 -56
- snowflake/cli/api/entities/utils.py +0 -370
- snowflake/cli/api/errno.py +0 -28
- snowflake/cli/api/exceptions.py +0 -190
- snowflake/cli/api/feature_flags.py +0 -54
- snowflake/cli/api/identifiers.py +0 -190
- snowflake/cli/api/metrics.py +0 -92
- snowflake/cli/api/output/__init__.py +0 -13
- snowflake/cli/api/output/formats.py +0 -20
- snowflake/cli/api/output/types.py +0 -118
- snowflake/cli/api/plugins/__init__.py +0 -13
- snowflake/cli/api/plugins/command/__init__.py +0 -72
- snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
- snowflake/cli/api/plugins/plugin_config.py +0 -32
- snowflake/cli/api/project/__init__.py +0 -13
- snowflake/cli/api/project/definition.py +0 -126
- snowflake/cli/api/project/definition_conversion.py +0 -395
- snowflake/cli/api/project/definition_manager.py +0 -145
- snowflake/cli/api/project/errors.py +0 -56
- snowflake/cli/api/project/project_verification.py +0 -23
- snowflake/cli/api/project/schemas/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/common.py +0 -153
- snowflake/cli/api/project/schemas/entities/entities.py +0 -61
- snowflake/cli/api/project/schemas/project_definition.py +0 -330
- snowflake/cli/api/project/schemas/template.py +0 -77
- snowflake/cli/api/project/schemas/updatable_model.py +0 -202
- snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
- snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
- snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
- snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
- snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
- snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
- snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
- snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
- snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
- snowflake/cli/api/project/util.py +0 -278
- snowflake/cli/api/rendering/__init__.py +0 -13
- snowflake/cli/api/rendering/jinja.py +0 -118
- snowflake/cli/api/rendering/project_definition_templates.py +0 -43
- snowflake/cli/api/rendering/project_templates.py +0 -98
- snowflake/cli/api/rendering/sql_templates.py +0 -105
- snowflake/cli/api/rest_api.py +0 -178
- snowflake/cli/api/sanitizers.py +0 -43
- snowflake/cli/api/secure_path.py +0 -360
- snowflake/cli/api/secure_utils.py +0 -118
- snowflake/cli/api/sql_execution.py +0 -280
- snowflake/cli/api/utils/__init__.py +0 -13
- snowflake/cli/api/utils/cursor.py +0 -34
- snowflake/cli/api/utils/definition_rendering.py +0 -415
- snowflake/cli/api/utils/dict_utils.py +0 -73
- snowflake/cli/api/utils/error_handling.py +0 -23
- snowflake/cli/api/utils/graph.py +0 -97
- snowflake/cli/api/utils/models.py +0 -63
- snowflake/cli/api/utils/naming_utils.py +0 -13
- snowflake/cli/api/utils/path_utils.py +0 -36
- snowflake/cli/api/utils/templating_functions.py +0 -144
- snowflake/cli/api/utils/types.py +0 -35
- snowflake_cli_labs-3.0.0rc4.dist-info/RECORD +0 -242
- snowflake_cli_labs-3.0.0rc4.dist-info/entry_points.txt +0 -2
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/licenses/LICENSE +0 -0
snowflake/cli/api/exceptions.py
DELETED
|
@@ -1,190 +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 Optional
|
|
19
|
-
|
|
20
|
-
from click.exceptions import ClickException, UsageError
|
|
21
|
-
from snowflake.cli.api.constants import ObjectType
|
|
22
|
-
from snowflake.connector.compat import IS_WINDOWS
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class EnvironmentVariableNotFoundError(ClickException):
|
|
26
|
-
def __init__(self, env_variable_name: str):
|
|
27
|
-
super().__init__(f"Environment variable {env_variable_name} not found")
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class MissingConfiguration(ClickException):
|
|
31
|
-
pass
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class CycleDetectedError(ClickException):
|
|
35
|
-
pass
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
class InvalidTemplate(ClickException):
|
|
39
|
-
pass
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class InvalidConnectionConfiguration(ClickException):
|
|
43
|
-
def format_message(self):
|
|
44
|
-
return f"Invalid connection configuration. {self.message}"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class InvalidLogsConfiguration(ClickException):
|
|
48
|
-
def format_message(self):
|
|
49
|
-
return f"Invalid logs configuration. {self.message}"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class InvalidPluginConfiguration(ClickException):
|
|
53
|
-
def format_message(self):
|
|
54
|
-
return f"Invalid plugin configuration. {self.message}"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class SnowflakeConnectionError(ClickException):
|
|
58
|
-
def __init__(self, snowflake_err: Exception):
|
|
59
|
-
super().__init__(f"Could not connect to Snowflake. Reason: {snowflake_err}")
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class UnsupportedConfigSectionTypeError(Exception):
|
|
63
|
-
def __init__(self, section_type: type):
|
|
64
|
-
super().__init__(f"Unsupported configuration section type {section_type}")
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
class OutputDataTypeError(ClickException):
|
|
68
|
-
def __init__(self, got_type: type, expected_type: type):
|
|
69
|
-
super().__init__(f"Got {got_type} type but expected {expected_type}")
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
class CommandReturnTypeError(ClickException):
|
|
73
|
-
def __init__(self, got_type: type):
|
|
74
|
-
super().__init__(f"Commands have to return OutputData type, but got {got_type}")
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class SnowflakeSQLExecutionError(ClickException):
|
|
78
|
-
"""
|
|
79
|
-
Could not successfully execute the Snowflake SQL statements.
|
|
80
|
-
"""
|
|
81
|
-
|
|
82
|
-
def __init__(self, queries: Optional[str] = None):
|
|
83
|
-
super().__init__(
|
|
84
|
-
f"""
|
|
85
|
-
{self.__doc__}
|
|
86
|
-
{queries if queries else ""}
|
|
87
|
-
"""
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
class ObjectAlreadyExistsError(ClickException):
|
|
92
|
-
def __init__(
|
|
93
|
-
self,
|
|
94
|
-
object_type: ObjectType,
|
|
95
|
-
name: str,
|
|
96
|
-
replace_available: bool = False,
|
|
97
|
-
):
|
|
98
|
-
msg = f"{str(object_type).capitalize()} {name} already exists."
|
|
99
|
-
if replace_available:
|
|
100
|
-
msg += " Use --replace flag to update objects."
|
|
101
|
-
super().__init__(msg)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
class NoProjectDefinitionError(ClickException):
|
|
105
|
-
def __init__(self, project_type: str, project_root: str | Path):
|
|
106
|
-
super().__init__(
|
|
107
|
-
f"No {project_type} project definition found in {project_root}"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
class InvalidProjectDefinitionVersionError(ClickException):
|
|
112
|
-
def __init__(self, expected_version: str, actual_version: str):
|
|
113
|
-
super().__init__(
|
|
114
|
-
f"This command only supports definition version {expected_version}, got {actual_version}."
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
class InvalidSchemaError(ClickException):
|
|
119
|
-
def __init__(self, schema: str):
|
|
120
|
-
super().__init__(f"Invalid schema {schema}")
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
class SecretsWithoutExternalAccessIntegrationError(ClickException):
|
|
124
|
-
def __init__(self, object_name: str):
|
|
125
|
-
super().__init__(
|
|
126
|
-
f"{object_name} defined with secrets but without external integration."
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
class FileTooLargeError(ClickException):
|
|
131
|
-
def __init__(self, path: Path, size_limit_in_kb: int):
|
|
132
|
-
super().__init__(
|
|
133
|
-
f"File {path} is too large (size limit: {size_limit_in_kb} KB)"
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
class DirectoryIsNotEmptyError(ClickException):
|
|
138
|
-
def __init__(self, path: Path):
|
|
139
|
-
super().__init__(f"Directory '{path}' is not empty")
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
class ConfigFileTooWidePermissionsError(ClickException):
|
|
143
|
-
def __init__(self, path: Path):
|
|
144
|
-
change_permissons_command = (
|
|
145
|
-
f'icacls "{path}" /deny <USER_ID>:F'
|
|
146
|
-
if IS_WINDOWS
|
|
147
|
-
else f'chmod 0600 "{path}"'
|
|
148
|
-
)
|
|
149
|
-
msg = f"Configuration file {path} has too wide permissions, run `{change_permissons_command}`."
|
|
150
|
-
if IS_WINDOWS:
|
|
151
|
-
msg += (
|
|
152
|
-
f'\nTo check which users have access to the file run `icacls "{path}"`.'
|
|
153
|
-
"Run the above command for all users except you and administrators."
|
|
154
|
-
)
|
|
155
|
-
super().__init__(msg)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
class DatabaseNotProvidedError(ClickException):
|
|
159
|
-
def __init__(self):
|
|
160
|
-
super().__init__(
|
|
161
|
-
"Database not specified. Please update connection to add `database` parameter, or re-run command using `--database` option. Use `snow connection list` to list existing connections."
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
class SchemaNotProvidedError(ClickException):
|
|
166
|
-
def __init__(self):
|
|
167
|
-
super().__init__(
|
|
168
|
-
"Schema not specified. Please update connection to add `schema` parameter, or re-run command using `--schema` option. Use `snow connection list` to list existing connections."
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
class FQNNameError(ClickException):
|
|
173
|
-
def __init__(self, name: str):
|
|
174
|
-
super().__init__(f"Specified name '{name}' is not valid name.")
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
class FQNInconsistencyError(ClickException):
|
|
178
|
-
def __init__(self, part: str, name: str):
|
|
179
|
-
super().__init__(
|
|
180
|
-
f"{part.capitalize()} provided but name '{name}' is fully qualified name."
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
class IncompatibleParametersError(UsageError):
|
|
185
|
-
def __init__(self, options: list[str]):
|
|
186
|
-
options_with_quotes = [f"'{option}'" for option in options]
|
|
187
|
-
comma_separated_options = ", ".join(options_with_quotes[:-1])
|
|
188
|
-
super().__init__(
|
|
189
|
-
f"Parameters {comma_separated_options} and {options_with_quotes[-1]} are incompatible and cannot be used simultaneously."
|
|
190
|
-
)
|
|
@@ -1,54 +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 enum import Enum, unique
|
|
16
|
-
from typing import NamedTuple
|
|
17
|
-
|
|
18
|
-
from snowflake.cli.api.config import (
|
|
19
|
-
FEATURE_FLAGS_SECTION_PATH,
|
|
20
|
-
get_config_bool_value,
|
|
21
|
-
get_env_variable_name,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class BooleanFlag(NamedTuple):
|
|
26
|
-
name: str
|
|
27
|
-
default: bool = False
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@unique
|
|
31
|
-
class FeatureFlagMixin(Enum):
|
|
32
|
-
def is_enabled(self) -> bool:
|
|
33
|
-
return get_config_bool_value(
|
|
34
|
-
*FEATURE_FLAGS_SECTION_PATH,
|
|
35
|
-
key=self.value.name.lower(),
|
|
36
|
-
default=self.value.default,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
def is_disabled(self):
|
|
40
|
-
return not self.is_enabled()
|
|
41
|
-
|
|
42
|
-
def env_variable(self):
|
|
43
|
-
return get_env_variable_name(*FEATURE_FLAGS_SECTION_PATH, key=self.value.name)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@unique
|
|
47
|
-
class FeatureFlag(FeatureFlagMixin):
|
|
48
|
-
ENABLE_STREAMLIT_EMBEDDED_STAGE = BooleanFlag(
|
|
49
|
-
"ENABLE_STREAMLIT_EMBEDDED_STAGE", False
|
|
50
|
-
)
|
|
51
|
-
ENABLE_STREAMLIT_NO_CHECKOUTS = BooleanFlag("ENABLE_STREAMLIT_NO_CHECKOUTS", False)
|
|
52
|
-
ENABLE_STREAMLIT_VERSIONED_STAGE = BooleanFlag(
|
|
53
|
-
"ENABLE_STREAMLIT_VERSIONED_STAGE", False
|
|
54
|
-
)
|
snowflake/cli/api/identifiers.py
DELETED
|
@@ -1,190 +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 re
|
|
18
|
-
|
|
19
|
-
from click import ClickException
|
|
20
|
-
from snowflake.cli.api.exceptions import FQNInconsistencyError, FQNNameError
|
|
21
|
-
from snowflake.cli.api.project.schemas.v1.identifier_model import (
|
|
22
|
-
ObjectIdentifierBaseModel,
|
|
23
|
-
)
|
|
24
|
-
from snowflake.cli.api.project.util import VALID_IDENTIFIER_REGEX, identifier_for_url
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class FQN:
|
|
28
|
-
"""
|
|
29
|
-
Class representing an identifier and supporting fully qualified names.
|
|
30
|
-
|
|
31
|
-
The instance supports builder pattern that allows updating the identifier with database and
|
|
32
|
-
schema from different sources. For example:
|
|
33
|
-
|
|
34
|
-
fqn = FQN.from_string("my_schema.object").using_connection(conn)
|
|
35
|
-
fqn = FQN.from_identifier_model(cli_context.project_definition.streamlit).using_context()
|
|
36
|
-
fqn = FQN.from_string("my_name").set_database("db").set_schema("foo")
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
def __init__(
|
|
40
|
-
self,
|
|
41
|
-
database: str | None,
|
|
42
|
-
schema: str | None,
|
|
43
|
-
name: str,
|
|
44
|
-
signature: str | None = None,
|
|
45
|
-
):
|
|
46
|
-
self._database = database
|
|
47
|
-
self._schema = schema
|
|
48
|
-
self._name = name
|
|
49
|
-
self.signature = signature
|
|
50
|
-
|
|
51
|
-
@property
|
|
52
|
-
def database(self) -> str | None:
|
|
53
|
-
return self._database
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def schema(self) -> str | None:
|
|
57
|
-
return self._schema
|
|
58
|
-
|
|
59
|
-
@property
|
|
60
|
-
def name(self) -> str:
|
|
61
|
-
return self._name
|
|
62
|
-
|
|
63
|
-
@property
|
|
64
|
-
def prefix(self) -> str:
|
|
65
|
-
if self.database:
|
|
66
|
-
return f"{self.database}.{self.schema if self.schema else 'PUBLIC'}"
|
|
67
|
-
if self.schema:
|
|
68
|
-
return f"{self.schema}"
|
|
69
|
-
return ""
|
|
70
|
-
|
|
71
|
-
@property
|
|
72
|
-
def identifier(self) -> str:
|
|
73
|
-
if self.prefix:
|
|
74
|
-
return f"{self.prefix}.{self.name}"
|
|
75
|
-
return self.name
|
|
76
|
-
|
|
77
|
-
@property
|
|
78
|
-
def url_identifier(self) -> str:
|
|
79
|
-
return ".".join(identifier_for_url(part) for part in self.identifier.split("."))
|
|
80
|
-
|
|
81
|
-
@property
|
|
82
|
-
def sql_identifier(self) -> str:
|
|
83
|
-
if self.signature:
|
|
84
|
-
return f"IDENTIFIER('{self.identifier}'){self.signature}"
|
|
85
|
-
return f"IDENTIFIER('{self.identifier}')"
|
|
86
|
-
|
|
87
|
-
def __str__(self):
|
|
88
|
-
return self.identifier
|
|
89
|
-
|
|
90
|
-
def __eq__(self, other):
|
|
91
|
-
return self.identifier == other.identifier
|
|
92
|
-
|
|
93
|
-
@classmethod
|
|
94
|
-
def from_string(cls, identifier: str) -> "FQN":
|
|
95
|
-
"""
|
|
96
|
-
Takes in an object name in the form [[database.]schema.]name. Returns a FQN instance.
|
|
97
|
-
"""
|
|
98
|
-
qualifier_pattern = rf"(?:(?P<first_qualifier>{VALID_IDENTIFIER_REGEX})\.)?(?:(?P<second_qualifier>{VALID_IDENTIFIER_REGEX})\.)?(?P<name>{VALID_IDENTIFIER_REGEX})(?P<signature>\(.*\))?"
|
|
99
|
-
result = re.fullmatch(qualifier_pattern, identifier)
|
|
100
|
-
|
|
101
|
-
if result is None:
|
|
102
|
-
raise FQNNameError(identifier)
|
|
103
|
-
|
|
104
|
-
unqualified_name = result.group("name")
|
|
105
|
-
if result.group("second_qualifier") is not None:
|
|
106
|
-
database = result.group("first_qualifier")
|
|
107
|
-
schema = result.group("second_qualifier")
|
|
108
|
-
else:
|
|
109
|
-
database = None
|
|
110
|
-
schema = result.group("first_qualifier")
|
|
111
|
-
|
|
112
|
-
signature = None
|
|
113
|
-
if result.group("signature"):
|
|
114
|
-
signature = result.group("signature")
|
|
115
|
-
return cls(
|
|
116
|
-
name=unqualified_name, schema=schema, database=database, signature=signature
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
@classmethod
|
|
120
|
-
def from_stage(cls, stage: str) -> "FQN":
|
|
121
|
-
name = stage
|
|
122
|
-
if stage.startswith("@"):
|
|
123
|
-
name = stage[1:]
|
|
124
|
-
return cls.from_string(name)
|
|
125
|
-
|
|
126
|
-
@classmethod
|
|
127
|
-
def from_identifier_model_v1(cls, model: ObjectIdentifierBaseModel) -> "FQN":
|
|
128
|
-
"""Create an instance from object model."""
|
|
129
|
-
if not isinstance(model, ObjectIdentifierBaseModel):
|
|
130
|
-
raise ClickException(
|
|
131
|
-
f"Expected {type(ObjectIdentifierBaseModel).__name__}, got {model}."
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
fqn = cls.from_string(model.name)
|
|
135
|
-
|
|
136
|
-
if fqn.database and model.database:
|
|
137
|
-
raise FQNInconsistencyError("database", model.name)
|
|
138
|
-
if fqn.schema and model.schema_name:
|
|
139
|
-
raise FQNInconsistencyError("schema", model.name)
|
|
140
|
-
|
|
141
|
-
return fqn.set_database(model.database).set_schema(model.schema_name)
|
|
142
|
-
|
|
143
|
-
@classmethod
|
|
144
|
-
def from_identifier_model_v2(cls, model) -> "FQN":
|
|
145
|
-
"""Create an instance from object model."""
|
|
146
|
-
from snowflake.cli.api.project.schemas.entities.common import Identifier
|
|
147
|
-
|
|
148
|
-
if not isinstance(model, Identifier):
|
|
149
|
-
raise ClickException(f"Expected {type(Identifier).__name__}, got {model}.")
|
|
150
|
-
|
|
151
|
-
fqn = cls.from_string(model.name)
|
|
152
|
-
|
|
153
|
-
if fqn.database and model.database:
|
|
154
|
-
raise FQNInconsistencyError("database", model.name)
|
|
155
|
-
if fqn.schema and model.schema_:
|
|
156
|
-
raise FQNInconsistencyError("schema", model.name)
|
|
157
|
-
|
|
158
|
-
return fqn.set_database(model.database).set_schema(model.schema_)
|
|
159
|
-
|
|
160
|
-
def set_database(self, database: str | None) -> "FQN":
|
|
161
|
-
if database:
|
|
162
|
-
self._database = database
|
|
163
|
-
return self
|
|
164
|
-
|
|
165
|
-
def set_schema(self, schema: str | None) -> "FQN":
|
|
166
|
-
if schema:
|
|
167
|
-
self._schema = schema
|
|
168
|
-
return self
|
|
169
|
-
|
|
170
|
-
def set_name(self, name: str) -> "FQN":
|
|
171
|
-
self._name = name
|
|
172
|
-
return self
|
|
173
|
-
|
|
174
|
-
def using_connection(self, conn) -> "FQN":
|
|
175
|
-
"""Update the instance with database and schema from connection."""
|
|
176
|
-
# Update the identifier only it if wasn't already a qualified name
|
|
177
|
-
if conn.database and not self.database:
|
|
178
|
-
self.set_database(conn.database)
|
|
179
|
-
if conn.schema and not self.schema:
|
|
180
|
-
self.set_schema(conn.schema)
|
|
181
|
-
return self
|
|
182
|
-
|
|
183
|
-
def using_context(self) -> "FQN":
|
|
184
|
-
"""Update the instance with database and schema from connection in current cli context."""
|
|
185
|
-
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
186
|
-
|
|
187
|
-
return self.using_connection(get_cli_context().connection)
|
|
188
|
-
|
|
189
|
-
def to_dict(self) -> dict:
|
|
190
|
-
return {"name": self.name, "schema": self.schema, "database": self.database}
|
snowflake/cli/api/metrics.py
DELETED
|
@@ -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 typing import Dict, Optional
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class _TypePrefix:
|
|
19
|
-
FEATURES = "features"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class _DomainPrefix:
|
|
23
|
-
GLOBAL = "global"
|
|
24
|
-
APP = "app"
|
|
25
|
-
SQL = "sql"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class CLICounterField:
|
|
29
|
-
"""
|
|
30
|
-
for each counter field we're adopting a convention of
|
|
31
|
-
<type>.<domain>.<name>
|
|
32
|
-
for example, if we're tracking a global feature, then the field name would be
|
|
33
|
-
features.global.feature_name
|
|
34
|
-
|
|
35
|
-
The metrics API is implemented to be generic, but we are adopting a convention
|
|
36
|
-
for feature tracking with the following model for a given command execution:
|
|
37
|
-
* counter not present -> feature is not available
|
|
38
|
-
* counter == 0 -> feature is available, but not used
|
|
39
|
-
* counter == 1 -> feature is used
|
|
40
|
-
this makes it easy to compute percentages for feature dashboards in Snowsight
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
TEMPLATES_PROCESSOR = (
|
|
44
|
-
f"{_TypePrefix.FEATURES}.{_DomainPrefix.GLOBAL}.templates_processor"
|
|
45
|
-
)
|
|
46
|
-
SQL_TEMPLATES = f"{_TypePrefix.FEATURES}.{_DomainPrefix.SQL}.sql_templates"
|
|
47
|
-
PDF_TEMPLATES = f"{_TypePrefix.FEATURES}.{_DomainPrefix.GLOBAL}.pdf_templates"
|
|
48
|
-
SNOWPARK_PROCESSOR = (
|
|
49
|
-
f"{_TypePrefix.FEATURES}.{_DomainPrefix.APP}.snowpark_processor"
|
|
50
|
-
)
|
|
51
|
-
POST_DEPLOY_SCRIPTS = (
|
|
52
|
-
f"{_TypePrefix.FEATURES}.{_DomainPrefix.APP}.post_deploy_scripts"
|
|
53
|
-
)
|
|
54
|
-
PACKAGE_SCRIPTS = f"{_TypePrefix.FEATURES}.{_DomainPrefix.APP}.package_scripts"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class CLIMetrics:
|
|
58
|
-
"""
|
|
59
|
-
Class to track various metrics across the execution of a command
|
|
60
|
-
"""
|
|
61
|
-
|
|
62
|
-
def __init__(self):
|
|
63
|
-
self._counters: Dict[str, int] = {}
|
|
64
|
-
|
|
65
|
-
def __eq__(self, other):
|
|
66
|
-
if isinstance(other, CLIMetrics):
|
|
67
|
-
return self._counters == other._counters
|
|
68
|
-
return False
|
|
69
|
-
|
|
70
|
-
def get_counter(self, name: str) -> Optional[int]:
|
|
71
|
-
return self._counters.get(name)
|
|
72
|
-
|
|
73
|
-
def set_counter(self, name: str, value: int) -> None:
|
|
74
|
-
self._counters[name] = value
|
|
75
|
-
|
|
76
|
-
def set_counter_default(self, name: str, value: int) -> None:
|
|
77
|
-
"""
|
|
78
|
-
sets the counter if it does not already exist
|
|
79
|
-
"""
|
|
80
|
-
if name not in self._counters:
|
|
81
|
-
self.set_counter(name, value)
|
|
82
|
-
|
|
83
|
-
def increment_counter(self, name: str, value: int = 1) -> None:
|
|
84
|
-
if name not in self._counters:
|
|
85
|
-
self.set_counter(name, value)
|
|
86
|
-
else:
|
|
87
|
-
self._counters[name] += value
|
|
88
|
-
|
|
89
|
-
@property
|
|
90
|
-
def counters(self) -> Dict[str, int]:
|
|
91
|
-
# return a copy of the original dict to avoid mutating the original
|
|
92
|
-
return self._counters.copy()
|
|
@@ -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,20 +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 enum import Enum
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class OutputFormat(Enum):
|
|
19
|
-
TABLE = "TABLE"
|
|
20
|
-
JSON = "JSON"
|
|
@@ -1,118 +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
|
-
import typing as t
|
|
19
|
-
|
|
20
|
-
from snowflake.connector import DictCursor
|
|
21
|
-
from snowflake.connector.cursor import SnowflakeCursor
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
class CommandResult:
|
|
25
|
-
@property
|
|
26
|
-
def result(self):
|
|
27
|
-
raise NotImplementedError()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class ObjectResult(CommandResult):
|
|
31
|
-
def __init__(self, element: t.Dict):
|
|
32
|
-
self._element = element
|
|
33
|
-
|
|
34
|
-
@property
|
|
35
|
-
def result(self):
|
|
36
|
-
return self._element
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class CollectionResult(CommandResult):
|
|
40
|
-
def __init__(self, elements: t.Iterable[t.Dict]):
|
|
41
|
-
self._elements = elements
|
|
42
|
-
|
|
43
|
-
@property
|
|
44
|
-
def result(self):
|
|
45
|
-
yield from self._elements
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
class MultipleResults(CommandResult):
|
|
49
|
-
def __init__(self, elements: t.Iterable[CommandResult] | None = None):
|
|
50
|
-
self._elements = elements or []
|
|
51
|
-
|
|
52
|
-
def add(self, element: CommandResult):
|
|
53
|
-
self._elements.append(element) # type: ignore
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def result(self):
|
|
57
|
-
return (element for element in self._elements)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
class StreamResult(CommandResult):
|
|
61
|
-
def __init__(self, generator: t.Generator[CommandResult, None, None]):
|
|
62
|
-
self._generator = generator
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def result(self):
|
|
66
|
-
return self._generator
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
class QueryResult(CollectionResult):
|
|
70
|
-
def __init__(self, cursor: SnowflakeCursor | DictCursor):
|
|
71
|
-
self.column_names = [col.name for col in cursor.description]
|
|
72
|
-
super().__init__(elements=self._prepare_payload(cursor))
|
|
73
|
-
self._query = cursor.query
|
|
74
|
-
|
|
75
|
-
def _prepare_payload(self, cursor: SnowflakeCursor | DictCursor):
|
|
76
|
-
if isinstance(cursor, DictCursor):
|
|
77
|
-
return (k for k in cursor)
|
|
78
|
-
return ({k: v for k, v in zip(self.column_names, row)} for row in cursor)
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def query(self):
|
|
82
|
-
return self._query
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class SingleQueryResult(ObjectResult):
|
|
86
|
-
def __init__(self, cursor: SnowflakeCursor):
|
|
87
|
-
super().__init__(element=self._prepare_payload(cursor))
|
|
88
|
-
|
|
89
|
-
def _prepare_payload(self, cursor):
|
|
90
|
-
results = list(QueryResult(cursor).result)
|
|
91
|
-
if results:
|
|
92
|
-
return results[0]
|
|
93
|
-
return None
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class QueryJsonValueResult(QueryResult):
|
|
97
|
-
def __init__(self, cursor: SnowflakeCursor):
|
|
98
|
-
super().__init__(cursor)
|
|
99
|
-
|
|
100
|
-
def _prepare_payload(self, cursor):
|
|
101
|
-
results = list(QueryResult(cursor).result)
|
|
102
|
-
if results:
|
|
103
|
-
# Return value of the first tuple
|
|
104
|
-
return json.loads(list(results[0].items())[0][1])
|
|
105
|
-
return None
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
class MessageResult(CommandResult):
|
|
109
|
-
def __init__(self, message: str):
|
|
110
|
-
self._message = message
|
|
111
|
-
|
|
112
|
-
@property
|
|
113
|
-
def message(self):
|
|
114
|
-
return self._message
|
|
115
|
-
|
|
116
|
-
@property
|
|
117
|
-
def result(self):
|
|
118
|
-
return {"message": self._message}
|
|
@@ -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.
|