Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to release-v0.13.1 #992

Merged
merged 25 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d9532e6
Merge pull request #952 from gluesql/release-v0.13
panarch Oct 19, 2022
9ee2b11
Fix README.md path in pkg/rust/Cargo.toml
panarch Oct 19, 2022
a7529f2
Move [profile.release] config from pkg/rust/Cargo.toml to root /Cargo…
panarch Oct 19, 2022
3557d48
Update AST builder ExprNode to contain borrowed values, (#961)
panarch Oct 20, 2022
29e9bd2
Set "PRIMARY" as a reserved keyword for index names (#960)
devgony Oct 20, 2022
75cf370
Remove `macro-exports` in `data/../macros` (#962)
ever0de Oct 22, 2022
e0d645c
Remove Cow from Evaluated::Value (#963)
zmrdltl Oct 22, 2022
c674625
Update CONCAT function behavior - concat with null to return NULL (#899)
seonghun-dev Oct 22, 2022
59f271d
Change evaluate::function return types to Evaluated (#966)
zmrdltl Oct 22, 2022
80ebf7a
Update AST builder ExprNode & ExprList to accept borrowed values (#967)
panarch Oct 23, 2022
79e88ac
Change rust pkg lib example to use MemoryStorage (#968)
panarch Oct 26, 2022
9fb4d04
Add `Dictionary::GLUE_OBJECTS` to provide table and index metadata (#…
devgony Oct 27, 2022
07eb030
Expose wasm-pack's init function argument to users (#971)
arbfay Oct 29, 2022
d2a07dc
Implement CONCAT_WS function (#965)
seonghun-dev Oct 29, 2022
fe185da
Add concat_ws function to AST builder (#973)
seonghun-dev Oct 29, 2022
823e8e8
Add `UINT16` data type (#844)
ChobobDev Oct 29, 2022
ab9697a
Replace coverage badges to coveralls.io in pkg/javascript/README.md (…
panarch Oct 30, 2022
189dc01
Fix examples path in gh-action coverage.yml (#980)
panarch Oct 30, 2022
6fc167e
Remove `ast::ColumnOptionDef` (#983)
MRGRAVITY817 Nov 4, 2022
6fe7445
Remove ColumnDefExt trait in data::Schema, (#985)
panarch Nov 4, 2022
d3d2a9d
Cover all payloads on cli::print (#984)
devgony Nov 4, 2022
2a8e386
Add examples for MemoryStorage (#499)
pythonbrad Nov 6, 2022
2f14d28
Merge remote-tracking branch 'upstream/main' into release-v0.13.1-to-…
devgony Nov 8, 2022
2293efc
fix: handle U16 to Expr
devgony Nov 8, 2022
79d2177
test: fix case from fet_all_schemas to GLUE_OBJECTS due to `created` …
devgony Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update CONCAT function behavior - concat with null to return NULL (#899)
  • Loading branch information
seonghun-dev authored Oct 22, 2022
commit c6746252dadfc00920fe038f2e8c24b21342b39f
31 changes: 23 additions & 8 deletions core/src/executor/evaluate/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use {
data::Value,
result::Result,
},
std::cmp::{max, min},
std::{
cmp::{max, min},
ops::ControlFlow,
},
uuid::Uuid,
};

Expand Down Expand Up @@ -55,13 +58,25 @@ macro_rules! eval_to_float {
// --- text ---

pub fn concat(exprs: Vec<Evaluated<'_>>) -> Result<Value> {
exprs
.into_iter()
.map(|expr| expr.try_into())
.filter(|value| !matches!(value, Ok(Value::Null)))
.try_fold(Value::Str("".to_owned()), |left, right| {
Ok(left.concat(&right?))
})
enum BreakCase {
Null,
Err(crate::result::Error),
}

let control_flow = exprs.into_iter().map(|expr| expr.try_into()).try_fold(
Value::Str(String::new()),
|left, right: Result<Value>| match right {
Ok(value) if value.is_null() => ControlFlow::Break(BreakCase::Null),
Err(err) => ControlFlow::Break(BreakCase::Err(err)),
Ok(value) => ControlFlow::Continue(left.concat(&value)),
},
);

match control_flow {
ControlFlow::Continue(value) => Ok(value),
ControlFlow::Break(BreakCase::Null) => Ok(Value::Null),
ControlFlow::Break(BreakCase::Err(err)) => Err(err),
}
}

pub fn lower(name: String, expr: Evaluated<'_>) -> Result<Value> {
Expand Down
24 changes: 18 additions & 6 deletions test-suite/src/function/concat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::*,
gluesql_core::{prelude::Value::*, translate::TranslateError},
gluesql_core::{data::ValueError, prelude::Value::*, translate::TranslateError},
};

test_case!(concat, async move {
Expand Down Expand Up @@ -37,12 +37,24 @@ test_case!(concat, async move {

test!(
r#"select concat("ab", "cd", NULL, "ef") as myconcat from Concat;"#,
Ok(select!(
myconcat
Str;
"abcdef".to_owned()
))
Ok(select_with_null!(myconcat; Null))
);

test!(
r#"select concat() as myconcat from Concat;"#,
Err(TranslateError::FunctionArgsLengthNotMatchingMin {
name: "CONCAT".to_owned(),
expected_minimum: 1,
found: 0
}
.into())
);

test!(
r#"select concat(DATE "2020-06-11", DATE "2020-16-3") as myconcat from Concat;"#,
Err(ValueError::FailedToParseDate("2020-16-3".to_owned()).into())
);

// test with non string arguments
test!(
r#"select concat(123, 456, 3.14) as myconcat from Concat;"#,
Expand Down