Skip to content

Commit

Permalink
Merge branch 'main' into switch-new-planner
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Apr 21, 2022
2 parents 1ea9791 + e54bef9 commit 59d2f51
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion common/ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ common-functions = { path = "../functions" }
# TODO (andylokandy): Use the version from crates.io once
# https://github.com/brendanzab/codespan/pull/331 is released.
codespan-reporting = { git = "https://github.com/brendanzab/codespan", rev = "c84116f5" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "818c0f9" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }

# Crates.io dependencies
async-trait = "0.1.53"
Expand Down
29 changes: 16 additions & 13 deletions common/datavalues/src/types/type_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ pub struct DateTimeType {
/// tz indicates the timezone, if it's None, it's UTC.
tz: Option<String>,
}
const DATETIME_0: &str = "DateTime_0";
const DATETIME_3: &str = "DateTime_3";
const DATETIME_6: &str = "DateTime_6";
const DATETIME_9: &str = "DateTime_9";

impl DateTimeType {
pub fn create(precision: usize, tz: Option<String>) -> Self {
Expand Down Expand Up @@ -99,19 +95,22 @@ impl DataType for DateTimeType {

fn name(&self) -> &str {
match self.precision {
0 => DATETIME_0,
3 => DATETIME_3,
6 => DATETIME_6,
9 => DATETIME_9,
0 => "DateTime",
1 => "DateTime(1)",
2 => "DateTime(2)",
3 => "DateTime(3)",
4 => "DateTime(4)",
5 => "DateTime(5)",
6 => "DateTime(6)",
7 => "DateTime(7)",
8 => "DateTime(8)",
9 => "DateTime(9)",
_ => unreachable!(),
}
}

fn aliases(&self) -> &[&str] {
match self.precision {
0 => &["DateTime"],
_ => &[],
}
&[]
}

fn default_value(&self) -> DataValue {
Expand Down Expand Up @@ -172,6 +171,10 @@ impl DataType for DateTimeType {

impl std::fmt::Debug for DateTimeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "DateTime_{}", self.precision())
if self.precision() == 0 {
write!(f, "DateTime")
} else {
write!(f, "DateTime({})", self.precision())
}
}
}
2 changes: 1 addition & 1 deletion common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ tonic = "=0.6.2"

# Github dependencies
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "818c0f9" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
2 changes: 1 addition & 1 deletion common/functions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde_json = "1.0.79"
sha1 = "0.10.1"
sha2 = "0.10.2"
simdutf8 = "0.1.4"
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "818c0f9" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }
strength_reduce = "0.2.3"
twox-hash = "1.6.2"
uuid = { version = "0.8.2", features = ["v4"] }
Expand Down
2 changes: 1 addition & 1 deletion common/functions/tests/it/scalars/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ fn test_variant_cast_function() -> Result<()> {
VariantValue::from(json!("2021-10-24 10:10:10")),
])],
expect: Series::from_data(vec![1614906061i64, 1635070210]),
error: "Cast error happens in casting from Variant to DateTime_0",
error: "Cast error happens in casting from Variant to DateTime",
}),
];

Expand Down
2 changes: 1 addition & 1 deletion query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ common-tracing = { path = "../common/tracing" }
bincode = { git = "https://github.com/datafuse-extras/bincode", rev = "fd3f9ff" }
opensrv-clickhouse = { git = "https://github.com/datafuselabs/opensrv", rev = "9690be9", package = "opensrv-clickhouse" }
opensrv-mysql = { git = "https://github.com/datafuselabs/opensrv", rev = "967477f1", package = "opensrv-mysql" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "818c0f9" }
sqlparser = { git = "https://github.com/datafuse-extras/sqlparser-rs", rev = "49f4ec2" }

# Crates.io dependencies
ahash = "0.7.6"
Expand Down
12 changes: 11 additions & 1 deletion query/src/sql/sql_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ impl SQLCommon {
SQLDataType::Real | SQLDataType::Double => Ok(f64::to_data_type()),
SQLDataType::Boolean => Ok(bool::to_data_type()),
SQLDataType::Date => Ok(DateType::arc()),
SQLDataType::Timestamp => Ok(DateTimeType::arc(3, None)),
SQLDataType::Timestamp | SQLDataType::DateTime(None) => Ok(DateTimeType::arc(0, None)),
SQLDataType::DateTime(Some(precision)) => {
if *precision <= 9 {
Ok(DateTimeType::arc(*precision as usize, None))
} else {
Err(ErrorCode::IllegalDataType(format!(
"The SQL data type DateTime(n), n only ranges from 0~9, {} is invalid",
precision
)))
}
}

// Custom types for databend:
// Custom(ObjectName([Ident { value: "uint8", quote_style: None }])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ select 'UInt64 OP UInt64', typeof(65536 * 65536 + 65536 * 65536), typeof(65536 *

select '=== TEST_datetimes';

select typeof(now()) = 'DateTime_0';
select typeof(now()) = 'DateTime';
select typeof(today()) = 'Date';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ select toDateTime(1640019661), toInt64(toDateTime(1640019661)) = 1640019661;

select typeof(today() + 3) = 'DATE';
select typeof(today() - 3) = 'DATE';
select typeof(now() - 3) = 'DATETIME_0';
select typeof(toDateTime(1640019661)) = 'DATETIME_0';
select typeof(now() - 3) = 'DATETIME';
select typeof(toDateTime(1640019661)) = 'DATETIME';
select today() + 1 - today() = 1;

select typeof(today() - today()) = 'INT';
Expand Down Expand Up @@ -193,13 +193,13 @@ select toDateTime('2022-04-01 06:50:20') < '2022-04-02 04:50:20';

select '===INSERT===';
drop table if exists ts;
create table ts(a DateTime_3, b DateTime, c Date);
create table ts(a DateTime(3), b DateTime, c Date);
insert into ts values(now(), now(), today());
select toDateTime(a) = toDateTime(b) from ts;
drop table if exists ts;


create table t(d32 datetime, d64 datetime_3);
create table t(d32 datetime, d64 DateTime(3));

insert into t values('2022-04-02 15:10:28', '2022-04-02 15:10:28');
insert into t values('2022-04-02 15:10:28.221', '2022-04-02 15:10:28.221');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ bigint_unsigned BIGINT UNSIGNED NO 0
float FLOAT NO 0
double DOUBLE NO 0
date DATE NO 0
datetime DATETIME_0 NO 0
ts DATETIME_3 NO 0
datetime DATETIME NO 0
ts DATETIME NO 0
str VARCHAR NO 3
bool BOOLEAN NO false
array ARRAY NO []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Projection: 1:UInt8
Projection: (1 + 1):UInt16
Expression: 2:UInt16 (Before Projection)
ReadDataSource: scan schema: [a:Int32;N], statistics: [read_rows: 1, read_bytes: 4, partitions_scanned: 1, partitions_total: 1], push_downs: [projections: [0]]
Projection: now():DateTime_0
Expression: now():DateTime_0 (Before Projection)
Projection: now():DateTime
Expression: now():DateTime (Before Projection)
ReadDataSource: scan schema: [a:Int32;N], statistics: [read_rows: 1, read_bytes: 4, partitions_scanned: 1, partitions_total: 1], push_downs: [projections: [0]]
Projection: sum(a):Nullable(Int64)
AggregatorFinal: groupBy=[[]], aggr=[[sum(a)]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RedistributeStage[expr: 0]
Expression: 2:UInt16 (Before Projection)
ReadDataSource: scan schema: [a:Int32;N], statistics: [read_rows: 1, read_bytes: 4, partitions_scanned: 1, partitions_total: 1], push_downs: [projections: [0]]
RedistributeStage[expr: 0]
Projection: now():DateTime_0
Expression: now():DateTime_0 (Before Projection)
Projection: now():DateTime
Expression: now():DateTime (Before Projection)
ReadDataSource: scan schema: [a:Int32;N], statistics: [read_rows: 1, read_bytes: 4, partitions_scanned: 1, partitions_total: 1], push_downs: [projections: [0]]
Projection: sum(a):Nullable(Int64)
AggregatorFinal: groupBy=[[]], aggr=[[sum(a)]]
Expand Down

0 comments on commit 59d2f51

Please sign in to comment.