pub enum ProjectList {
Name(Vec<ProjectName>),
List(Vec<RelExpr>, Vec<(Box<str>, FieldProject)>),
Limit(Box<ProjectList>, u64),
Agg(Vec<RelExpr>, AggType, Box<str>, AlgebraicType),
}Expand description
A projection is the root of any relational expression. This type represents a projection that returns fields.
For example:
select a, b from tand
select t.a as x from t join s ...Note that RLS takes a single expression and produces a list of expressions. Hence why these variants take lists rather than single expressions.
Why does RLS take an expression and produce a list?
There may be multiple RLS rules associated to a single table. Semantically these rules represent a UNION over that table, and this corresponds to a UNION in the original expression.
TODO: We should model the UNION explicitly in the physical plan.
Ex.
Let’s say we have the following rules for the users table:
use spacetimedb::client_visibility_filter;
use spacetimedb::Filter;
#[client_visibility_filter]
const USER_FILTER: Filter = Filter::Sql(
"SELECT users.* FROM users WHERE identity = :sender"
);
#[client_visibility_filter]
const ADMIN_FILTER: Filter = Filter::Sql(
"SELECT users.* FROM users JOIN admins"
);The user query
SELECT * FROM users WHERE level > 5essentially resolves to
SELECT users.*
FROM users
WHERE identity = :sender AND level > 5
UNION ALL
SELECT users.*
FROM users JOIN admins
WHERE users.level > 5Variants§
Name(Vec<ProjectName>)
List(Vec<RelExpr>, Vec<(Box<str>, FieldProject)>)
Limit(Box<ProjectList>, u64)
Agg(Vec<RelExpr>, AggType, Box<str>, AlgebraicType)
Implementations§
Source§impl ProjectList
impl ProjectList
Sourcepub fn return_table(&self) -> Option<&TableSchema>
pub fn return_table(&self) -> Option<&TableSchema>
Does this expression project a single relvar? If so, we return it’s TableSchema. If not, it projects a list of columns, so we return None.
Sourcepub fn return_table_id(&self) -> Option<TableId>
pub fn return_table_id(&self) -> Option<TableId>
Sourcepub fn for_each_return_field(&self, f: impl FnMut(&str, &AlgebraicType))
pub fn for_each_return_field(&self, f: impl FnMut(&str, &AlgebraicType))
Iterate over the projected column names and types
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ProjectList
impl RefUnwindSafe for ProjectList
impl Send for ProjectList
impl Sync for ProjectList
impl Unpin for ProjectList
impl UnwindSafe for ProjectList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more