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
24c9fc52
Commit
24c9fc52
authored
3 years ago
by
Denis Smirnov
Browse files
Options
Downloads
Patches
Plain Diff
refactoring: make "add_select" Plan method.
Also fix some documetation style
parent
873cbeeb
No related branches found
No related tags found
1 merge request
!1414
sbroad import
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ir/operator.rs
+28
-32
28 additions, 32 deletions
src/ir/operator.rs
src/ir/operator/tests.rs
+3
-3
3 additions, 3 deletions
src/ir/operator/tests.rs
with
31 additions
and
35 deletions
src/ir/operator.rs
+
28
−
32
View file @
24c9fc52
...
...
@@ -191,35 +191,6 @@ impl Relational {
}
}
/// New `Selection` constructor
///
/// # Errors
/// Returns `QueryPlannerError`:
/// - filter expression is not boolean
/// - child node is not relational
/// - child output tuple is not valid
pub
fn
new_select
(
plan
:
&
mut
Plan
,
child
:
usize
,
filter
:
usize
,
)
->
Result
<
Self
,
QueryPlannerError
>
{
if
let
Node
::
Expression
(
Expression
::
Bool
{
..
})
=
plan
.get_node
(
filter
)
?
{
}
else
{
return
Err
(
QueryPlannerError
::
InvalidBool
);
}
let
id
=
plan
.nodes
.next_id
();
let
children
:
Vec
<
usize
>
=
vec!
[
child
];
let
output
=
plan
.add_output_row
(
id
,
&
children
,
&
[
0
],
&
[])
?
;
Ok
(
Relational
::
Selection
{
children
,
filter
,
id
,
output
,
})
}
/// New `UnionAll` constructor.
///
/// # Errors
...
...
@@ -290,7 +261,7 @@ impl Plan {
/// Add a scan node.
///
/// # Errors
///
Returns `QueryPlannerError` when when
relation is invalid
.
///
-
relation is invalid
pub
fn
add_scan
(
&
mut
self
,
table
:
&
str
)
->
Result
<
usize
,
QueryPlannerError
>
{
let
logical_id
=
self
.nodes
.next_id
();
let
nodes
=
&
mut
self
.nodes
;
...
...
@@ -325,10 +296,9 @@ impl Plan {
// TODO: we need a more flexible projection constructor (constants, etc)
///
New `P
rojection
` constructor
.
///
Add p
rojection
node
.
///
/// # Errors
/// Returns `QueryPlannerError`:
/// - child node is not relational
/// - child output tuple is invalid
/// - column name do not match the ones in the child output tuple
...
...
@@ -348,6 +318,32 @@ impl Plan {
};
Ok
(
self
.nodes
.push
(
Node
::
Relational
(
proj
)))
}
/// Add selection node
///
/// # Errors
/// - filter expression is not boolean
/// - child node is not relational
/// - child output tuple is not valid
pub
fn
add_select
(
&
mut
self
,
child
:
usize
,
filter
:
usize
)
->
Result
<
usize
,
QueryPlannerError
>
{
if
let
Node
::
Expression
(
Expression
::
Bool
{
..
})
=
self
.get_node
(
filter
)
?
{
}
else
{
return
Err
(
QueryPlannerError
::
InvalidBool
);
}
let
id
=
self
.nodes
.next_id
();
let
children
:
Vec
<
usize
>
=
vec!
[
child
];
let
output
=
self
.add_output_row
(
id
,
&
children
,
&
[
0
],
&
[])
?
;
let
select
=
Relational
::
Selection
{
children
,
filter
,
id
,
output
,
};
Ok
(
self
.nodes
.push
(
Node
::
Relational
(
select
)))
}
}
#[cfg(test)]
...
...
This diff is collapsed.
Click to expand it.
src/ir/operator/tests.rs
+
3
−
3
View file @
24c9fc52
...
...
@@ -155,18 +155,18 @@ fn selection() {
let
gt_id
=
plan
.nodes
.add_bool
(
a_id
,
Bool
::
Gt
,
const_id
)
.unwrap
();
// Correct Selection operator
Relational
::
new_select
(
&
mut
plan
,
scan_id
,
gt_id
)
.unwrap
();
plan
.add_select
(
scan_id
,
gt_id
)
.unwrap
();
// Non-boolean filter
assert_eq!
(
QueryPlannerError
::
InvalidBool
,
Relational
::
new_select
(
&
mut
plan
,
scan_id
,
const_id
)
.unwrap_err
()
plan
.add_select
(
scan_id
,
const_id
)
.unwrap_err
()
);
// Non-relational child
assert_eq!
(
QueryPlannerError
::
InvalidNode
,
Relational
::
new_select
(
&
mut
plan
,
const_id
,
gt_id
)
.unwrap_err
()
plan
.add_select
(
const_id
,
gt_id
)
.unwrap_err
()
);
}
...
...
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