data-factory-utils 2.2.0__tar.gz → 2.4.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: data-factory-utils
3
- Version: 2.2.0
3
+ Version: 2.4.0
4
4
  Summary: Utility functions for interacting with data factories.
5
5
  Requires-Dist: boto3>=1.42.8
6
6
  Requires-Dist: boto3-stubs>=1.42.89
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "data-factory-utils"
3
- version = "2.2.0"
3
+ version = "2.4.0"
4
4
  description = "Utility functions for interacting with data factories."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -89,8 +89,9 @@ class WhereSetMembership(NamedTuple):
89
89
  """Config for WHERE IN comparisons."""
90
90
 
91
91
  col: str
92
- set: tuple[str]
92
+ set: tuple[str] | Subquery
93
93
  unquote: bool | None = False
94
+ membership_operator: Literal["IN", "NOT IN"] = "IN"
94
95
  prefix: Literal["AND", "OR", "NOT"] | None = "AND"
95
96
  brackets: Literal["open", "close", "wrap"] | None = None
96
97
 
@@ -529,15 +530,19 @@ def _build_where_set_membership(config: WhereSetMembership) -> str:
529
530
  - WHERE NOT col IN (value, value)
530
531
  """
531
532
  validate_identifier(config.col)
532
- for value in config.set:
533
- validate_identifier(value)
533
+ if not isinstance(config.set, Subquery):
534
+ for value in config.set:
535
+ validate_identifier(value)
534
536
 
535
- if config.unquote:
537
+ if isinstance(config.set, Subquery):
538
+ values = str(config.set)
539
+ query_str = f"{config.col} {config.membership_operator} {values}"
540
+ elif config.unquote:
536
541
  values = ", ".join(config.set)
537
- query_str = f"{config.col} IN ({values})"
542
+ query_str = f"{config.col} {config.membership_operator} ({values})"
538
543
  else:
539
544
  values = ", ".join(f"'{value}'" for value in config.set)
540
- query_str = f'"{config.col}" IN ({values})'
545
+ query_str = f'"{config.col}" {config.membership_operator} ({values})'
541
546
 
542
547
  if config.brackets:
543
548
  query_str = _wrap(loc=config.brackets, text=query_str)
@@ -733,8 +738,8 @@ class Query:
733
738
  msg = "WHERE statement has no valid conditions."
734
739
  raise ValueError(msg)
735
740
 
736
- # first condition cannot have prefix
737
- if i > 0 and condition.prefix:
741
+ # first condition cannot have prefix - unless it's "NOT"
742
+ if (i == 0 and condition.prefix == "NOT") or (i > 0 and condition.prefix):
738
743
  cond_str = f"{condition.prefix} {cond_str}"
739
744
 
740
745
  query_str.append(cond_str)