Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
f6323f61
Commit
f6323f61
authored
1 year ago
by
Maksim Kaitmazian
Browse files
Options
Downloads
Patches
Plain Diff
fix: types decimal and decimal are not supported for arithmetic expression
parent
53efa041
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1414
sbroad import
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sbroad-core/src/ir/expression/tests.rs
+83
-2
83 additions, 2 deletions
sbroad-core/src/ir/expression/tests.rs
sbroad-core/src/ir/expression/types.rs
+2
-2
2 additions, 2 deletions
sbroad-core/src/ir/expression/types.rs
with
85 additions
and
4 deletions
sbroad-core/src/ir/expression/tests.rs
+
83
−
2
View file @
f6323f61
use
crate
::
ir
::
tests
::
column_integer_user_non_null
;
use
crate
::
ir
::
operator
::
Arithmetic
;
use
crate
::
ir
::
tests
::{
column_integer_user_non_null
,
sharding_column
};
use
pretty_assertions
::
assert_eq
;
use
pretty_assertions
::
assert_eq
;
use
crate
::
ir
::
relation
::{
SpaceEngine
,
Table
};
use
crate
::
ir
::
relation
::{
Column
,
SpaceEngine
,
Table
,
Type
};
use
crate
::
ir
::
value
::
Value
;
use
crate
::
ir
::
value
::
Value
;
use
crate
::
ir
::{
Plan
,
SbroadError
};
use
crate
::
ir
::{
Plan
,
SbroadError
};
...
@@ -66,3 +67,83 @@ fn rel_nodes_from_reference_in_proj() {
...
@@ -66,3 +67,83 @@ fn rel_nodes_from_reference_in_proj() {
assert_eq!
(
1
,
rel_set
.len
());
assert_eq!
(
1
,
rel_set
.len
());
assert_eq!
(
Some
(
&
scan_id
),
rel_set
.get
(
&
scan_id
));
assert_eq!
(
Some
(
&
scan_id
),
rel_set
.get
(
&
scan_id
));
}
}
#[test]
fn
derive_expr_type
()
{
fn
column
(
name
:
String
,
ty
:
Type
)
->
Column
{
Column
{
name
,
r
#
type
:
ty
,
role
:
Default
::
default
(),
is_nullable
:
false
,
}
}
let
mut
plan
=
Plan
::
default
();
let
t
=
Table
::
new_sharded
(
"t"
,
vec!
[
column
(
String
::
from
(
"a"
),
Type
::
Integer
),
column
(
String
::
from
(
"b"
),
Type
::
Integer
),
column
(
String
::
from
(
"c"
),
Type
::
Unsigned
),
column
(
String
::
from
(
"d"
),
Type
::
Decimal
),
column
(
String
::
from
(
"e"
),
Type
::
Decimal
),
column
(
String
::
from
(
"f"
),
Type
::
Double
),
sharding_column
(),
],
&
[
"a"
],
&
[
"a"
],
SpaceEngine
::
Memtx
,
)
.unwrap
();
plan
.add_rel
(
t
);
let
scan_id
=
plan
.add_scan
(
"t"
,
None
)
.unwrap
();
let
a_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"a"
])
.unwrap
();
let
b_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"b"
])
.unwrap
();
let
c_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"c"
])
.unwrap
();
let
d_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"d"
])
.unwrap
();
let
e_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"e"
])
.unwrap
();
let
f_id
=
plan
.add_row_from_child
(
scan_id
,
&
[
"f"
])
.unwrap
();
// b/c
let
arith_divide_id
=
plan
.add_arithmetic_to_plan
(
b_id
,
Arithmetic
::
Divide
,
c_id
,
false
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_divide_id
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Integer
);
// d*e
let
arith_multiply_id
=
plan
.add_arithmetic_to_plan
(
d_id
,
Arithmetic
::
Multiply
,
e_id
,
false
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_multiply_id
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Decimal
);
// (b/c + d*e)
let
arith_addition_id
=
plan
.add_arithmetic_to_plan
(
arith_divide_id
,
Arithmetic
::
Add
,
arith_multiply_id
,
true
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_addition_id
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Decimal
);
// (b/c + d*e) * f
let
arith_multiply_id2
=
plan
.add_arithmetic_to_plan
(
arith_addition_id
,
Arithmetic
::
Multiply
,
f_id
,
false
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_multiply_id2
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Double
);
// a + (b/c + d*e) * f
let
arith_addition_id2
=
plan
.add_arithmetic_to_plan
(
a_id
,
Arithmetic
::
Add
,
arith_multiply_id2
,
false
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_addition_id2
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Double
);
// a + (b/c + d*e) * f - b
let
arith_subract_id
=
plan
.add_arithmetic_to_plan
(
arith_addition_id2
,
Arithmetic
::
Subtract
,
b_id
,
false
)
.unwrap
();
let
expr
=
plan
.get_expression_node
(
arith_subract_id
)
.unwrap
();
assert_eq!
(
expr
.calculate_type
(
&
plan
)
.unwrap
(),
Type
::
Double
);
}
This diff is collapsed.
Click to expand it.
sbroad-core/src/ir/expression/types.rs
+
2
−
2
View file @
f6323f61
...
@@ -41,11 +41,11 @@ impl Expression {
...
@@ -41,11 +41,11 @@ impl Expression {
let
left_type
=
plan
.get_node_type
(
*
left
)
?
;
let
left_type
=
plan
.get_node_type
(
*
left
)
?
;
let
right_type
=
plan
.get_node_type
(
*
right
)
?
;
let
right_type
=
plan
.get_node_type
(
*
right
)
?
;
match
(
&
left_type
,
&
right_type
)
{
match
(
&
left_type
,
&
right_type
)
{
(
Type
::
Double
,
Type
::
Unsigned
|
Type
::
Integer
|
Type
::
Decimal
)
(
Type
::
Double
,
Type
::
Double
|
Type
::
Unsigned
|
Type
::
Integer
|
Type
::
Decimal
)
|
(
Type
::
Unsigned
|
Type
::
Integer
|
Type
::
Decimal
,
Type
::
Double
)
=>
{
|
(
Type
::
Unsigned
|
Type
::
Integer
|
Type
::
Decimal
,
Type
::
Double
)
=>
{
Ok
(
Type
::
Double
)
Ok
(
Type
::
Double
)
}
}
(
Type
::
Decimal
,
Type
::
Unsigned
|
Type
::
Integer
)
(
Type
::
Decimal
,
Type
::
Decimal
|
Type
::
Unsigned
|
Type
::
Integer
)
|
(
Type
::
Unsigned
|
Type
::
Integer
,
Type
::
Decimal
)
=>
Ok
(
Type
::
Decimal
),
|
(
Type
::
Unsigned
|
Type
::
Integer
,
Type
::
Decimal
)
=>
Ok
(
Type
::
Decimal
),
(
Type
::
Integer
,
Type
::
Unsigned
|
Type
::
Integer
)
(
Type
::
Integer
,
Type
::
Unsigned
|
Type
::
Integer
)
|
(
Type
::
Unsigned
,
Type
::
Integer
)
=>
Ok
(
Type
::
Integer
),
|
(
Type
::
Unsigned
,
Type
::
Integer
)
=>
Ok
(
Type
::
Integer
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment