-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: impl `View` Encode & Decode * chore: add `ReferenceSerialization` for `DataValue::Tuple` & fix subquery plan on `ReferenceSerialization` * feat: impl `CreateView` * feat: impl `View` as data source * test: add test for `View` * chore: add feature `is_sorted` * chore: version up
- Loading branch information
Showing
97 changed files
with
1,688 additions
and
702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
[package] | ||
name = "fnck_sql" | ||
version = "0.0.3" | ||
version = "0.0.4" | ||
edition = "2021" | ||
authors = ["Kould <[email protected]>", "Xwg <[email protected]>"] | ||
description = "SQL as a Function for Rust" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nightly-2024-10-18 | ||
nightly-2024-10-10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::binder::{lower_case_name, lower_ident, Binder}; | ||
use crate::catalog::view::View; | ||
use crate::catalog::{ColumnCatalog, ColumnRef}; | ||
use crate::errors::DatabaseError; | ||
use crate::expression::{AliasType, ScalarExpression}; | ||
use crate::planner::operator::create_view::CreateViewOperator; | ||
use crate::planner::operator::Operator; | ||
use crate::planner::LogicalPlan; | ||
use crate::storage::Transaction; | ||
use itertools::Itertools; | ||
use sqlparser::ast::{Ident, ObjectName, Query}; | ||
use std::sync::Arc; | ||
use ulid::Ulid; | ||
|
||
impl<T: Transaction> Binder<'_, '_, T> { | ||
pub(crate) fn bind_create_view( | ||
&mut self, | ||
or_replace: &bool, | ||
name: &ObjectName, | ||
columns: &[Ident], | ||
query: &Query, | ||
) -> Result<LogicalPlan, DatabaseError> { | ||
let view_name = Arc::new(lower_case_name(name)?); | ||
let mut plan = self.bind_query(query)?; | ||
|
||
if !columns.is_empty() { | ||
let mapping_schema = plan.output_schema(); | ||
let exprs = columns | ||
.iter() | ||
.enumerate() | ||
.map(|(i, ident)| { | ||
let mapping_column = &mapping_schema[i]; | ||
let mut column = ColumnCatalog::new( | ||
lower_ident(ident), | ||
mapping_column.nullable(), | ||
mapping_column.desc().clone(), | ||
); | ||
column.set_ref_table(view_name.clone(), Ulid::new(), true); | ||
|
||
ScalarExpression::Alias { | ||
expr: Box::new(ScalarExpression::ColumnRef(mapping_column.clone())), | ||
alias: AliasType::Expr(Box::new(ScalarExpression::ColumnRef( | ||
ColumnRef::from(column), | ||
))), | ||
} | ||
}) | ||
.collect_vec(); | ||
plan = self.bind_project(plan, exprs)?; | ||
} | ||
|
||
Ok(LogicalPlan::new( | ||
Operator::CreateView(CreateViewOperator { | ||
view: View { | ||
name: view_name, | ||
plan: Box::new(plan), | ||
}, | ||
or_replace: *or_replace, | ||
}), | ||
vec![], | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.