snowpark-checkpoints-collectors 0.2.0rc1__py3-none-any.whl → 0.2.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.
Files changed (41) hide show
  1. snowflake/snowpark_checkpoints_collector/__init__.py +30 -0
  2. snowflake/snowpark_checkpoints_collector/__version__.py +16 -0
  3. snowflake/snowpark_checkpoints_collector/collection_common.py +160 -0
  4. snowflake/snowpark_checkpoints_collector/collection_result/model/__init__.py +24 -0
  5. snowflake/snowpark_checkpoints_collector/collection_result/model/collection_point_result.py +91 -0
  6. snowflake/snowpark_checkpoints_collector/collection_result/model/collection_point_result_manager.py +74 -0
  7. snowflake/snowpark_checkpoints_collector/column_collection/__init__.py +22 -0
  8. snowflake/snowpark_checkpoints_collector/column_collection/column_collector_manager.py +276 -0
  9. snowflake/snowpark_checkpoints_collector/column_collection/model/__init__.py +75 -0
  10. snowflake/snowpark_checkpoints_collector/column_collection/model/array_column_collector.py +113 -0
  11. snowflake/snowpark_checkpoints_collector/column_collection/model/binary_column_collector.py +87 -0
  12. snowflake/snowpark_checkpoints_collector/column_collection/model/boolean_column_collector.py +71 -0
  13. snowflake/snowpark_checkpoints_collector/column_collection/model/column_collector_base.py +95 -0
  14. snowflake/snowpark_checkpoints_collector/column_collection/model/date_column_collector.py +74 -0
  15. snowflake/snowpark_checkpoints_collector/column_collection/model/day_time_interval_column_collector.py +67 -0
  16. snowflake/snowpark_checkpoints_collector/column_collection/model/decimal_column_collector.py +92 -0
  17. snowflake/snowpark_checkpoints_collector/column_collection/model/empty_column_collector.py +88 -0
  18. snowflake/snowpark_checkpoints_collector/column_collection/model/map_column_collector.py +120 -0
  19. snowflake/snowpark_checkpoints_collector/column_collection/model/null_column_collector.py +49 -0
  20. snowflake/snowpark_checkpoints_collector/column_collection/model/numeric_column_collector.py +108 -0
  21. snowflake/snowpark_checkpoints_collector/column_collection/model/string_column_collector.py +70 -0
  22. snowflake/snowpark_checkpoints_collector/column_collection/model/struct_column_collector.py +102 -0
  23. snowflake/snowpark_checkpoints_collector/column_collection/model/timestamp_column_collector.py +75 -0
  24. snowflake/snowpark_checkpoints_collector/column_collection/model/timestamp_ntz_column_collector.py +75 -0
  25. snowflake/snowpark_checkpoints_collector/column_pandera_checks/__init__.py +20 -0
  26. snowflake/snowpark_checkpoints_collector/column_pandera_checks/pandera_column_checks_manager.py +241 -0
  27. snowflake/snowpark_checkpoints_collector/singleton.py +23 -0
  28. snowflake/snowpark_checkpoints_collector/snow_connection_model/__init__.py +20 -0
  29. snowflake/snowpark_checkpoints_collector/snow_connection_model/snow_connection.py +201 -0
  30. snowflake/snowpark_checkpoints_collector/summary_stats_collector.py +410 -0
  31. snowflake/snowpark_checkpoints_collector/utils/checkpoint_name_utils.py +53 -0
  32. snowflake/snowpark_checkpoints_collector/utils/extra_config.py +119 -0
  33. snowflake/snowpark_checkpoints_collector/utils/file_utils.py +132 -0
  34. snowflake/snowpark_checkpoints_collector/utils/logging_utils.py +67 -0
  35. snowflake/snowpark_checkpoints_collector/utils/telemetry.py +889 -0
  36. snowpark_checkpoints_collectors-0.2.1.dist-info/METADATA +158 -0
  37. snowpark_checkpoints_collectors-0.2.1.dist-info/RECORD +39 -0
  38. {snowpark_checkpoints_collectors-0.2.0rc1.dist-info → snowpark_checkpoints_collectors-0.2.1.dist-info}/licenses/LICENSE +0 -25
  39. snowpark_checkpoints_collectors-0.2.0rc1.dist-info/METADATA +0 -347
  40. snowpark_checkpoints_collectors-0.2.0rc1.dist-info/RECORD +0 -4
  41. {snowpark_checkpoints_collectors-0.2.0rc1.dist-info → snowpark_checkpoints_collectors-0.2.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,132 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ import inspect
16
+ import os
17
+ import tempfile
18
+
19
+ from typing import Optional
20
+
21
+ from snowflake.snowpark_checkpoints_collector.collection_common import (
22
+ COLLECTION_RESULT_FILE_NAME,
23
+ DOT_IPYNB_EXTENSION,
24
+ SNOWPARK_CHECKPOINTS_OUTPUT_DIRECTORY_NAME,
25
+ UNKNOWN_LINE_OF_CODE,
26
+ UNKNOWN_SOURCE_FILE,
27
+ )
28
+
29
+
30
+ def get_output_file_path(out_path: Optional[str] = None) -> str:
31
+ """Get the output file path.
32
+
33
+ Args:
34
+ out_path (Optional[str], optional): the output path. Defaults to None.
35
+
36
+ Returns:
37
+ str: returns the output file path.
38
+
39
+ """
40
+ output_directory_path = get_output_directory_path(out_path)
41
+ output_file_path = os.path.join(output_directory_path, COLLECTION_RESULT_FILE_NAME)
42
+ return output_file_path
43
+
44
+
45
+ def get_relative_file_path(path: str) -> str:
46
+ """Get the relative file path.
47
+
48
+ Args:
49
+ path (str): a file path.
50
+
51
+ Returns:
52
+ str: returns the relative file path of the given file.
53
+
54
+ """
55
+ relative_file_path = os.path.relpath(path)
56
+ return relative_file_path
57
+
58
+
59
+ def get_output_directory_path(output_path: Optional[str] = None) -> str:
60
+ """Get the output directory path.
61
+
62
+ Returns:
63
+ str: returns the output directory path.
64
+
65
+ """
66
+ current_working_directory_path = output_path if output_path else os.getcwd()
67
+ checkpoints_output_directory_path = os.path.join(
68
+ current_working_directory_path, SNOWPARK_CHECKPOINTS_OUTPUT_DIRECTORY_NAME
69
+ )
70
+ os.makedirs(checkpoints_output_directory_path, exist_ok=True)
71
+ return checkpoints_output_directory_path
72
+
73
+
74
+ def get_collection_point_source_file_path() -> str:
75
+ """Get the path of the source file where collection point it is.
76
+
77
+ Returns:
78
+ str: returns the path of source file where collection point it is.
79
+
80
+ """
81
+ try:
82
+ collection_point_file_path = inspect.stack()[2].filename
83
+ is_temporal_file_path = _is_temporal_path(collection_point_file_path)
84
+ if is_temporal_file_path:
85
+ ipynb_file_path_collection = _get_ipynb_file_path_collection()
86
+ if len(ipynb_file_path_collection) == 1:
87
+ collection_point_file_path = ipynb_file_path_collection[0]
88
+ else:
89
+ collection_point_file_path = UNKNOWN_SOURCE_FILE
90
+
91
+ return collection_point_file_path
92
+
93
+ except Exception:
94
+ return UNKNOWN_SOURCE_FILE
95
+
96
+
97
+ def get_collection_point_line_of_code() -> int:
98
+ """Find the line of code of the source file where collection point it is.
99
+
100
+ Returns:
101
+ int: returns the line of code of the source file where collection point it is.
102
+
103
+ """
104
+ try:
105
+ collection_point_file_path = inspect.stack()[2].filename
106
+ collection_point_line_of_code = inspect.stack()[2].lineno
107
+ is_temporal_file_path = _is_temporal_path(collection_point_file_path)
108
+ if is_temporal_file_path:
109
+ collection_point_line_of_code = UNKNOWN_LINE_OF_CODE
110
+ return collection_point_line_of_code
111
+
112
+ except Exception:
113
+ return UNKNOWN_LINE_OF_CODE
114
+
115
+
116
+ def _is_temporal_path(path: str) -> bool:
117
+ temporal_directory_path = tempfile.gettempdir()
118
+ is_temporal_path = path.startswith(temporal_directory_path)
119
+ return is_temporal_path
120
+
121
+
122
+ def _get_ipynb_file_path_collection() -> list[str]:
123
+ current_working_directory_path = os.getcwd()
124
+ cwd_file_name_collection = os.listdir(current_working_directory_path)
125
+ ipynb_file_path_collection = []
126
+ for file_name in cwd_file_name_collection:
127
+ is_ipynb_file = file_name.endswith(DOT_IPYNB_EXTENSION)
128
+ if is_ipynb_file:
129
+ file_path = os.path.join(current_working_directory_path, file_name)
130
+ ipynb_file_path_collection.append(file_path)
131
+
132
+ return ipynb_file_path_collection
@@ -0,0 +1,67 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import logging
17
+
18
+ from functools import wraps
19
+ from typing import Callable, Optional, TypeVar
20
+
21
+ from typing_extensions import ParamSpec
22
+
23
+
24
+ P = ParamSpec("P")
25
+ R = TypeVar("R")
26
+
27
+
28
+ def log(
29
+ _func: Optional[Callable[P, R]] = None,
30
+ *,
31
+ logger: Optional[logging.Logger] = None,
32
+ log_args: bool = True,
33
+ ) -> Callable[[Callable[P, R]], Callable[P, R]]:
34
+ """Log the function call and any exceptions that occur.
35
+
36
+ Args:
37
+ _func: The function to log.
38
+ logger: The logger to use for logging. If not provided, a logger will be created using the
39
+ function's module name.
40
+ log_args: Whether to log the arguments passed to the function.
41
+
42
+ Returns:
43
+ A decorator that logs the function call and any exceptions that occur.
44
+
45
+ """
46
+
47
+ def decorator(func: Callable[P, R]) -> Callable[P, R]:
48
+ @wraps(func)
49
+ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
50
+ _logger = logging.getLogger(func.__module__) if logger is None else logger
51
+ if log_args:
52
+ args_repr = [repr(a) for a in args]
53
+ kwargs_repr = [f"{k}={v!r}" for k, v in kwargs.items()]
54
+ formatted_args = ", ".join([*args_repr, *kwargs_repr])
55
+ _logger.debug("%s called with args %s", func.__name__, formatted_args)
56
+ try:
57
+ return func(*args, **kwargs)
58
+ except Exception:
59
+ _logger.exception("An error occurred in %s", func.__name__)
60
+ raise
61
+
62
+ return wrapper
63
+
64
+ # Handle the case where the decorator is used without parentheses
65
+ if _func is None:
66
+ return decorator
67
+ return decorator(_func)