Skip to content

Commit

Permalink
Introduce custom application and --query-tag CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
littleK0i committed Nov 1, 2023
1 parent c89a119 commit c4c6070
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Changelog

## [0.21.0] - 2023-11-01

- Introduced custom value for application option (`SnowDDL <version>`) while opening Snowflake connection. Now it should be possible to find sessions created by SnowDDL using `SESSIONS` system view.
- Added `--query-tag` CLI option to set custom `QUERY_TAG` session parameter.
- Fixed pydantic deprecation warning related to `__fields__`.
- Added explicit `.close()` call for Snowflake connection after execution of CLI commands. It should help to terminate SnowDDL sessions earlier, regardless of `CLIENT_SESSION_KEEP_ALIVE` parameter.

## [0.20.1] - 2023-10-20

- Add additional debug logs for `VIEW` resolver in attempt to diagnose rare unnecessary re-creation problem.
- Added additional debug logs for `VIEW` resolver in attempt to diagnose rare unnecessary re-creation problem.

## [0.20.0] - 2023-10-13

Expand Down
15 changes: 15 additions & 0 deletions snowddl/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@


class BaseApp:
application_name = "SnowDDL"
application_version = __version__

parser_sequence = default_parser_sequence
resolver_sequence = default_resolver_sequence

Expand Down Expand Up @@ -100,6 +103,11 @@ def init_arguments_parser(self):
parser.add_argument(
"--max-workers", help="Maximum number of workers to resolve objects in parallel", default=None, type=int
)
parser.add_argument(
"--query-tag",
help="Add QUERY_TAG to all queries produced by SnowDDL",
default=environ.get("SNOWFLAKE_QUERY_TAG"),
)

# Logging
parser.add_argument(
Expand Down Expand Up @@ -363,6 +371,7 @@ def get_connection(self):
"user": self.args["u"],
"role": self.args["r"],
"warehouse": self.args["w"],
"application": f"{self.application_name} {self.application_version}",
}

if self.args.get("k"):
Expand All @@ -381,6 +390,11 @@ def get_connection(self):
else:
options["password"] = self.args["p"]

if self.args.get("query_tag"):
options["session_parameters"] = {
"QUERY_TAG": self.args.get("query_tag"),
}

return connect(**options)

def execute(self):
Expand All @@ -407,6 +421,7 @@ def execute(self):

error_count += len(resolver.errors)

self.engine.connection.close()
self.output_engine_stats()

if self.args.get("show_sql"):
Expand Down
2 changes: 1 addition & 1 deletion snowddl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_blueprints_by_type_and_pattern(self, cls: Type[T_Blueprint], pattern: st
type_blueprints = self.blueprints.get(cls, {})

# Add env prefix to pattern IF blueprint supports it
if "full_name" in cls.__fields__ and issubclass(cls.__fields__["full_name"].annotation, AbstractIdentWithPrefix):
if "full_name" in cls.model_fields and issubclass(cls.model_fields["full_name"].annotation, AbstractIdentWithPrefix):
pattern = f"{self.env_prefix}{pattern}"

# Use Unix-style wildcards if any special characters detected in pattern
Expand Down
4 changes: 3 additions & 1 deletion snowddl/resolver/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def compare_object(self, bp: ViewBlueprint, row: dict):
},
)
except SnowDDLExecuteError as e:
self.engine.logger.debug(f"View [{bp.full_name}] caused describe error [{e.snow_exc.errno}]: {e.snow_exc.raw_msg}")
self.engine.logger.debug(
f"View [{bp.full_name}] caused describe error [{e.snow_exc.errno}]: {e.snow_exc.raw_msg}"
)
else:
# Comments on views are broken and must be applied separately
if bp.comment != row["comment"]:
Expand Down
2 changes: 1 addition & 1 deletion snowddl/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.20.1"
__version__ = "0.21.0"

0 comments on commit c4c6070

Please sign in to comment.