relationalai 1.0.0a3__py3-none-any.whl → 1.0.0a5__py3-none-any.whl
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.
- relationalai/config/config.py +47 -21
- relationalai/config/connections/__init__.py +5 -2
- relationalai/config/connections/duckdb.py +2 -2
- relationalai/config/connections/local.py +31 -0
- relationalai/config/connections/snowflake.py +0 -1
- relationalai/config/external/raiconfig_converter.py +235 -0
- relationalai/config/external/raiconfig_models.py +202 -0
- relationalai/config/external/utils.py +31 -0
- relationalai/config/shims.py +1 -0
- relationalai/semantics/__init__.py +10 -8
- relationalai/semantics/backends/sql/sql_compiler.py +1 -4
- relationalai/semantics/experimental/__init__.py +0 -0
- relationalai/semantics/experimental/builder.py +295 -0
- relationalai/semantics/experimental/builtins.py +154 -0
- relationalai/semantics/frontend/base.py +67 -42
- relationalai/semantics/frontend/core.py +34 -6
- relationalai/semantics/frontend/front_compiler.py +209 -37
- relationalai/semantics/frontend/pprint.py +6 -2
- relationalai/semantics/metamodel/__init__.py +7 -0
- relationalai/semantics/metamodel/metamodel.py +2 -0
- relationalai/semantics/metamodel/metamodel_analyzer.py +58 -16
- relationalai/semantics/metamodel/pprint.py +6 -1
- relationalai/semantics/metamodel/rewriter.py +11 -7
- relationalai/semantics/metamodel/typer.py +116 -41
- relationalai/semantics/reasoners/__init__.py +11 -0
- relationalai/semantics/reasoners/graph/__init__.py +35 -0
- relationalai/semantics/reasoners/graph/core.py +9028 -0
- relationalai/semantics/std/__init__.py +30 -10
- relationalai/semantics/std/aggregates.py +641 -12
- relationalai/semantics/std/common.py +146 -13
- relationalai/semantics/std/constraints.py +71 -1
- relationalai/semantics/std/datetime.py +904 -21
- relationalai/semantics/std/decimals.py +143 -2
- relationalai/semantics/std/floats.py +57 -4
- relationalai/semantics/std/integers.py +98 -4
- relationalai/semantics/std/math.py +857 -35
- relationalai/semantics/std/numbers.py +216 -20
- relationalai/semantics/std/re.py +213 -5
- relationalai/semantics/std/strings.py +437 -44
- relationalai/shims/executor.py +60 -52
- relationalai/shims/fixtures.py +85 -0
- relationalai/shims/helpers.py +26 -2
- relationalai/shims/hoister.py +28 -9
- relationalai/shims/mm2v0.py +204 -173
- relationalai/tools/cli/cli.py +192 -10
- relationalai/tools/cli/components/progress_reader.py +1 -1
- relationalai/tools/cli/docs.py +394 -0
- relationalai/tools/debugger.py +11 -4
- relationalai/tools/qb_debugger.py +435 -0
- relationalai/tools/typer_debugger.py +1 -2
- relationalai/util/dataclasses.py +3 -5
- relationalai/util/docutils.py +1 -2
- relationalai/util/error.py +2 -5
- relationalai/util/python.py +23 -0
- relationalai/util/runtime.py +1 -2
- relationalai/util/schema.py +2 -4
- relationalai/util/structures.py +4 -2
- relationalai/util/tracing.py +8 -2
- {relationalai-1.0.0a3.dist-info → relationalai-1.0.0a5.dist-info}/METADATA +8 -5
- {relationalai-1.0.0a3.dist-info → relationalai-1.0.0a5.dist-info}/RECORD +118 -95
- {relationalai-1.0.0a3.dist-info → relationalai-1.0.0a5.dist-info}/WHEEL +1 -1
- v0/relationalai/__init__.py +1 -1
- v0/relationalai/clients/client.py +52 -18
- v0/relationalai/clients/exec_txn_poller.py +122 -0
- v0/relationalai/clients/local.py +23 -8
- v0/relationalai/clients/resources/azure/azure.py +36 -11
- v0/relationalai/clients/resources/snowflake/__init__.py +4 -4
- v0/relationalai/clients/resources/snowflake/cli_resources.py +12 -1
- v0/relationalai/clients/resources/snowflake/direct_access_resources.py +124 -100
- v0/relationalai/clients/resources/snowflake/engine_service.py +381 -0
- v0/relationalai/clients/resources/snowflake/engine_state_handlers.py +35 -29
- v0/relationalai/clients/resources/snowflake/error_handlers.py +43 -2
- v0/relationalai/clients/resources/snowflake/snowflake.py +277 -179
- v0/relationalai/clients/resources/snowflake/use_index_poller.py +8 -0
- v0/relationalai/clients/types.py +5 -0
- v0/relationalai/errors.py +19 -1
- v0/relationalai/semantics/lqp/algorithms.py +173 -0
- v0/relationalai/semantics/lqp/builtins.py +199 -2
- v0/relationalai/semantics/lqp/executor.py +68 -37
- v0/relationalai/semantics/lqp/ir.py +28 -2
- v0/relationalai/semantics/lqp/model2lqp.py +215 -45
- v0/relationalai/semantics/lqp/passes.py +13 -658
- v0/relationalai/semantics/lqp/rewrite/__init__.py +12 -0
- v0/relationalai/semantics/lqp/rewrite/algorithm.py +385 -0
- v0/relationalai/semantics/lqp/rewrite/constants_to_vars.py +70 -0
- v0/relationalai/semantics/lqp/rewrite/deduplicate_vars.py +104 -0
- v0/relationalai/semantics/lqp/rewrite/eliminate_data.py +108 -0
- v0/relationalai/semantics/lqp/rewrite/extract_keys.py +25 -3
- v0/relationalai/semantics/lqp/rewrite/period_math.py +77 -0
- v0/relationalai/semantics/lqp/rewrite/quantify_vars.py +65 -31
- v0/relationalai/semantics/lqp/rewrite/unify_definitions.py +317 -0
- v0/relationalai/semantics/lqp/utils.py +11 -1
- v0/relationalai/semantics/lqp/validators.py +14 -1
- v0/relationalai/semantics/metamodel/builtins.py +2 -1
- v0/relationalai/semantics/metamodel/compiler.py +2 -1
- v0/relationalai/semantics/metamodel/dependency.py +12 -3
- v0/relationalai/semantics/metamodel/executor.py +11 -1
- v0/relationalai/semantics/metamodel/factory.py +2 -2
- v0/relationalai/semantics/metamodel/helpers.py +7 -0
- v0/relationalai/semantics/metamodel/ir.py +3 -2
- v0/relationalai/semantics/metamodel/rewrite/dnf_union_splitter.py +30 -20
- v0/relationalai/semantics/metamodel/rewrite/flatten.py +50 -13
- v0/relationalai/semantics/metamodel/rewrite/format_outputs.py +9 -3
- v0/relationalai/semantics/metamodel/typer/checker.py +6 -4
- v0/relationalai/semantics/metamodel/typer/typer.py +4 -3
- v0/relationalai/semantics/metamodel/visitor.py +4 -3
- v0/relationalai/semantics/reasoners/optimization/solvers_dev.py +1 -1
- v0/relationalai/semantics/reasoners/optimization/solvers_pb.py +336 -86
- v0/relationalai/semantics/rel/compiler.py +2 -1
- v0/relationalai/semantics/rel/executor.py +3 -2
- v0/relationalai/semantics/tests/lqp/__init__.py +0 -0
- v0/relationalai/semantics/tests/lqp/algorithms.py +345 -0
- v0/relationalai/tools/cli.py +339 -186
- v0/relationalai/tools/cli_controls.py +216 -67
- v0/relationalai/tools/cli_helpers.py +410 -6
- v0/relationalai/util/format.py +5 -2
- {relationalai-1.0.0a3.dist-info → relationalai-1.0.0a5.dist-info}/entry_points.txt +0 -0
- {relationalai-1.0.0a3.dist-info → relationalai-1.0.0a5.dist-info}/top_level.txt +0 -0
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Common utility functions.
|
|
3
|
+
|
|
4
|
+
This module provides general-purpose functions including:
|
|
5
|
+
- Range generation
|
|
6
|
+
- Hashing and UUID operations
|
|
7
|
+
- Raw source code attachment
|
|
8
|
+
"""
|
|
1
9
|
from __future__ import annotations
|
|
2
10
|
|
|
3
|
-
from . import StringValue, IntegerValue
|
|
4
|
-
from ..frontend.base import
|
|
5
|
-
from ..frontend.core import Any,
|
|
11
|
+
from . import StringValue, IntegerValue
|
|
12
|
+
from ..frontend.base import Library, Expression, Field, TupleVariable, Value
|
|
13
|
+
from ..frontend.core import Any, String, Integer, Hash
|
|
14
|
+
from relationalai.util.docutils import include_in_docs
|
|
15
|
+
|
|
6
16
|
|
|
7
|
-
|
|
8
|
-
import datetime as dt
|
|
17
|
+
__include_in_docs__ = True
|
|
9
18
|
|
|
10
19
|
# the front-end library object
|
|
11
20
|
library = Library("common")
|
|
@@ -13,14 +22,41 @@ library = Library("common")
|
|
|
13
22
|
|
|
14
23
|
_range = library.Relation("range", [Field.input("start", Integer), Field.input("stop", Integer), Field.input("step", Integer), Field("value", Integer)])
|
|
15
24
|
|
|
25
|
+
@include_in_docs
|
|
16
26
|
def range(*args: IntegerValue) -> Expression:
|
|
17
|
-
"""
|
|
27
|
+
"""
|
|
28
|
+
Generate a range of integers.
|
|
29
|
+
|
|
30
|
+
- Supports `range(stop)`, `range(start, stop)`, `range(start, stop, step)`.
|
|
31
|
+
- `start` is inclusive and defaults to `0`.
|
|
32
|
+
- `stop` is exclusive.
|
|
33
|
+
- `step` defaults to `1`.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
*args: IntegerValue
|
|
38
|
+
- 1 arg: `stop`
|
|
39
|
+
- 2 args: `start`, `stop`
|
|
40
|
+
- 3 args: `start`, `stop`, `step`
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
Expression
|
|
45
|
+
An `Expression` computing integer values in the specified range. Returns `Integer`.
|
|
18
46
|
|
|
19
|
-
|
|
47
|
+
Examples
|
|
48
|
+
--------
|
|
49
|
+
Generate numbers from 0 to 9:
|
|
20
50
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
51
|
+
>>> common.range(10)
|
|
52
|
+
|
|
53
|
+
Generate numbers from 5 to 14:
|
|
54
|
+
|
|
55
|
+
>>> common.range(5, 15)
|
|
56
|
+
|
|
57
|
+
Generate even numbers from 0 to 18:
|
|
58
|
+
|
|
59
|
+
>>> common.range(0, 20, 2)
|
|
24
60
|
"""
|
|
25
61
|
if len(args) == 1:
|
|
26
62
|
start, stop, step = 0, args[0], 1
|
|
@@ -34,11 +70,108 @@ def range(*args: IntegerValue) -> Expression:
|
|
|
34
70
|
return _range(start, stop, step)
|
|
35
71
|
|
|
36
72
|
_hash = library.Relation("hash", [Field.input("args", Any, is_list=True), Field("hash", Hash)])
|
|
73
|
+
|
|
74
|
+
@include_in_docs
|
|
37
75
|
def hash(*args: Value) -> Expression:
|
|
38
|
-
"""
|
|
76
|
+
"""
|
|
77
|
+
Compute a hash value for the given arguments.
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
*args: Value
|
|
82
|
+
Values to hash together.
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
Expression
|
|
87
|
+
An `Expression` representing the computed hash value. Returns `Hash`.
|
|
88
|
+
|
|
89
|
+
Examples
|
|
90
|
+
--------
|
|
91
|
+
Compute hash of a single value:
|
|
92
|
+
|
|
93
|
+
>>> select(common.hash(Person.email))
|
|
94
|
+
|
|
95
|
+
Compute hash of multiple values together:
|
|
96
|
+
|
|
97
|
+
>>> select(common.hash(Order.customer_id, Order.order_date))
|
|
98
|
+
"""
|
|
39
99
|
return _hash(TupleVariable(args))
|
|
40
100
|
|
|
41
101
|
_uuid_to_string = library.Relation("uuid_to_string", [Field.input("uuid", Hash), Field("str", String)])
|
|
102
|
+
|
|
103
|
+
@include_in_docs
|
|
42
104
|
def uuid_to_string(uuid: Value) -> Expression:
|
|
43
|
-
"""
|
|
44
|
-
|
|
105
|
+
"""
|
|
106
|
+
Convert a UUID (Hash) to its string representation.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
uuid: Value
|
|
111
|
+
The UUID (Hash) value to convert.
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
Expression
|
|
116
|
+
An `Expression` representing the string representation of the UUID. Returns `String`.
|
|
117
|
+
|
|
118
|
+
Examples
|
|
119
|
+
--------
|
|
120
|
+
Convert UUID to string:
|
|
121
|
+
|
|
122
|
+
>>> select(common.uuid_to_string(Session.id))
|
|
123
|
+
"""
|
|
124
|
+
return _uuid_to_string(uuid)
|
|
125
|
+
|
|
126
|
+
_parse_uuid = library.Relation("parse_uuid", [Field.input("str", String), Field("uuid", Hash)])
|
|
127
|
+
|
|
128
|
+
@include_in_docs
|
|
129
|
+
def parse_uuid(s: StringValue) -> Expression:
|
|
130
|
+
"""
|
|
131
|
+
Parse a UUID from its string representation.
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
s: StringValue
|
|
136
|
+
The string representation of the UUID.
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
Expression
|
|
141
|
+
An `Expression` representing the parsed UUID. Returns `Hash`.
|
|
142
|
+
|
|
143
|
+
Examples
|
|
144
|
+
--------
|
|
145
|
+
Parse UUID from string:
|
|
146
|
+
|
|
147
|
+
>>> select(common.parse_uuid("550e8400-e29b-41d4-a716-446655440000"))
|
|
148
|
+
>>> select(common.parse_uuid(Request.session_id_str))
|
|
149
|
+
"""
|
|
150
|
+
return _parse_uuid(s)
|
|
151
|
+
|
|
152
|
+
_raw_source = library.Relation("raw_source", [Field.input("lang", String), Field.input("source", String)])
|
|
153
|
+
|
|
154
|
+
@include_in_docs
|
|
155
|
+
def raw_source(lang: StringValue, source: str) -> Expression:
|
|
156
|
+
"""
|
|
157
|
+
Attach raw source code to the transaction when the backend understands this language.
|
|
158
|
+
|
|
159
|
+
Parameters
|
|
160
|
+
----------
|
|
161
|
+
lang: StringValue
|
|
162
|
+
The language identifier for the source code (e.g. `"sql"`, `"lqp"`, or `"rel"`).
|
|
163
|
+
source: str
|
|
164
|
+
The source code to attach.
|
|
165
|
+
|
|
166
|
+
Returns
|
|
167
|
+
-------
|
|
168
|
+
Expression
|
|
169
|
+
An `Expression` representing the raw source attachment.
|
|
170
|
+
|
|
171
|
+
Examples
|
|
172
|
+
--------
|
|
173
|
+
Attach raw Rel source code:
|
|
174
|
+
|
|
175
|
+
>>> common.raw_source("rel", "def my_rule = 42")
|
|
176
|
+
"""
|
|
177
|
+
return _raw_source(lang, source)
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Functions for declaring constraints.
|
|
1
3
|
|
|
2
|
-
|
|
4
|
+
This module provides functions for declaring constraints on data models including:
|
|
5
|
+
- Uniqueness constraints
|
|
6
|
+
- Exclusive/anyof/oneof constraints for relationships
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from ..frontend.base import FieldRef, Fragment, Library, Expression, Field, TupleVariable, Variable, Concept, Ref, MetaRef
|
|
3
11
|
from ..frontend import core
|
|
12
|
+
from relationalai.util.docutils import include_in_docs
|
|
13
|
+
|
|
14
|
+
__include_in_docs__ = True
|
|
4
15
|
|
|
5
16
|
# the front-end library object
|
|
6
17
|
library = Library("constraints")
|
|
@@ -18,20 +29,79 @@ _anyof =library.Relation("anyof", [Field.input("concepts", core.Relation, is_lis
|
|
|
18
29
|
# API
|
|
19
30
|
#------------------------------------------------------
|
|
20
31
|
|
|
32
|
+
@include_in_docs
|
|
21
33
|
def unique(*args: Variable) -> Expression:
|
|
34
|
+
"""
|
|
35
|
+
Declare a uniqueness constraint on variables.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
*args: Variable
|
|
40
|
+
Variables representing values or fields that must be unique.
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
Expression
|
|
45
|
+
An `Expression` computing the uniqueness constraint.
|
|
46
|
+
|
|
47
|
+
"""
|
|
22
48
|
if all(isinstance(arg, FieldRef) for arg in args):
|
|
23
49
|
fields = [MetaRef(arg._resolved) for arg in args] # type: ignore - we know these are FieldRefs from the all above
|
|
24
50
|
return _unique_fields(TupleVariable(fields))
|
|
25
51
|
return _unique(TupleVariable(args))
|
|
26
52
|
|
|
53
|
+
@include_in_docs
|
|
27
54
|
def exclusive(*args: Concept|Ref) -> Expression:
|
|
55
|
+
"""
|
|
56
|
+
Declare that the given concepts are mutually exclusive.
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
*args: Concept | Ref
|
|
61
|
+
Concepts or Refs that should be mutually exclusive.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
Expression
|
|
66
|
+
An `Expression` computing the exclusivity constraint.
|
|
67
|
+
"""
|
|
28
68
|
concepts = [arg._to_concept() for arg in args]
|
|
29
69
|
return _exclusive(TupleVariable(concepts))
|
|
30
70
|
|
|
71
|
+
@include_in_docs
|
|
31
72
|
def anyof(*args: Concept|Ref) -> Expression:
|
|
73
|
+
"""
|
|
74
|
+
Declare that at least one of the given concepts must be true.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
*args: Concept | Ref
|
|
79
|
+
Concepts or Refs, at least one of which must be satisfied.
|
|
80
|
+
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
Expression
|
|
84
|
+
An `Expression` computing the anyof constraint.
|
|
85
|
+
"""
|
|
32
86
|
concepts = [arg._to_concept() for arg in args]
|
|
33
87
|
return _anyof(TupleVariable(concepts))
|
|
34
88
|
|
|
89
|
+
@include_in_docs
|
|
35
90
|
def oneof(*args: Concept | Ref) -> Fragment:
|
|
91
|
+
"""
|
|
92
|
+
Declare that exactly one of the given concepts must be true.
|
|
93
|
+
|
|
94
|
+
This combines `anyof` (at least one) and `exclusive` (at most one) constraints.
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
*args: Concept | Ref
|
|
99
|
+
Concepts or Refs, exactly one of which must be satisfied.
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
Fragment
|
|
104
|
+
A `Fragment` representing the oneof constraint.
|
|
105
|
+
"""
|
|
36
106
|
model = args[0]._model
|
|
37
107
|
return model.where(anyof(*args), exclusive(*args))
|