Skip to content

Commit

Permalink
Add explicit normalisation for SQL text params in object types like V…
Browse files Browse the repository at this point in the history
…IEW, TASK, etc.
  • Loading branch information
littleK0i committed Jan 29, 2025
1 parent 02ef3bb commit b7a090c
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion snowddl/blueprint/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class PrimaryKeyBlueprint(SchemaObjectBlueprint):
class ProcedureBlueprint(SchemaObjectBlueprint):
full_name: SchemaObjectIdentWithArgs
language: str
body: str
body: Optional[str] = None
arguments: List[ArgumentWithType]
returns: Union[DataType, List[NameWithType]]
is_strict: bool = False
Expand Down
3 changes: 3 additions & 0 deletions snowddl/parser/abc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def add_error(self, exc: Exception, path: Path, entity_name: Optional[str] = Non

self.errors[error_key] = exc

def normalise_sql_text_param(self, text: str):
return text.lstrip(" \t\n\r").rstrip(" \t\n\r;")

def normalise_params_list(self, params):
if params is None:
return None
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/aggregation_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def process_aggregation_policy(self, f: ParsedFile):

bp = AggregationPolicyBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
body=f.params["body"],
body=self.normalise_sql_text_param(f.params["body"]),
references=references,
comment=f.params.get("comment"),
)
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/dynamic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def process_dynamic_table(self, f: ParsedFile):

bp = DynamicTableBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
text=f.params["text"],
text=self.normalise_sql_text_param(f.params["text"]),
columns=column_blueprints if column_blueprints else None,
target_lag=self.normalise_target_lag(f.params["target_lag"]),
warehouse=AccountObjectIdent(self.env_prefix, f.params["warehouse"]),
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/masking_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def process_masking_policy(self, f: ParsedFile):

bp = MaskingPolicyBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
body=f.params["body"],
body=self.normalise_sql_text_param(f.params["body"]),
arguments=arguments,
returns=DataType(f.params["returns"]),
exempt_other_policies=f.params.get("exempt_other_policies", False),
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/materialized_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def process_materialized_view(self, f: ParsedFile):

bp = MaterializedViewBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
text=f.params["text"],
text=self.normalise_sql_text_param(f.params["text"]),
columns=column_blueprints if column_blueprints else None,
is_secure=f.params.get("is_secure", False),
cluster_by=f.params.get("cluster_by"),
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/projection_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def process_projection_policy(self, f: ParsedFile):

bp = ProjectionPolicyBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
body=f.params["body"],
body=self.normalise_sql_text_param(f.params["body"]),
references=references,
comment=f.params.get("comment"),
)
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/row_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def process_row_access_policy(self, f: ParsedFile):

bp = RowAccessPolicyBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
body=f.params["body"],
body=self.normalise_sql_text_param(f.params["body"]),
arguments=arguments,
references=references,
comment=f.params.get("comment"),
Expand Down
3 changes: 2 additions & 1 deletion snowddl/parser/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"type": "string"
}
},
"required": ["body"],
"additionalProperties": False
}
# fmt: on
Expand All @@ -86,7 +87,7 @@ def process_task(self, f: ParsedFile):

bp = TaskBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
body=f.params["body"],
body=self.normalise_sql_text_param(f.params["body"]),
schedule=f.params.get("schedule"),
after=after,
finalize=finalize,
Expand Down
2 changes: 1 addition & 1 deletion snowddl/parser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def process_view(self, f: ParsedFile):

bp = ViewBlueprint(
full_name=SchemaObjectIdent(self.env_prefix, f.database, f.schema, f.name),
text=f.params["text"],
text=self.normalise_sql_text_param(f.params["text"]),
columns=column_blueprints if column_blueprints else None,
is_secure=f.params.get("is_secure", False),
change_tracking=f.params.get("change_tracking", False),
Expand Down

0 comments on commit b7a090c

Please sign in to comment.