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
148d23ee
Commit
148d23ee
authored
3 years ago
by
Denis Smirnov
Browse files
Options
Downloads
Patches
Plain Diff
refactoring: reduce nested levels in Select::new()
parent
ce6a4bb4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1414
sbroad import
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/sql/tree.rs
+54
-49
54 additions, 49 deletions
src/backend/sql/tree.rs
with
54 additions
and
49 deletions
src/backend/sql/tree.rs
+
54
−
49
View file @
148d23ee
...
@@ -220,62 +220,67 @@ impl Select {
...
@@ -220,62 +220,67 @@ impl Select {
id
:
usize
,
id
:
usize
,
)
->
Result
<
Option
<
Select
>
,
QueryPlannerError
>
{
)
->
Result
<
Option
<
Select
>
,
QueryPlannerError
>
{
let
sn
=
sp
.nodes
.get_syntax_node
(
id
)
?
;
let
sn
=
sp
.nodes
.get_syntax_node
(
id
)
?
;
let
pn
=
if
let
Some
(
node
)
=
sp
.get_plan_node
(
&
sn
.data
)
?
{
// Check if the node is a projection
node
if
let
Some
(
Node
::
Relational
(
Relational
::
Projection
{
..
}))
=
sp
.get_plan_node
(
&
sn
.data
)
?
{
}
else
{
}
else
{
return
Ok
(
None
);
return
Ok
(
None
);
}
// Get the left node
let
left_id
=
match
sn
.left
{
Some
(
id
)
=>
id
,
None
=>
{
return
Err
(
QueryPlannerError
::
CustomError
(
"Projection can't be a leaf node"
.into
(),
))
}
};
};
if
let
Node
::
Relational
(
Relational
::
Projection
{
..
})
=
pn
{
let
syntax_node_left
=
sp
.nodes
.get_syntax_node
(
left_id
)
?
;
if
let
Some
(
lev_1
)
=
sn
.left
{
let
plan_node_left
=
sp
let
syntax_node_lev_1
=
sp
.nodes
.get_syntax_node
(
lev_1
)
?
;
.get_plan_node
(
&
syntax_node_left
.data
)
?
let
plan_node_lev_1
=
sp
.ok_or
(
QueryPlannerError
::
InvalidNode
)
?
;
.get_plan_node
(
&
syntax_node_lev_1
.data
)
?
match
plan_node_left
{
.ok_or
(
QueryPlannerError
::
InvalidNode
)
?
;
// Expecting projection over selection and scan
match
plan_node_lev_1
{
Node
::
Relational
(
Relational
::
Selection
{
..
})
=>
{
Node
::
Relational
(
Relational
::
Selection
{
..
})
=>
{
// Get the next left node
if
let
Some
(
lev_2
)
=
syntax_node_lev_1
.left
{
let
next_left_id
=
match
syntax_node_left
.left
{
let
syntax_node_lev_2
=
sp
.nodes
.get_syntax_node
(
lev_2
)
?
;
Some
(
id
)
=>
id
,
let
plan_node_lev_2
=
sp
None
=>
{
.get_plan_node
(
&
syntax_node_lev_2
.data
)
?
return
Err
(
QueryPlannerError
::
CustomError
(
.ok_or
(
QueryPlannerError
::
InvalidNode
)
?
;
"Selection can't be a leaf node"
.into
(),
if
let
Node
::
Relational
(
))
Relational
::
ScanRelation
{
..
}
|
Relational
::
ScanSubQuery
{
..
},
)
=
plan_node_lev_2
{
Ok
(
Some
(
Select
{
parent
,
branch
,
proj
:
id
,
scan
:
lev_2
,
select
:
Some
(
lev_1
),
}))
}
else
{
Err
(
QueryPlannerError
::
InvalidPlan
)
}
}
else
{
Err
(
QueryPlannerError
::
CustomError
(
"Selection can't be a leaf node"
.into
(),
))
}
}
}
Node
::
Relational
(
};
Relational
::
ScanRelation
{
..
}
|
Relational
::
ScanSubQuery
{
..
},
// We expect that the next left node is a scan
)
=>
Ok
(
Some
(
Select
{
let
syntax_node_next_left
=
sp
.nodes
.get_syntax_node
(
next_left_id
)
?
;
parent
,
let
plan_node_next_left
=
sp
branch
,
.get_plan_node
(
&
syntax_node_next_left
.data
)
?
.ok_or
(
QueryPlannerError
::
InvalidNode
)
?
;
if
let
Node
::
Relational
(
Relational
::
ScanRelation
{
..
}
|
Relational
::
ScanSubQuery
{
..
},
)
=
plan_node_next_left
{
Ok
(
Some
(
Select
{
parent
:
parent
,
branch
:
branch
,
proj
:
id
,
proj
:
id
,
scan
:
lev_1
,
scan
:
next_left_id
,
select
:
None
,
select
:
Some
(
left_id
),
})),
}))
_
=>
Err
(
QueryPlannerError
::
InvalidPlan
),
}
else
{
Err
(
QueryPlannerError
::
InvalidPlan
)
}
}
}
else
{
Err
(
QueryPlannerError
::
CustomError
(
"Projection can't be a leaf node"
.into
(),
))
}
}
}
else
{
// Expecting projection over scan
Ok
(
None
)
Node
::
Relational
(
Relational
::
ScanRelation
{
..
}
|
Relational
::
ScanSubQuery
{
..
})
=>
{
Ok
(
Some
(
Select
{
parent
:
parent
,
branch
:
branch
,
proj
:
id
,
scan
:
left_id
,
select
:
None
,
}))
}
_
=>
Err
(
QueryPlannerError
::
InvalidPlan
),
}
}
}
}
...
...
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