Skip to content

Commit 4b9e590

Browse files
author
oleksandr.volha
committed
resolve conflicts
2 parents 40f8c29 + b0a757f commit 4b9e590

File tree

10 files changed

+108
-14
lines changed

10 files changed

+108
-14
lines changed

uncoder-core/app/translator/core/custom_types/functions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
class FunctionType(CustomEnum):
55
avg = "avg"
66
count = "count"
7+
distinct_count = "distinct_count"
8+
earliest = "earliest"
9+
eval = "eval"
10+
fields = "fields"
11+
latest = "latest"
712
max = "max"
813
min = "min"
14+
rename = "rename"
915
search = "search"
1016
sort = "sort"
1117
stats = "stats"
1218
sum = "sum"
1319
table = "table"
20+
values = "values"

uncoder-core/app/translator/core/custom_types/tokens.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class OperatorType(CustomEnum):
2323
REGEX = "re"
2424
NOT_REGEX = "not re"
2525
KEYWORD = "keyword"
26+
IS_NONE = "is none"
27+
IS_NOT_NONE = "is not none"
2628

2729

2830
class GroupType(CustomEnum):

uncoder-core/app/translator/core/functions.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,55 @@
1818

1919
from __future__ import annotations
2020

21+
import re
2122
from abc import ABC, abstractmethod
23+
from dataclasses import dataclass
2224
from functools import cached_property
23-
from typing import TYPE_CHECKING, Optional
25+
from typing import TYPE_CHECKING, Any, Optional
2426

2527
from app.translator.core.exceptions.functions import InvalidFunctionSignature, NotSupportedFunctionException
2628
from app.translator.core.mapping import SourceMapping
2729
from app.translator.core.models.field import Field
2830
from app.translator.core.models.functions.base import Function, ParsedFunctions, RenderedFunctions
29-
from app.translator.core.tokenizer import BaseTokenizer
3031
from settings import INIT_FUNCTIONS
3132

3233
if TYPE_CHECKING:
3334
from app.translator.core.render import PlatformQueryRender
3435

3536

36-
class FunctionParser(ABC):
37-
tokenizer: BaseTokenizer = None
37+
@dataclass
38+
class FunctionMatchContainer:
39+
name: str
40+
match: re.Match
3841

42+
43+
class BaseFunctionParser(ABC):
44+
@abstractmethod
45+
def parse(self, *args, **kwargs) -> Function:
46+
raise NotImplementedError
47+
48+
def tokenize_body(self, func_body: str) -> list[Any]:
49+
tokenized = []
50+
while func_body:
51+
identifier, func_body = self._get_next_token(func_body=func_body)
52+
tokenized.append(identifier)
53+
return tokenized
54+
55+
def _get_next_token(self, func_body: str) -> tuple[Any, str]:
56+
raise NotImplementedError
57+
58+
59+
class FunctionParser(BaseFunctionParser):
60+
@abstractmethod
61+
def parse(self, func_name: str, match: re.Match) -> Function:
62+
raise NotImplementedError
63+
64+
@abstractmethod
65+
def get_func_match(self, higher_order_func_body: str) -> Optional[FunctionMatchContainer]:
66+
raise NotImplementedError
67+
68+
69+
class HigherOrderFunctionParser(BaseFunctionParser): # for highest level functions e.g. | stats, | search, | sort, etc.
3970
@abstractmethod
4071
def parse(self, func_body: str, raw: str) -> Function:
4172
raise NotImplementedError
@@ -67,18 +98,18 @@ def map_field(field: Field, source_mapping: SourceMapping) -> str:
6798

6899
class PlatformFunctionsManager:
69100
def __init__(self):
70-
self._parsers_map: dict[str, FunctionParser] = {}
101+
self._parsers_map: dict[str, HigherOrderFunctionParser] = {}
71102
self._renders_map: dict[str, FunctionRender] = {}
72103
self._names_map: dict[str, str] = {}
73104

74-
def init_search_func_render(self, platform_render: PlatformQueryRender) -> None:
105+
def post_init_configure(self, platform_render: PlatformQueryRender) -> None:
75106
raise NotImplementedError
76107

