Skip to content

Commit 15976d8

Browse files
committed
Rework arguments parsing logic for SHOW FUNCTIONS and SHOW PROCEDURES; Resource constraint is now required for SNOWPARK-OPTIMIZED warehouse; Display active bundles
1 parent 546b15f commit 15976d8

File tree

19 files changed

+146
-29
lines changed

19 files changed

+146
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [0.52.0] - 2025-05-23
4+
5+
- Reworked data type parsing logic for `SHOW FUNCTIONS` and `SHOW PROCEDURES` to prepare for bundle `2025_03` [changes](https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_03/bcr-1944).
6+
- Parameter `resource_constraint` is now required for `SNOWPARK-OPTIMIZED` warehouse. It is necessary to protect from future random changes in default values.
7+
- Added `Active bundles` to context and logging.
8+
- Skipped some checks in tests until bundle `2025_03` is fully deployed. Proposed change is so problematic, I expect it to be partially reverted.
9+
310
## [0.51.1] - 2025-05-20
411

512
- Added temporary workaround for potential new default `resource_constraint=STANDARD_GEN_1` for `STANDARD` warehouses. Previously it was `null`.

snowddl/app/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,24 +635,25 @@ def execute(self):
635635
exit(8)
636636

637637
def output_engine_context(self, engine: SnowDDLEngine):
638-
roles = []
638+
system_roles = []
639639

640640
if engine.context.is_account_admin:
641-
roles.append("ACCOUNTADMIN")
641+
system_roles.append("ACCOUNTADMIN")
642642

643643
if engine.context.is_sys_admin:
644-
roles.append("SYSADMIN")
644+
system_roles.append("SYSADMIN")
645645

646646
if engine.context.is_security_admin:
647-
roles.append("SECURITYADMIN")
647+
system_roles.append("SECURITYADMIN")
648648

649649
self.logger.info(
650650
f"Snowflake version = {engine.context.version} ({engine.context.edition.name}), SnowDDL version = {__version__}"
651651
)
652652
self.logger.info(f"Account = {engine.context.current_account}, Region = {engine.context.current_region}")
653653
self.logger.info(f"Session = {engine.context.current_session}, User = {engine.context.current_user}")
654654
self.logger.info(f"Role = {engine.context.current_role}, Warehouse = {engine.context.current_warehouse}")
655-
self.logger.info(f"Roles in session = {','.join(roles)}")
655+
self.logger.info(f"System roles = {','.join(system_roles)}")
656+
self.logger.info(f"Active bundles = {','.join(engine.context.active_bundles)}")
656657
self.logger.info("---")
657658

658659
def get_placeholder_path(self):

