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

chore(query): introduce TzLUT util #9920

Merged
merged 9 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/query/expression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ chrono = { workspace = true }
chrono-tz = { workspace = true }
comfy-table = "6"
common-jsonb = { path = "../../common/jsonb" }
dashmap = "5.4"
educe = "0.4"
enum-as-inner = "0.5"
enum_dispatch = "0.3.8"
Expand All @@ -34,6 +35,7 @@ lexical-core = "0.8.5"
match-template = "0.0.1"
micromarshal = "0.2.1"
num-traits = "0.2.15"
once_cell = "1.15.0"
ordered-float = { workspace = true, features = ["serde", "rand"] }
parking_lot = "0.12.1"
primitive-types = "0.12.0"
Expand Down
14 changes: 4 additions & 10 deletions src/query/expression/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::collections::HashMap;
use std::ops::BitAnd;
use std::sync::Arc;

use chrono_tz::Tz;
use common_arrow::arrow::bitmap::Bitmap;
use common_arrow::arrow::bitmap::MutableBitmap;
use common_exception::ErrorCode;
Expand All @@ -26,6 +25,7 @@ use itertools::Itertools;
use serde::Deserialize;
use serde::Serialize;

use crate::date_helper::TzLUT;
use crate::property::Domain;
use crate::property::FunctionProperty;
use crate::types::nullable::NullableColumn;
Expand All @@ -49,22 +49,16 @@ pub struct FunctionSignature {

pub type AutoCastSignature = Vec<(DataType, DataType)>;

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Default)]
pub struct FunctionContext {
pub tz: Tz,
}

impl Default for FunctionContext {
fn default() -> Self {
Self { tz: Tz::UTC }
}
pub tz: TzLUT,
}

#[derive(Clone)]
pub struct EvalContext<'a> {
pub generics: &'a GenericMap,
pub num_rows: usize,
pub tz: Tz,
pub tz: TzLUT,

/// Validity bitmap of outer nullable column. This is an optimization
/// to avoid recording errors on the NULL value which has a coresponding
Expand Down
12 changes: 6 additions & 6 deletions src/query/expression/src/types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

use std::ops::Range;

use chrono_tz::Tz;

use super::date::date_to_string;
use super::number::NumberScalar;
use super::timestamp::timestamp_to_string;
use crate::date_helper::TzLUT;
use crate::property::Domain;
use crate::types::string::StringColumn;
use crate::types::string::StringColumnBuilder;
Expand Down Expand Up @@ -170,7 +169,8 @@ impl ArgType for VariantType {
}
}

pub fn cast_scalar_to_variant(scalar: ScalarRef, tz: Tz, buf: &mut Vec<u8>) {
pub fn cast_scalar_to_variant(scalar: ScalarRef, tz: TzLUT, buf: &mut Vec<u8>) {
let inner_tz = tz.tz;
let value = match scalar {
ScalarRef::Null => common_jsonb::Value::Null,
ScalarRef::EmptyArray => common_jsonb::Value::Array(vec![]),
Expand All @@ -189,8 +189,8 @@ pub fn cast_scalar_to_variant(scalar: ScalarRef, tz: Tz, buf: &mut Vec<u8>) {
ScalarRef::Decimal(_) => todo!("decimal"),
ScalarRef::Boolean(b) => common_jsonb::Value::Bool(b),
ScalarRef::String(s) => common_jsonb::Value::String(String::from_utf8_lossy(s)),
ScalarRef::Timestamp(ts) => timestamp_to_string(ts, tz).to_string().into(),
ScalarRef::Date(d) => date_to_string(d, tz).to_string().into(),
ScalarRef::Timestamp(ts) => timestamp_to_string(ts, inner_tz).to_string().into(),
ScalarRef::Date(d) => date_to_string(d, inner_tz).to_string().into(),
ScalarRef::Array(col) => {
let items = cast_scalars_to_variants(col.iter(), tz);
common_jsonb::build_array(items.iter(), buf).expect("failed to build jsonb array");
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn cast_scalar_to_variant(scalar: ScalarRef, tz: Tz, buf: &mut Vec<u8>) {

pub fn cast_scalars_to_variants(
scalars: impl IntoIterator<Item = ScalarRef>,
tz: Tz,
tz: TzLUT,
) -> StringColumn {
let iter = scalars.into_iter();
let mut builder = StringColumnBuilder::with_capacity(iter.size_hint().0, 0);
Expand Down
Loading