flagsmith-sql-flag-engine 0.1.0__tar.gz → 0.1.2__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.
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/PKG-INFO +1 -1
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/pyproject.toml +1 -1
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/translator.py +22 -21
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/README.md +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/__init__.py +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/dialect.py +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/dialects/__init__.py +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/dialects/clickhouse.py +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/py.typed +0 -0
- {flagsmith_sql_flag_engine-0.1.0 → flagsmith_sql_flag_engine-0.1.2}/src/flagsmith_sql_flag_engine/utils.py +0 -0
|
@@ -435,19 +435,13 @@ def translate_condition(cond: SegmentCondition, ctx: TranslateContext) -> str |
|
|
|
435
435
|
identity: dict[str, object] = ctx.evaluation_context.get("identity") or {} # type: ignore[assignment]
|
|
436
436
|
kind = classification.kind
|
|
437
437
|
if not prop:
|
|
438
|
-
#
|
|
439
|
-
# identity,
|
|
440
|
-
#
|
|
441
|
-
if not identity.get("key"):
|
|
442
|
-
return "FALSE"
|
|
438
|
+
# In traditional engine implementations, this branch implies
|
|
439
|
+
# an identity-less context, which makes no sense for the SQL engine.
|
|
440
|
+
# Assume identity key.
|
|
443
441
|
value_expr = ctx.dialect.cast_string(ctx.identity_key_expr)
|
|
444
442
|
elif kind == "key":
|
|
445
|
-
if not identity.get("key"):
|
|
446
|
-
return "FALSE"
|
|
447
443
|
value_expr = ctx.dialect.cast_string(ctx.jsonpath_expr("$.identity.key"))
|
|
448
444
|
elif kind == "identifier":
|
|
449
|
-
if not identity.get("identifier"):
|
|
450
|
-
return "FALSE"
|
|
451
445
|
value_expr = ctx.dialect.cast_string(ctx.jsonpath_expr("$.identity.identifier"))
|
|
452
446
|
elif kind == "identity_object":
|
|
453
447
|
# PERCENTAGE_SPLIT on `$.identity` — the whole dict. Engine
|
|
@@ -517,26 +511,33 @@ def translate_condition(cond: SegmentCondition, ctx: TranslateContext) -> str |
|
|
|
517
511
|
|
|
518
512
|
|
|
519
513
|
def translate_rule(rule: SegmentRule, ctx: TranslateContext) -> str | None:
|
|
520
|
-
|
|
514
|
+
cond_children: list[str] = []
|
|
521
515
|
for cond in rule.get("conditions") or []:
|
|
522
516
|
sql = translate_condition(cond, ctx)
|
|
523
517
|
if sql is None:
|
|
524
518
|
return None
|
|
525
|
-
|
|
519
|
+
cond_children.append(f"({sql})")
|
|
520
|
+
rule_children: list[str] = []
|
|
526
521
|
for nested in rule.get("rules") or []:
|
|
527
522
|
sql = translate_rule(nested, ctx)
|
|
528
523
|
if sql is None:
|
|
529
524
|
return None
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
525
|
+
rule_children.append(f"({sql})")
|
|
526
|
+
|
|
527
|
+
# Mirror the engine's `context_matches_rule`: conditions and nested rules
|
|
528
|
+
# are two independent groups AND-ed together, each vacuously true when
|
|
529
|
+
# empty.
|
|
530
|
+
op = {"ALL": " AND ", "ANY": " OR ", "NONE": " OR "}[rule["type"]]
|
|
531
|
+
groups = [
|
|
532
|
+
f"NOT ({op.join(c)})" if rule["type"] == "NONE" else op.join(c)
|
|
533
|
+
for c in (cond_children, rule_children)
|
|
534
|
+
if c
|
|
535
|
+
]
|
|
536
|
+
if not groups:
|
|
537
|
+
return "TRUE"
|
|
538
|
+
if len(groups) == 1:
|
|
539
|
+
return groups[0]
|
|
540
|
+
return " AND ".join(f"({g})" for g in groups)
|
|
540
541
|
|
|
541
542
|
|
|
542
543
|
def translate_segment(segment: SegmentContext, ctx: TranslateContext) -> str | None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|