Skip to content

Commit

Permalink
slt update
Browse files Browse the repository at this point in the history
  • Loading branch information
taytzehao committed Sep 25, 2023
1 parent 053b9b2 commit 90c1405
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ message ExprNode {
HEX_TO_INT256 = 560;

// Jsonb functions


// jsonb -> int, jsonb -> text, jsonb #> text[] that returns jsonb
JSONB_ACCESS_INNER = 600;
Expand Down
1 change: 0 additions & 1 deletion src/common/src/types/jsonb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ impl From<Value> for JsonbVal {
}
}


impl<'a> JsonbRef<'a> {
pub fn memcmp_serialize(
&self,
Expand Down
23 changes: 10 additions & 13 deletions src/expr/src/vector_op/jsonb_concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ use serde_json::{json, Value};
/// SELECT '1'::jsonb || '2'::jsonb;
/// ----
/// [1, 2]
///
///
/// query T
/// SELECT '[1,2]'::jsonb || NULL::jsonb;
/// ----
/// NULL
///
/// null
///
/// query T
/// SELECT NULL::jsonb || '[1,2]'::jsonb;
/// ----
/// NULL
/// null
/// ```
#[function("jsonb_cat(jsonb, jsonb) -> jsonb")]
pub fn jsonb_cat(left: Option<JsonbRef<'_>>, right: Option<JsonbRef<'_>>) -> JsonbVal {
let left_val = left.map_or(Value::Null,|v| v.value().clone());
let right_val = right.map_or(Value::Null,|v| v.value().clone());
let left_val = left.map_or(Value::Null, |v| v.value().clone());
let right_val = right.map_or(Value::Null, |v| v.value().clone());
match (left_val, right_val) {
// left and right are object based.
// This would have left:{'a':1}, right:{'b':2} -> {'a':1,'b':2}
Expand All @@ -75,20 +75,17 @@ pub fn jsonb_cat(left: Option<JsonbRef<'_>>, right: Option<JsonbRef<'_>>) -> Jso
// One operand is an array, and the other is a single element.
// This would insert the non-array value as another element into the array
// Eg left:[1,2] right: {'a':1} -> [1,2,{'a':1}]
(Value::Array(mut left_arr), single_val)
| (single_val, Value::Array(mut left_arr))
if single_val != Value::Null => {
(Value::Array(mut left_arr), single_val) | (single_val, Value::Array(mut left_arr))
if single_val != Value::Null =>
{
left_arr.push(single_val);
JsonbVal::from(Value::Array(left_arr))
}

// Either left/right is None
// This return a None value
// This would have left:[1,2], right:None -> None
(Value::Null, _)
| (_, Value::Null) => {
JsonbVal::from(Value::Null)
}
(Value::Null, _) | (_, Value::Null) => JsonbVal::from(Value::Null),

// Both are non-array inputs.
// Both elements would be placed together in an array
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/binder/expr/binary_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl Binder {
ExprType::ConcatOp
}

(Some(DataType::Jsonb), Some(DataType::Jsonb))
| (Some(DataType::Jsonb), None)
| (None, Some(DataType::Jsonb))=> ExprType::JsonbCat,
(Some(DataType::Jsonb), Some(DataType::Jsonb))
| (Some(DataType::Jsonb), None)
| (None, Some(DataType::Jsonb)) => ExprType::JsonbCat,

// bytea (and varbit, tsvector, tsquery)
(Some(t @ DataType::Bytea), Some(DataType::Bytea))
Expand Down

0 comments on commit 90c1405

Please sign in to comment.