Skip to content

Commit ffbd657

Browse files
committed
fix: drop TABLESAMPLE and MATCH_RECOGNIZE chains without recursion
The BigQuery parser wraps the relation in a new TableSample or MatchRecognize once per repeated clause after FROM, through a helper constructor, so FROM t followed by 20,000 TABLESAMPLE clauses built a chain whose derived drop aborted a 2 MiB debug thread, including on the syntax error path. Both now drop iteratively, and the 100,000-step drop test covers them; it aborts without this change.
1 parent 8dacf52 commit ffbd657

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎crates/sqlquack-syntax/src/expressions/tree/_helpers/drops.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use crate::expressions::operators::models::LikeOp;
1717
use crate::expressions::operators::models::MethodCall;
1818
use crate::expressions::operators::models::Subscript;
1919
use crate::expressions::operators::models::UnaryOp;
20+
use crate::expressions::queries::models::MatchRecognize;
2021
use crate::expressions::queries::models::PipeOperator;
22+
use crate::expressions::statements::models::TableSample;
2123
use crate::expressions::tree::models::Expression;
2224
use crate::expressions::typed_functions::models::AtTimeZone;
2325
use crate::expressions::typed_functions::models::BinaryFunc;
@@ -62,11 +64,13 @@ drop_iteratively!(
6264
JSONCast,
6365
JsonExtractFunc,
6466
LikeOp,
67+
MatchRecognize,
6568
MethodCall,
6669
ModelAttribute,
6770
Operator,
6871
PipeOperator,
6972
Subscript,
73+
TableSample,
7074
UnaryOp,
7175
Xor,
7276
);

‎crates/sqlquack-syntax/src/guard/tests/test_ast_guard.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::expressions::functions::models::Xor;
44
use crate::expressions::names::models::Identifier;
55
use crate::expressions::operators::models::ArraySlice;
66
use crate::expressions::operators::models::MethodCall;
7+
use crate::expressions::queries::models::MatchRecognize;
78
use crate::expressions::queries::models::PipeOperator;
9+
use crate::expressions::statements::models::TableSample;
810
use crate::expressions::tree::models::Expression;
911
use crate::expressions::typed_functions::models::AtTimeZone;
1012
use crate::expressions::typed_functions::models::BinaryFunc;
@@ -433,6 +435,44 @@ fn given_a_100_000_step_chain_of_a_node_parsers_build_in_a_loop_when_dropping_on
433435
},
434436
expected_depth: 100_000,
435437
},
438+
ChainStepTestCase {
439+
description: "TABLESAMPLE after TABLESAMPLE",
440+
step: |input| {
441+
Expression::TableSample(Box::new(TableSample {
442+
this: Some(Box::new(input)),
443+
sample: None,
444+
expressions: Vec::new(),
445+
method: None,
446+
bucket_numerator: None,
447+
bucket_denominator: None,
448+
bucket_field: None,
449+
percent: Some(Box::new(Expression::number(1))),
450+
rows: None,
451+
size: None,
452+
seed: None,
453+
}))
454+
},
455+
expected_depth: 100_000,
456+
},
457+
ChainStepTestCase {
458+
description: "MATCH_RECOGNIZE after MATCH_RECOGNIZE",
459+
step: |input| {
460+
Expression::MatchRecognize(Box::new(MatchRecognize {
461+
this: Some(Box::new(input)),
462+
partition_by: None,
463+
order_by: None,
464+
measures: None,
465+
rows: None,
466+
after: None,
467+
pattern: None,
468+
define: None,
469+
alias: None,
470+
alias_explicit_as: false,
471+
options: vec![Expression::number(1)],
472+
}))
473+
},
474+
expected_depth: 100_000,
475+
},
436476
ChainStepTestCase {
437477
description: "method calls",
438478
step: |input| {

0 commit comments

Comments
 (0)