diff --git a/packages/cubejs-backend-native/Cargo.lock b/packages/cubejs-backend-native/Cargo.lock index 5f74584f1932f..58c638a3cf013 100644 --- a/packages/cubejs-backend-native/Cargo.lock +++ b/packages/cubejs-backend-native/Cargo.lock @@ -112,7 +112,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "arrow" version = "11.1.0" -source = "git+https://github.com/cube-js/arrow-rs.git?rev=db18b5c398ba5554fc774544cec4b713445102bf#db18b5c398ba5554fc774544cec4b713445102bf" +source = "git+https://github.com/cube-js/arrow-rs.git?rev=8fd2aa80114d5c0d4e6a0c370729507a4424e7b3#8fd2aa80114d5c0d4e6a0c370729507a4424e7b3" dependencies = [ "bitflags 1.3.2", "chrono", @@ -689,7 +689,7 @@ dependencies = [ [[package]] name = "cube-ext" version = "1.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "arrow", "chrono", @@ -809,7 +809,7 @@ checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "datafusion" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -842,7 +842,7 @@ dependencies = [ [[package]] name = "datafusion-common" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "arrow", "ordered-float 2.10.1", @@ -853,7 +853,7 @@ dependencies = [ [[package]] name = "datafusion-data-access" version = "1.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "async-trait", "chrono", @@ -866,7 +866,7 @@ dependencies = [ [[package]] name = "datafusion-expr" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -877,7 +877,7 @@ dependencies = [ [[package]] name = "datafusion-physical-expr" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -2037,7 +2037,7 @@ dependencies = [ [[package]] name = "parquet" version = "11.1.0" -source = "git+https://github.com/cube-js/arrow-rs.git?rev=db18b5c398ba5554fc774544cec4b713445102bf#db18b5c398ba5554fc774544cec4b713445102bf" +source = "git+https://github.com/cube-js/arrow-rs.git?rev=8fd2aa80114d5c0d4e6a0c370729507a4424e7b3#8fd2aa80114d5c0d4e6a0c370729507a4424e7b3" dependencies = [ "arrow", "base64 0.13.1", diff --git a/rust/cubesql/Cargo.lock b/rust/cubesql/Cargo.lock index bb2ed766e16f6..492000b8bd03a 100644 --- a/rust/cubesql/Cargo.lock +++ b/rust/cubesql/Cargo.lock @@ -127,7 +127,7 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "arrow" version = "11.1.0" -source = "git+https://github.com/cube-js/arrow-rs.git?rev=db18b5c398ba5554fc774544cec4b713445102bf#db18b5c398ba5554fc774544cec4b713445102bf" +source = "git+https://github.com/cube-js/arrow-rs.git?rev=8fd2aa80114d5c0d4e6a0c370729507a4424e7b3#8fd2aa80114d5c0d4e6a0c370729507a4424e7b3" dependencies = [ "bitflags 1.3.2", "chrono", @@ -739,7 +739,7 @@ dependencies = [ [[package]] name = "cube-ext" version = "1.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "arrow", "chrono", @@ -872,7 +872,7 @@ dependencies = [ [[package]] name = "datafusion" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -905,7 +905,7 @@ dependencies = [ [[package]] name = "datafusion-common" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "arrow", "ordered-float 2.10.0", @@ -916,7 +916,7 @@ dependencies = [ [[package]] name = "datafusion-data-access" version = "1.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "async-trait", "chrono", @@ -929,7 +929,7 @@ dependencies = [ [[package]] name = "datafusion-expr" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -940,7 +940,7 @@ dependencies = [ [[package]] name = "datafusion-physical-expr" version = "7.0.0" -source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=f99263552906b5b9fb22d679cb466876057d95e9#f99263552906b5b9fb22d679cb466876057d95e9" +source = "git+https://github.com/cube-js/arrow-datafusion.git?rev=bba28d60b4a048afb18944cc0ded1141437bd7c3#bba28d60b4a048afb18944cc0ded1141437bd7c3" dependencies = [ "ahash 0.7.8", "arrow", @@ -2067,7 +2067,7 @@ dependencies = [ [[package]] name = "parquet" version = "11.1.0" -source = "git+https://github.com/cube-js/arrow-rs.git?rev=db18b5c398ba5554fc774544cec4b713445102bf#db18b5c398ba5554fc774544cec4b713445102bf" +source = "git+https://github.com/cube-js/arrow-rs.git?rev=8fd2aa80114d5c0d4e6a0c370729507a4424e7b3#8fd2aa80114d5c0d4e6a0c370729507a4424e7b3" dependencies = [ "arrow", "base64 0.13.0", diff --git a/rust/cubesql/cubesql/Cargo.toml b/rust/cubesql/cubesql/Cargo.toml index 40e1939b0663a..359e03bc365e3 100644 --- a/rust/cubesql/cubesql/Cargo.toml +++ b/rust/cubesql/cubesql/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://cube.dev" [dependencies] arc-swap = "1" -datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "f99263552906b5b9fb22d679cb466876057d95e9", default-features = false, features = ["regex_expressions", "unicode_expressions"] } +datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "bba28d60b4a048afb18944cc0ded1141437bd7c3", default-features = false, features = ["regex_expressions", "unicode_expressions"] } anyhow = "1.0" thiserror = "1.0.50" cubeclient = { path = "../cubeclient" } diff --git a/rust/cubesql/cubesql/src/compile/mod.rs b/rust/cubesql/cubesql/src/compile/mod.rs index e821cb3006fbf..523fab04a3358 100644 --- a/rust/cubesql/cubesql/src/compile/mod.rs +++ b/rust/cubesql/cubesql/src/compile/mod.rs @@ -10153,7 +10153,7 @@ ORDER BY async fn test_interval_mul() -> Result<(), CubeError> { let base_timestamp = "TO_TIMESTAMP('2020-01-01 00:00:00', 'yyyy-MM-dd HH24:mi:ss')"; let units = vec!["year", "month", "week", "day", "hour", "minute", "second"]; - let multiplicands = vec![1, 5, -10]; + let multiplicands = vec!["1", "5", "-10", "1.5"]; let selects = units .iter() @@ -10185,6 +10185,42 @@ ORDER BY Ok(()) } + #[tokio::test] + async fn test_interval_div() -> Result<(), CubeError> { + let base_timestamp = "TO_TIMESTAMP('2020-01-01 00:00:00', 'yyyy-MM-dd HH24:mi:ss')"; + let units = vec!["year", "month", "week", "day", "hour", "minute", "second"]; + let divisors = vec!["1.5"]; + + let selects = units + .iter() + .enumerate() + .map(|(i, unit)| { + let columns = divisors + .iter() + .map(|divisor| { + // Brackets around interval are necessary due to bug in sqlparser + // See https://github.com/sqlparser-rs/sqlparser-rs/issues/1345 + // TODO remove brackets once fixed + format!( + "{base_timestamp} + (interval '1 {unit}') / {divisor} AS \"i/{divisor}\"" + ) + }) + .collect::>(); + format!( + "SELECT {i} AS id, '{unit}' AS unit, {}", + columns.join(", ") + ) + }) + .collect::>(); + let query = format!("{} ORDER BY id ASC", selects.join(" UNION ALL ")); + insta::assert_snapshot!( + "interval_div", + execute_query(query, DatabaseProtocol::PostgreSQL).await? + ); + + Ok(()) + } + #[tokio::test] async fn test_interval_sum() -> Result<(), CubeError> { init_logger(); diff --git a/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_div.snap b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_div.snap new file mode 100644 index 0000000000000..07090d7282cd9 --- /dev/null +++ b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_div.snap @@ -0,0 +1,15 @@ +--- +source: cubesql/src/compile/mod.rs +expression: "execute_query(query, DatabaseProtocol::PostgreSQL).await?" +--- ++----+--------+-------------------------+ +| id | unit | i/1.5 | ++----+--------+-------------------------+ +| 0 | year | 2020-09-01T00:00:00.000 | +| 1 | month | 2020-01-21T00:00:00.000 | +| 2 | week | 2020-01-05T16:00:00.000 | +| 3 | day | 2020-01-01T16:00:00.000 | +| 4 | hour | 2020-01-01T00:40:00.000 | +| 5 | minute | 2020-01-01T00:00:40.000 | +| 6 | second | 2020-01-01T00:00:00.666 | ++----+--------+-------------------------+ diff --git a/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_mul.snap b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_mul.snap index 22a2d0504d1aa..81c159f054027 100644 --- a/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_mul.snap +++ b/rust/cubesql/cubesql/src/compile/snapshots/cubesql__compile__tests__interval_mul.snap @@ -2,14 +2,14 @@ source: cubesql/src/compile/mod.rs expression: "execute_query(query, DatabaseProtocol::PostgreSQL).await?" --- -+----+--------+-------------------------+-------------------------+-------------------------+ -| id | unit | i*1 | i*5 | i*-10 | -+----+--------+-------------------------+-------------------------+-------------------------+ -| 0 | year | 2021-01-01T00:00:00.000 | 2025-01-01T00:00:00.000 | 2010-01-01T00:00:00.000 | -| 1 | month | 2020-02-01T00:00:00.000 | 2020-06-01T00:00:00.000 | 2019-03-01T00:00:00.000 | -| 2 | week | 2020-01-08T00:00:00.000 | 2020-02-05T00:00:00.000 | 2019-10-23T00:00:00.000 | -| 3 | day | 2020-01-02T00:00:00.000 | 2020-01-06T00:00:00.000 | 2019-12-22T00:00:00.000 | -| 4 | hour | 2020-01-01T01:00:00.000 | 2020-01-01T05:00:00.000 | 2019-12-31T14:00:00.000 | -| 5 | minute | 2020-01-01T00:01:00.000 | 2020-01-01T00:05:00.000 | 2019-12-31T23:50:00.000 | -| 6 | second | 2020-01-01T00:00:01.000 | 2020-01-01T00:00:05.000 | 2019-12-31T23:59:50.000 | -+----+--------+-------------------------+-------------------------+-------------------------+ ++----+--------+-------------------------+-------------------------+-------------------------+-------------------------+ +| id | unit | i*1 | i*5 | i*-10 | i*1.5 | ++----+--------+-------------------------+-------------------------+-------------------------+-------------------------+ +| 0 | year | 2021-01-01T00:00:00.000 | 2025-01-01T00:00:00.000 | 2010-01-01T00:00:00.000 | 2021-07-01T00:00:00.000 | +| 1 | month | 2020-02-01T00:00:00.000 | 2020-06-01T00:00:00.000 | 2019-03-01T00:00:00.000 | 2020-02-16T00:00:00.000 | +| 2 | week | 2020-01-08T00:00:00.000 | 2020-02-05T00:00:00.000 | 2019-10-23T00:00:00.000 | 2020-01-11T12:00:00.000 | +| 3 | day | 2020-01-02T00:00:00.000 | 2020-01-06T00:00:00.000 | 2019-12-22T00:00:00.000 | 2020-01-02T12:00:00.000 | +| 4 | hour | 2020-01-01T01:00:00.000 | 2020-01-01T05:00:00.000 | 2019-12-31T14:00:00.000 | 2020-01-01T01:30:00.000 | +| 5 | minute | 2020-01-01T00:01:00.000 | 2020-01-01T00:05:00.000 | 2019-12-31T23:50:00.000 | 2020-01-01T00:01:30.000 | +| 6 | second | 2020-01-01T00:00:01.000 | 2020-01-01T00:00:05.000 | 2019-12-31T23:59:50.000 | 2020-01-01T00:00:01.500 | ++----+--------+-------------------------+-------------------------+-------------------------+-------------------------+