Skip to content

Commit

Permalink
Support new AQL operators
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-elimity committed Mar 24, 2023
1 parent 35523a7 commit 59428c0
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/elimity_insights_client/api/_encode_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DateTimeExpression,
DirectLinkAggregateNumberExpression,
DirectlyLinkedToBooleanExpression,
ExistsBooleanExpression,
IdInBooleanExpression,
IdStringExpression,
LinkAggregateNumberExpression,
Expand All @@ -40,6 +41,7 @@
LiteralStringExpression,
LiteralTimeExpression,
MatchBooleanExpression,
MatchesPatternBooleanExpression,
MatchMode,
MatchOperator,
NameStringExpression,
Expand Down Expand Up @@ -109,6 +111,16 @@ def encode_boolean_expression(expression: BooleanExpression) -> object:
"type": "directlyLinkedTo",
}

if isinstance(expression, ExistsBooleanExpression):
condition = encode_boolean_expression(expression.condition)
return {
"alias": expression.alias,
"condition": condition,
"entityType": expression.entity_type,
"sourceId": expression.source_id,
"type": "exists",
}

if isinstance(expression, IdInBooleanExpression):
return {
"ids": expression.ids,
Expand Down Expand Up @@ -154,6 +166,14 @@ def encode_boolean_expression(expression: BooleanExpression) -> object:
"type": "match",
}

if isinstance(expression, MatchesPatternBooleanExpression):
expr = encode_string_expression(expression.expr)
return {
"expr": expr,
"pattern": expression.pattern,
"type": "matchesPattern",
}

if isinstance(expression, NotBooleanExpression):
expr = encode_boolean_expression(expression.expr)
return {"expr": expr, "type": "not"}
Expand Down Expand Up @@ -410,6 +430,9 @@ def _encode_match_operator(operator: MatchOperator) -> object:
if operator is MatchOperator.EQUALS:
return "equals"

if operator is MatchOperator.SPLIT_INTERSECTS:
return "splitIntersects"

if operator is MatchOperator.STARTS_WITH:
return "startsWith"

Expand Down
21 changes: 21 additions & 0 deletions src/elimity_insights_client/api/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ class DirectLinkAggregateNumberExpression:
source_id: int


@dataclass
class ExistsBooleanExpression:
"""Expression evaluating whether a given condition holds for some entity of a given type."""

alias: str
condition: "BooleanExpression"
entity_type: str
source_id: int


@dataclass
class IdInBooleanExpression:
"""Expression evaluating whether an entity's identifier occurs in a given list."""
Expand Down Expand Up @@ -304,9 +314,18 @@ class MatchOperator(Enum):
CONTAINS = auto()
ENDS_WITH = auto()
EQUALS = auto()
SPLIT_INTERSECTS = auto()
STARTS_WITH = auto()


@dataclass
class MatchesPatternBooleanExpression:
"""Expression matching the result of a given expression to a given pattern."""

expr: "StringExpression"
pattern: str


@dataclass
class NameStringExpression:
"""Expression evaluating to a given entity's name."""
Expand Down Expand Up @@ -404,12 +423,14 @@ class TimeCmpBooleanExpression:
DateCmpBooleanExpression,
DateTimeCmpBooleanExpression,
DirectlyLinkedToBooleanExpression,
ExistsBooleanExpression,
IdInBooleanExpression,
LinkAssignedBooleanExpression,
LinkAttributeBooleanExpression,
LinkedToBooleanExpression,
LiteralBooleanExpression,
MatchBooleanExpression,
MatchesPatternBooleanExpression,
NotBooleanExpression,
NumberCmpBooleanExpression,
TimeCmpBooleanExpression,
Expand Down
55 changes: 55 additions & 0 deletions tests/elimity_insights_client/api/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
{
"$ref": "#/definitions/directlyLinkedToBooleanExpression"
},
{
"$ref": "#/definitions/existsBooleanExpression"
},
{
"$ref": "#/definitions/idInBooleanExpression"
},
Expand All @@ -184,6 +187,9 @@
{
"$ref": "#/definitions/matchBooleanExpression"
},
{
"$ref": "#/definitions/matchesPatternBooleanExpression"
},
{
"$ref": "#/definitions/notBooleanExpression"
},
Expand Down Expand Up @@ -493,6 +499,34 @@
],
"type": "object"
},
"existsBooleanExpression": {
"additionalProperties": false,
"properties": {
"alias": {
"type": "string"
},
"condition": {
"$ref": "#/definitions/booleanExpression"
},
"entityType": {
"type": "string"
},
"sourceId": {
"type": "integer"
},
"type": {
"const": "exists"
}
},
"required": [
"alias",
"condition",
"entityType",
"sourceId",
"type"
],
"type": "object"
},
"grouping": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -852,6 +886,26 @@
],
"type": "object"
},
"matchesPatternBooleanExpression": {
"additionalProperties": false,
"properties": {
"expr": {
"$ref": "#/definitions/stringExpression"
},
"pattern": {
"type": "string"
},
"type": {
"const": "matchesPattern"
}
},
"required": [
"expr",
"pattern",
"type"
],
"type": "object"
},
"matchMode": {
"enum": [
"caseInsensitive",
Expand All @@ -863,6 +917,7 @@
"contains",
"endsWith",
"equals",
"splitIntersects",
"startsWith"
]
},
Expand Down

0 comments on commit 59428c0

Please sign in to comment.