snowddl/context.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, engine: "SnowDDLEngine"):
2323
, IS_ROLE_IN_SESSION('SYSADMIN') AS is_sys_admin
2424
, IS_ROLE_IN_SESSION('SECURITYADMIN') AS is_security_admin
2525
, SYSTEM$BOOTSTRAP_DATA_REQUEST('ACCOUNT') AS bootstrap_account
26+
, SYSTEM$SHOW_ACTIVE_BEHAVIOR_CHANGE_BUNDLES() AS active_bundles
2627
"""
2728
)
2829

@@ -42,9 +43,11 @@ def __init__(self, engine: "SnowDDLEngine"):
4243
self.is_security_admin = r["IS_SECURITY_ADMIN"]
4344

4445
bootstrap_account = loads(r["BOOTSTRAP_ACCOUNT"])
46+
active_bundles = loads(r["ACTIVE_BUNDLES"])
4547

4648
self.version = bootstrap_account["serverVersion"]
4749
self.edition = Edition[bootstrap_account["accountInfo"]["serviceLevelName"]]
50+
self.active_bundles = [bundle["name"] for bundle in active_bundles if bundle["isEnabled"]]
4851

4952
self._validate()
5053

snowddl/resolver/_utils.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,46 @@ def compare_dynamic_param_value(bp_value: Union[bool, int, float, str], existing
2929

3030

3131
def dtypes_from_arguments(arguments: str) -> str:
32-
arguments = arguments.replace("DEFAULT ", "")
33-
arguments = arguments.translate(str.maketrans("", "", "[] "))
32+
all_dtypes = []
3433

3534
start_dtypes_idx = arguments.index("(")
36-
finish_dtypes_idx = arguments.index(")")
35+
finish_dtypes_idx = arguments.index(") RETURN ")
3736

38-
return ",".join(a for a in arguments[start_dtypes_idx + 1 : finish_dtypes_idx].split(","))
37+
for dtype_part in split_by_comma_outside_parentheses(arguments[start_dtypes_idx + 1 : finish_dtypes_idx]):
38+
# Remove optional DEFAULT prefix from the beginning
39+
dtype_part = dtype_part.removeprefix("DEFAULT ")
40+
41+
# Remove optional data type size introduced in bundle 2025_03
42+
# https://docs.snowflake.com/en/release-notes/bcr-bundles/2025_03/bcr-1944
43+
dtype_size_start_idx = dtype_part.find("(")
44+
45+
if dtype_size_start_idx > -1:
46+
dtype_part = dtype_part[:dtype_size_start_idx]
47+
48+
all_dtypes.append(dtype_part)
49+
50+
return ",".join(all_dtypes)
51+
52+
53+
def split_by_comma_outside_parentheses(s: str):
54+
parts = []
55+
current = []
56+
depth = 0
57+
58+
for char in s:
59+
if char == "," and depth == 0:
60+
parts.append("".join(current).strip())
61+
current = []
62+
63+
else:
64+
if char == "(":
65+
depth += 1
66+
elif char == ")":
67+
depth -= 1
68+
69+
current.append(char)
70+
71+
if current:
72+
parts.append("".join(current).strip())
73+
74+
return parts

snowddl/resolver/warehouse.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,8 @@ def _compare_resource_constraint(self, bp: WarehouseBlueprint, row: dict):
276276
return False
277277

278278
# Special rules for RESOURCE_CONSTRAINT are required to take both old and new default logic into account
279-
if bp.resource_constraint is None:
280-
if bp.type == "STANDARD" and row["resource_constraint"] == "STANDARD_GEN_1":
281-
return False
282-
283-
if bp.type == "SNOWPARK-OPTIMIZED" and row["resource_constraint"] == "MEMORY_16X":
284-
return False
279+
if bp.resource_constraint is None and bp.type == "STANDARD" and row["resource_constraint"] == "STANDARD_GEN_1":
280+
return False
285281

286282
return True
287283

snowddl/validator/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
from .technical_role import TechnicalRoleValidator
1010
from .user import UserValidator
1111
from .view import ViewValidator
12+
from .warehouse import WarehouseValidator
1213

1314

1415
default_validate_sequence = [
16+
WarehouseValidator,
1517
DatabaseValidator,
1618
SchemaValidator,
1719
DynamicTableValidator,

snowddl/validator/warehouse.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from snowddl.blueprint import WarehouseBlueprint
2+
from snowddl.validator.abc_validator import AbstractValidator
3+
4+
5+
class WarehouseValidator(AbstractValidator):
6+
def get_blueprints(self):
7+
return self.config.get_blueprints_by_type(WarehouseBlueprint)
8+
9+
def validate_blueprint(self, bp: WarehouseBlueprint):
10+
self._validate_resource_constraint(bp)
11+
12+
def _validate_resource_constraint(self, bp: WarehouseBlueprint):
13+
if bp.type == "SNOWPARK-OPTIMIZED" and bp.resource_constraint is None:
14+
raise ValueError(f"Resource constraint must be defined for SNOWPARK-OPTIMIZED warehouse [{bp.full_name}]")

snowddl/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.51.1"
1+
__version__ = "0.52.0"

test/_config/step1/warehouse.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ wh002_wh1:
5555
wh003_wh1:
5656
size: MEDIUM
5757
type: SNOWPARK-OPTIMIZED
58+
resource_constraint: MEMORY_16X

test/_config/step3/warehouse.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ wh002_wh1:
2828
wh003_wh1:
2929
size: MEDIUM
3030
type: SNOWPARK-OPTIMIZED
31+
resource_constraint: MEMORY_16X

0 commit comments

Comments
 (0)