77108
@cached_property
78109
def _inverted_names_map(self) -> dict[str, str]:
79110
return {value: key for key, value in self._names_map.items()}
80111

81-
def get_parser(self, generic_func_name: str) -> FunctionParser:
112+
def get_parser(self, generic_func_name: str) -> HigherOrderFunctionParser:
82113
if INIT_FUNCTIONS and (parser := self._parsers_map.get(generic_func_name)):
83114
return parser
84115

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from dataclasses import dataclass, field
2+
from typing import Union
3+
4+
from app.translator.core.custom_types.functions import FunctionType
5+
from app.translator.core.models.field import Field
6+
from app.translator.core.models.functions.base import Function
7+
from app.translator.core.models.identifier import Identifier
8+
9+
10+
@dataclass
11+
class EvalArg:
12+
field_: Field = None
13+
expression: list[Union[Field, Function, Identifier, int, float, str]] = field(default_factory=list)
14+
15+
16+
@dataclass
17+
class EvalFunction(Function):
18+
name: str = FunctionType.eval
19+
args: list[EvalArg] = None
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from dataclasses import dataclass
2+
3+
from app.translator.core.custom_types.functions import FunctionType
4+
from app.translator.core.models.field import Field
5+
from app.translator.core.models.functions.base import Function
6+
7+
8+
@dataclass
9+
class RenameArg:
10+
field_: Field = None
11+
alias: str = None
12+
13+
14+
@dataclass
15+
class RenameFunction(Function):
16+
name: str = FunctionType.rename
17+
args: list[RenameArg] = None

uncoder-core/app/translator/platforms/base/spl/functions/const.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
class SplFunctionType(CustomEnum):
55
avg = "avg"
66
count = "count"
7+
distinct_count = "distinct_count"
8+
earliest = "earliest"
9+
eval = "eval"
10+
fields = "fields"
11+
latest = "latest"
712
max = "max"
813
min = "min"
14+
rename = "rename"
915
search = "search"
1016
sort = "sort"
1117
stats = "stats"
1218
sum = "sum"
1319
table = "table"
20+
values = "values"
21+
where = "where"
1422

1523

1624
class SplSortOrderType(CustomEnum):

uncoder-core/app/translator/platforms/base/spl/functions/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010

1111
class SplFunctionsManager(PlatformFunctionsManager):
12-
def init_search_func_render(self, platform_render: SplQueryRender) -> None:
12+
def post_init_configure(self, platform_render: SplQueryRender) -> None:
1313
pass

uncoder-core/app/translator/platforms/logscale/functions/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010

1111
class LogScaleFunctionsManager(PlatformFunctionsManager):
12-
def init_search_func_render(self, platform_render: LogScaleQueryRender) -> None:
12+
def post_init_configure(self, platform_render: LogScaleQueryRender) -> None:
1313
pass

uncoder-core/app/translator/platforms/microsoft/functions/const.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
class KQLFunctionType(CustomEnum):
55
avg = "avg"
66
count = "count"
7+
distinct = "distinct"
8+
distinct_count = "count_distinct"
9+
extend = "extend"
710
max = "max"
811
min = "min"
9-
sum = "sum"
10-
where = "where"
11-
search = "search"
12-
summarize = "summarize"
1312
project = "project"
13+
project_rename = "project-rename"
14+
search = "search"
1415
sort = "sort"
16+
sum = "sum"
17+
summarize = "summarize"
18+
top = "top"
19+
where = "where"
20+
21+
22+
class KQLSortOrderType(CustomEnum):
23+
asc = "asc"
24+
desc = "desc"

uncoder-core/app/translator/platforms/microsoft/functions/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010

1111
class MicrosoftFunctionsManager(PlatformFunctionsManager):
12-
def init_search_func_render(self, platform_render: MicrosoftSentinelQueryRender) -> None:
12+
def post_init_configure(self, platform_render: MicrosoftSentinelQueryRender) -> None:
1313
pass

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy