Skip to content
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
17 changes: 8 additions & 9 deletions crates/sqllib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,39 +457,38 @@ macro_rules! some_function4 {
}

#[doc(hidden)]
pub fn [<$func_name N__N>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: Option<$arg_type2>, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
pub fn [<$func_name N__N>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: $arg_type2, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
let arg0 = arg0?;
let arg2 = arg2?;
let arg3 = arg3?;
Some([<$func_name ____>](arg0, arg1, arg2, arg3))
}

#[doc(hidden)]
pub fn [<$func_name N_N_>]( arg0: Option<$arg_type0>, arg1: Option<$arg_type1>, arg2: $arg_type2, arg3: $arg_type3 ) -> Option<$ret_type> {
pub fn [<$func_name N_N_>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: Option<$arg_type2>, arg3: $arg_type3 ) -> Option<$ret_type> {
let arg0 = arg0?;
let arg1 = arg1?;
let arg2 = arg2?;
Some([<$func_name ____>](arg0, arg1, arg2, arg3))
}

#[doc(hidden)]
pub fn [<$func_name N_NN>]( arg0: Option<$arg_type0>, arg1: Option<$arg_type1>, arg2: Option<$arg_type2>, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
pub fn [<$func_name N_NN>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: Option<$arg_type2>, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
let arg0 = arg0?;
let arg1 = arg1?;
let arg2 = arg2?;
let arg3 = arg3?;
Some([<$func_name ____>](arg0, arg1, arg2, arg3))
}

#[doc(hidden)]
pub fn [<$func_name NN__>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: $arg_type2, arg3: $arg_type3 ) -> Option<$ret_type> {
pub fn [<$func_name NN__>]( arg0: Option<$arg_type0>, arg1: Option<$arg_type1>, arg2: $arg_type2, arg3: $arg_type3 ) -> Option<$ret_type> {
let arg0 = arg0?;
let arg1 = arg1?;
Some([<$func_name ____>](arg0, arg1, arg2, arg3))
}

#[doc(hidden)]
pub fn [<$func_name NN_N>]( arg0: Option<$arg_type0>, arg1: $arg_type1, arg2: Option<$arg_type2>, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
pub fn [<$func_name NN_N>]( arg0: Option<$arg_type0>, arg1: Option<$arg_type1>, arg2: $arg_type2, arg3: Option<$arg_type3> ) -> Option<$ret_type> {
let arg0 = arg0?;
let arg2 = arg2?;
let arg1 = arg1?;
let arg3 = arg3?;
Some([<$func_name ____>](arg0, arg1, arg2, arg3))
}
Expand Down
28 changes: 28 additions & 0 deletions crates/sqllib/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,13 @@ pub fn date_trunc_year_Timestamp(timestamp: Timestamp) -> Timestamp {
Timestamp::from_date(dt)
}

#[doc(hidden)]
pub fn date_trunc_quarter_Timestamp(timestamp: Timestamp) -> Timestamp {
let dt = timestamp.get_date();
let dt = date_trunc_quarter_Date(dt);
Timestamp::from_date(dt)
}

#[doc(hidden)]
pub fn date_trunc_month_Timestamp(timestamp: Timestamp) -> Timestamp {
let dt = timestamp.get_date();
Expand All @@ -1877,6 +1884,7 @@ some_polymorphic_function1!(date_trunc_millennium, Timestamp, Timestamp, Timesta
some_polymorphic_function1!(date_trunc_century, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_decade, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_year, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_quarter, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_month, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_week, Timestamp, Timestamp, Timestamp);
some_polymorphic_function1!(date_trunc_day, Timestamp, Timestamp, Timestamp);
Expand All @@ -1901,6 +1909,11 @@ pub fn timestamp_trunc_year_Timestamp(timestamp: Timestamp) -> Timestamp {
date_trunc_year_Timestamp(timestamp)
}

#[doc(hidden)]
pub fn timestamp_trunc_quarter_Timestamp(timestamp: Timestamp) -> Timestamp {
date_trunc_quarter_Timestamp(timestamp)
}

#[doc(hidden)]
pub fn timestamp_trunc_month_Timestamp(timestamp: Timestamp) -> Timestamp {
date_trunc_month_Timestamp(timestamp)
Expand Down Expand Up @@ -1985,6 +1998,20 @@ pub fn date_trunc_year_Date(date: Date) -> Date {
Date::from_date(rounded)
}

#[doc(hidden)]
pub fn date_trunc_quarter_Date(date: Date) -> Date {
let date = date.to_dateTime();
let month = match date.month() {
1..=3 => 1,
4..=6 => 4,
7..=9 => 7,
10..=12 => 10,
_ => unreachable!(),
};
let rounded = NaiveDate::from_ymd_opt(date.year(), month, 1).unwrap();
Date::from_date(rounded)
}

#[doc(hidden)]
pub fn date_trunc_month_Date(date: Date) -> Date {
let date = date.to_dateTime();
Expand All @@ -2009,6 +2036,7 @@ some_polymorphic_function1!(date_trunc_millennium, Date, Date, Date);
some_polymorphic_function1!(date_trunc_century, Date, Date, Date);
some_polymorphic_function1!(date_trunc_decade, Date, Date, Date);
some_polymorphic_function1!(date_trunc_year, Date, Date, Date);
some_polymorphic_function1!(date_trunc_quarter, Date, Date, Date);
some_polymorphic_function1!(date_trunc_month, Date, Date, Date);
some_polymorphic_function1!(date_trunc_week, Date, Date, Date);
some_polymorphic_function1!(date_trunc_day, Date, Date, Date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ DBSPExpression convertToRawTuple(
DBSPType convertedType = new DBSPTypeMap(type.getKeyType(), type.getValueType(), sourceType.mayBeNull);
return new DBSPBinaryExpression(node,
convertedType, DBSPOpcode.MAP_CONVERT,
source, new DBSPRawTupleExpression(convertKey, convertValue));
source.applyClone(), new DBSPRawTupleExpression(convertKey, convertValue));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -823,4 +823,54 @@ public void jsonTests() {
jsonstring_as_a_t("data")."b"."y"."value" AS "y_val"
FROM src;""");
}

@Test
public void issue5899a() {
this.getCCS("""
CREATE TABLE F(file_id INT, original_path VARCHAR, replacement VARCHAR);
CREATE VIEW V AS SELECT file_id, original_path,
OVERLAY(original_path PLACING replacement FROM 10 FOR 4) AS updated_path
FROM F WHERE original_path IS NOT NULL AND replacement IS NOT NULL;""");
boolean[] b = new boolean[] { false, true };
for (var a1: b)
for (var a2: b)
for (var a3: b)
for (var a4: b) {
var e1 = a1 ? "x" : "y";
var e2 = a2 ? "x" : "y";
var e3 = a3 ? "1" : "NULL";
var e4 = a4 ? "1" : "NULL";
String query = "CREATE TABLE T(x VARCHAR NOT NULL, y VARCHAR, i INT NOT NULL);";
query += "CREATE VIEW V AS SELECT OVERLAY(" + e1 +
" PLACING " + e2 + " FROM " + e3 + " FOR " + e4 + ") FROM T;";
this.getCCS(query);
}
}

@Test
public void issue5899b() {
this.getCCS("""
CREATE VIEW V AS
SELECT COUNT(*)
FROM (
VALUES
(CAST(ROW(ARRAY[MAP[1, 2, 2, 3], MAP[1, 3]]) AS ROW(b MAP<INT, INT> ARRAY))),
(CAST(ROW(ARRAY[MAP[2, 3], MAP[1, 3]]) AS ROW(b MAP<INT, INT> ARRAY))),
(CAST(ROW(ARRAY[MAP[2, 3, 1, 2], MAP[1, 3]]) AS ROW(b MAP<INT, INT> ARRAY)))
) AS t(a)
GROUP BY a""");
}

@Test
public void issue5899c() {
var ccs = this.getCCS("""
CREATE TABLE E(hire_date DATE);
CREATE VIEW Q AS
SELECT DATE_TRUNC(hire_date, QUARTER) FROM E;""");
ccs.step("INSERT INTO E VALUES (DATE '2020-02-01') , (DATE '2020-05-01')", """
trunc | weight
----------------
2020-01-01 | 1
2020-04-01 | 1""");
}
}