Skip to content

Commit 2a6c198

Browse files
authored
feat(sqlsmith): fuzz query support sqllogic test cases (#17216)
1 parent 701b445 commit 2a6c198

File tree

15 files changed

+830
-325
lines changed

15 files changed

+830
-325
lines changed

src/query/expression/src/property.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ impl Domain {
252252
min: this.min.min(other.min),
253253
max: this.max.max(other.max),
254254
}),
255+
(Domain::Interval(this), Domain::Interval(other)) => Domain::Interval(SimpleDomain {
256+
min: this.min.min(other.min),
257+
max: this.max.max(other.max),
258+
}),
255259
(
256260
Domain::Nullable(NullableDomain {
257261
has_null: true,
@@ -389,6 +393,9 @@ impl Domain {
389393
Some(Scalar::Timestamp(*min))
390394
}
391395
Domain::Date(SimpleDomain { min, max }) if min == max => Some(Scalar::Date(*min)),
396+
Domain::Interval(SimpleDomain { min, max }) if min == max => {
397+
Some(Scalar::Interval(*min))
398+
}
392399
Domain::Nullable(NullableDomain {
393400
has_null: true,
394401
value: None,

src/query/expression/src/utils/column_from.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl_from_data! { VariantType }
7171
impl_from_data! { BitmapType }
7272
impl_from_data! { GeometryType }
7373
impl_from_data! { GeographyType }
74+
impl_from_data! { IntervalType }
7475

7576
impl<'a> FromData<&'a [u8]> for BinaryType {
7677
fn from_data(d: Vec<&'a [u8]>) -> Column {

src/query/expression/src/values.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,17 @@ impl Column {
13251325
.map(|_| rng.gen_range(DATE_MIN..=DATE_MAX))
13261326
.collect::<Vec<i32>>(),
13271327
),
1328-
DataType::Interval => unimplemented!(),
1328+
DataType::Interval => IntervalType::from_data(
1329+
(0..len)
1330+
.map(|_| {
1331+
months_days_micros::new(
1332+
rng.gen::<i32>(),
1333+
rng.gen::<i32>(),
1334+
rng.gen::<i64>(),
1335+
)
1336+
})
1337+
.collect::<Vec<months_days_micros>>(),
1338+
),
13291339
DataType::Nullable(ty) => NullableColumn::new_column(
13301340
Column::random(ty, len, options),
13311341
Bitmap::from((0..len).map(|_| rng.gen_bool(0.5)).collect::<Vec<bool>>()),

src/query/sql/src/planner/binder/bind_query/bind_select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl Binder {
241241

242242
s_expr = self.bind_projection(&mut from_context, &projections, &scalar_items, s_expr)?;
243243

244-
if !order_by.is_empty() {
244+
if !order_items.items.is_empty() {
245245
s_expr = self.bind_order_by(&from_context, order_items, &select_list, s_expr)?;
246246
}
247247

src/query/sql/src/planner/semantic/type_check.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,12 @@ impl<'a> TypeChecker<'a> {
26222622
)
26232623
.set_span(span));
26242624
}
2625+
ExprContext::QualifyClause => {
2626+
return Err(ErrorCode::SemanticError(
2627+
"set-returning functions cannot be used in QUALIFY clause".to_string(),
2628+
)
2629+
.set_span(span));
2630+
}
26252631
_ => {}
26262632
}
26272633

src/tests/sqlsmith/src/bin/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ pub struct Args {
4848
/// The number of timeout seconds of one query.
4949
#[clap(long, default_value = "5")]
5050
timeout: u64,
51+
52+
/// The fuzz query test file path.
53+
#[clap(long, default_value = "")]
54+
fuzz_path: String,
5155
}
5256

5357
#[tokio::main(flavor = "multi_thread", worker_threads = 5)]
@@ -70,7 +74,12 @@ async fn main() -> Result<()> {
7074
args.timeout,
7175
)
7276
.await?;
73-
runner.run().await?;
77+
78+
if !args.fuzz_path.is_empty() {
79+
runner.run_fuzz(&args.fuzz_path).await?;
80+
} else {
81+
runner.run().await?;
82+
}
7483

7584
Ok(())
7685
}

0 commit comments

Comments
 (0)