Skip to content

Commit

Permalink
fix: support decimal mul interval (risingwavelabs#3734)
Browse files Browse the repository at this point in the history
  • Loading branch information
neverchanje authored Jul 7, 2022
1 parent 9b64fca commit 8d97480
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/expr/src/expr/expr_binary_nonnull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ pub fn new_binary_expr(
{ timestamp, interval, timestamp, timestamp_interval_add },
{ interval, timestamp, timestamp, interval_timestamp_add },
{ interval, date, timestamp, interval_date_add },
{ interval, time, time, interval_time_add },
{ date, interval, timestamp, date_interval_add },
{ date, int32, date, date_int_add },
{ int32, date, date, int_date_add },
Expand Down Expand Up @@ -397,14 +398,16 @@ pub fn new_binary_expr(
{ interval, int16, interval, interval_int_mul },
{ interval, int32, interval, interval_int_mul },
{ interval, int64, interval, interval_int_mul },
{interval, float32, interval, interval_float_mul },
{interval, float64, interval, interval_float_mul },
{ interval, float32, interval, interval_float_mul },
{ interval, float64, interval, interval_float_mul },
{ interval, decimal, interval, interval_float_mul },

{ int16, interval, interval, int_interval_mul },
{ int32, interval, interval, int_interval_mul },
{ int64, interval, interval, int_interval_mul },
{ float32, interval, interval, float_interval_mul },
{ float64, interval, interval, float_interval_mul },
{ decimal, interval, interval, float_interval_mul },
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/expr/src/vector_op/arithmetic_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ pub fn interval_date_add<T1, T2, T3>(
interval_timestamp_add::<T1, T2, T3>(l, date_to_timestamp(r)?)
}

#[inline(always)]
pub fn interval_time_add<T1, T2, T3>(
l: IntervalUnit,
r: NaiveTimeWrapper,
) -> Result<NaiveTimeWrapper> {
time_interval_add::<T2, T1, T3>(r, l)
}

#[inline(always)]
pub fn date_interval_add<T2, T1, T3>(
l: NaiveDateWrapper,
Expand Down
15 changes: 15 additions & 0 deletions src/tests/sqlsmith/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sqlsmith

SqlSmith is currently used as a testing tool to discover unexpected panics in RisingWave (It's not designed to generally test every SQL database, as it also tests some special SQL syntax used in RisingWave). It always generates the correct SQL based on the feature set supported so far. Therefore, if a test fails, it can only be due to two causes:

1. There's a bug in SQLSmith, as it generates invalid SQL.
2. There's a bug in RisingWave because it's unable to handle a correct query.

SqlSmith has two modes. The first one focuses on testing the frontend, i.e, testing the functionalities of SQL compilation (binding, transforming an AST into a logical plan, transforming a logical plan into a physical plan). This test will be run as a unit test (via `./risedev test`).

In the second mode, it will test the entire query handling end-to-end. We provide a CLI tool that represents a Postgres client. You can run this tool via:

```sh
cd risingwave
./target/debug/sqlsmith --testdata ./src/tests/sqlsmith/tests/testdata
```
6 changes: 5 additions & 1 deletion src/tests/sqlsmith/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use core::panic;
use std::time::Duration;

use clap::Parser as ClapParser;
Expand Down Expand Up @@ -99,6 +100,9 @@ async fn main() {
for _ in 0..100 {
let sql = sql_gen(&mut rng, tables.clone());
log::info!("Executing: {}", sql);
let _ = client.query(sql.as_str(), &[]).await.unwrap();
let _ = client
.query(sql.as_str(), &[])
.await
.unwrap_or_else(|e| panic!("Failed to execute query: {}\n{}", e, sql));
}
}

0 comments on commit 8d97480

Please sign in to comment.