Skip to content

Commit 83fa549

Browse files
committed
fix
1 parent 5977d7f commit 83fa549

File tree

5 files changed

+65
-49
lines changed

5 files changed

+65
-49
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ color-eyre = { git = "https://github.com/eyre-rs/eyre.git", rev = "e5d92c3" }
638638
deltalake = { git = "https://github.com/delta-io/delta-rs", rev = "c149502" }
639639
display-more = { git = "https://github.com/databendlabs/display-more", tag = "v0.1.2" }
640640
ethnum = { git = "https://github.com/datafuse-extras/ethnum-rs", rev = "4cb05f1" }
641-
jsonb = { git = "https://github.com/b41sh/jsonb", rev = "4c8c2feedbfcfcf04db6e76a887b59f63ff4417d" }
641+
jsonb = { git = "https://github.com/b41sh/jsonb", rev = "e59567b08e4a3db886764096305b3be74c8e1e13" }
642642
map-api = { git = "https://github.com/databendlabs/map-api", tag = "v0.2.3" }
643643
openai_api_rust = { git = "https://github.com/datafuse-extras/openai-api", rev = "819a0ed" }
644644
openraft = { git = "https://github.com/databendlabs/openraft", tag = "v0.10.0-alpha.9" }

src/query/expression/src/types/variant.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ use super::date::date_to_string;
3131
use super::number::NumberScalar;
3232
use super::timestamp::timestamp_to_string;
3333
use crate::property::Domain;
34-
use crate::types::interval::interval_to_string;
3534
use crate::types::map::KvPair;
3635
use crate::types::AnyType;
3736
use crate::types::ArgType;
3837
use crate::types::DataType;
38+
use crate::types::DecimalScalar;
3939
use crate::types::DecimalSize;
4040
use crate::types::GenericMap;
4141
use crate::types::ValueType;
@@ -230,32 +230,34 @@ pub fn cast_scalar_to_variant(scalar: ScalarRef, tz: &TimeZone, buf: &mut Vec<u8
230230
NumberScalar::Float32(n) => n.0.into(),
231231
NumberScalar::Float64(n) => n.0.into(),
232232
},
233-
ScalarRef::Decimal(x) => {
234-
/**
235-
match x {
236-
DecimalScalar::Decimal128(value, size) => {
237-
let dec = jsonb::Decimal128 {
238-
scale: size.scale,
239-
value,
240-
};
241-
jsonb::Value::Number(jsonb::Number::Decimal128(dec))
242-
}
243-
DecimalScalar::Decimal256(value, size) => {
244-
let dec = jsonb::Decimal256 {
245-
scale: size.scale,
246-
value,
247-
};
248-
jsonb::Value::Number(jsonb::Number::Decimal256(dec))
249-
}
233+
ScalarRef::Decimal(x) => match x {
234+
DecimalScalar::Decimal128(value, size) => {
235+
let dec = jsonb::Decimal128 {
236+
scale: size.scale,
237+
value,
238+
};
239+
jsonb::Value::Number(jsonb::Number::Decimal128(dec))
250240
}
251-
*/
252-
todo!()
253-
}
241+
DecimalScalar::Decimal256(_value, _size) => {
242+
// let dec = jsonb::Decimal256 {
243+
// scale: size.scale,
244+
// value,
245+
//};
246+
// jsonb::Value::Number(jsonb::Number::Decimal256(dec))
247+
todo!()
248+
}
249+
},
254250
ScalarRef::Boolean(b) => jsonb::Value::Bool(b),
255251
ScalarRef::Binary(s) => jsonb::Value::Binary(s),
256252
ScalarRef::String(s) => jsonb::Value::String(s.into()),
257-
ScalarRef::Timestamp(ts) => jsonb::Value::Timestamp(jsonb::Timestamp {offset:0, value: ts}),
258-
ScalarRef::Date(d) => jsonb::Value::Date(jsonb::Date {offset:0, value: d}),
253+
ScalarRef::Timestamp(ts) => jsonb::Value::Timestamp(jsonb::Timestamp {
254+
offset: 0,
255+
value: ts,
256+
}),
257+
ScalarRef::Date(d) => jsonb::Value::Date(jsonb::Date {
258+
offset: 0,
259+
value: d,
260+
}),
259261
ScalarRef::Interval(i) => {
260262
let interval = jsonb::Interval {
261263
months: i.months(),

src/query/functions/src/scalars/variant.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use std::collections::HashSet;
1818
use std::iter::once;
1919
use std::sync::Arc;
2020

21-
use databend_common_expression::types::BinaryType;
2221
use bstr::ByteSlice;
22+
use databend_common_column::types::months_days_micros;
2323
use databend_common_expression::types::binary::BinaryColumnBuilder;
2424
use databend_common_expression::types::date::string_to_date;
2525
use databend_common_expression::types::nullable::NullableColumn;
@@ -32,11 +32,13 @@ use databend_common_expression::types::variant::cast_scalar_to_variant;
3232
use databend_common_expression::types::variant::cast_scalars_to_variants;
3333
use databend_common_expression::types::AnyType;
3434
use databend_common_expression::types::ArrayType;
35+
use databend_common_expression::types::BinaryType;
3536
use databend_common_expression::types::Bitmap;
3637
use databend_common_expression::types::BooleanType;
3738
use databend_common_expression::types::DataType;
3839
use databend_common_expression::types::DateType;
3940
use databend_common_expression::types::GenericType;
41+
use databend_common_expression::types::IntervalType;
4042
use databend_common_expression::types::MutableBitmap;
4143
use databend_common_expression::types::NullableType;
4244
use databend_common_expression::types::NumberDataType;
@@ -767,37 +769,41 @@ pub fn register(registry: &mut FunctionRegistry) {
767769
registry.register_combine_nullable_1_arg::<VariantType, TimestampType, _, _>(
768770
"as_timestamp",
769771
|_, _| FunctionDomain::Full,
770-
vectorize_with_builder_1_arg::<VariantType, NullableType<TimestampType>>(|v, output, ctx| {
771-
if let Some(validity) = &ctx.validity {
772-
if !validity.get_bit(output.len()) {
773-
output.push_null();
774-
return;
772+
vectorize_with_builder_1_arg::<VariantType, NullableType<TimestampType>>(
773+
|v, output, ctx| {
774+
if let Some(validity) = &ctx.validity {
775+
if !validity.get_bit(output.len()) {
776+
output.push_null();
777+
return;
778+
}
775779
}
776-
}
777-
match RawJsonb::new(v).as_timestamp() {
778-
Ok(Some(res)) => output.push(res.value),
779-
_ => output.push_null(),
780-
}
781-
}),
780+
match RawJsonb::new(v).as_timestamp() {
781+
Ok(Some(res)) => output.push(res.value),
782+
_ => output.push_null(),
783+
}
784+
},
785+
),
782786
);
783787

784788
registry.register_combine_nullable_1_arg::<VariantType, IntervalType, _, _>(
785789
"as_interval",
786790
|_, _| FunctionDomain::Full,
787-
vectorize_with_builder_1_arg::<VariantType, NullableType<IntervalType>>(|v, output, ctx| {
788-
if let Some(validity) = &ctx.validity {
789-
if !validity.get_bit(output.len()) {
790-
output.push_null();
791-
return;
791+
vectorize_with_builder_1_arg::<VariantType, NullableType<IntervalType>>(
792+
|v, output, ctx| {
793+
if let Some(validity) = &ctx.validity {
794+
if !validity.get_bit(output.len()) {
795+
output.push_null();
796+
return;
797+
}
792798
}
793-
}
794-
match RawJsonb::new(v).as_interval() {
795-
Ok(Some(res)) => {
796-
todo!()
799+
match RawJsonb::new(v).as_interval() {
800+
Ok(Some(res)) => {
801+
output.push(months_days_micros::new(res.months, res.days, res.micros))
802+
}
803+
_ => output.push_null(),
797804
}
798-
_ => output.push_null(),
799-
}
800-
}),
805+
},
806+
),
801807
);
802808

803809
registry.register_combine_nullable_1_arg::<VariantType, VariantType, _, _>(

src/query/functions/tests/it/scalars/testdata/function_list.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,24 @@ Functions overloads:
201201
0 arrays_zip FACTORY
202202
0 as_array(Variant) :: Variant NULL
203203
1 as_array(Variant NULL) :: Variant NULL
204+
0 as_binary(Variant) :: Binary NULL
205+
1 as_binary(Variant NULL) :: Binary NULL
204206
0 as_boolean(Variant) :: Boolean NULL
205207
1 as_boolean(Variant NULL) :: Boolean NULL
208+
0 as_date(Variant) :: Date NULL
209+
1 as_date(Variant NULL) :: Date NULL
206210
0 as_float(Variant) :: Float64 NULL
207211
1 as_float(Variant NULL) :: Float64 NULL
208212
0 as_integer(Variant) :: Int64 NULL
209213
1 as_integer(Variant NULL) :: Int64 NULL
214+
0 as_interval(Variant) :: Interval NULL
215+
1 as_interval(Variant NULL) :: Interval NULL
210216
0 as_object(Variant) :: Variant NULL
211217
1 as_object(Variant NULL) :: Variant NULL
212218
0 as_string(Variant) :: String NULL
213219
1 as_string(Variant NULL) :: String NULL
220+
0 as_timestamp(Variant) :: Timestamp NULL
221+
1 as_timestamp(Variant NULL) :: Timestamp NULL
214222
0 ascii(String) :: UInt8
215223
1 ascii(String NULL) :: UInt8 NULL
216224
0 asin(Float64) :: Float64

0 commit comments

Comments
 (0)