Skip to content

Commit 115167a

Browse files
committed
Align DF55 compatibility tests with fork behavior
1 parent 549b436 commit 115167a

6 files changed

Lines changed: 90 additions & 29 deletions

File tree

datafusion/physical-expr/src/expressions/binary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4798,7 +4798,7 @@ mod tests {
47984798
Field::new("b", DataType::Decimal128(10, 2), true),
47994799
]));
48004800
let expect = Arc::new(create_decimal_array(
4801-
&[Some(1000000), None, Some(1008196), Some(1000000)],
4801+
&[Some(1000000), None, Some(1008197), Some(1000000)],
48024802
16,
48034803
4,
48044804
)) as ArrayRef;

datafusion/physical-plan/src/joins/hash_join/spill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! and per-partition write buffers; held until the spill join completes.
3434
//! - `HashJoinSpillPartition[p.k]`: per partition-pair; covers the loaded
3535
//! build batches plus the hash table built from them (moved into the
36-
//! pair's [`JoinLeftData`]); dropped when the pair finishes.
36+
//! pair's in-memory join state); dropped when the pair finishes.
3737
//!
3838
//! The scatter hash uses seeds distinct from both `RepartitionExec`'s
3939
//! `(0,0,0,0)` routing seeds and the join hash map's `HASH_JOIN_SEED`

datafusion/sql/src/parser.rs

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -925,23 +925,31 @@ impl<'a> DFParser<'a> {
925925
/// Parse a SQL `CREATE` statement handling `CREATE EXTERNAL TABLE`
926926
pub fn parse_create(&mut self) -> Result<Statement, DataFusionError> {
927927
// TODO: Change sql parser to take in `or_replace: bool` inside parse_create()
928-
if self
929-
.parser
930-
.parse_keywords(&[Keyword::OR, Keyword::REPLACE, Keyword::EXTERNAL])
928+
if self.external_is_followed_by_table(2)
929+
&& self.parser.parse_keywords(&[
930+
Keyword::OR,
931+
Keyword::REPLACE,
932+
Keyword::EXTERNAL,
933+
])
931934
{
932935
self.parse_create_external_table(false, true)
933-
} else if self.parser.parse_keywords(&[
934-
Keyword::OR,
935-
Keyword::REPLACE,
936-
Keyword::UNBOUNDED,
937-
Keyword::EXTERNAL,
938-
]) {
936+
} else if self.external_is_followed_by_table(3)
937+
&& self.parser.parse_keywords(&[
938+
Keyword::OR,
939+
Keyword::REPLACE,
940+
Keyword::UNBOUNDED,
941+
Keyword::EXTERNAL,
942+
])
943+
{
939944
self.parse_create_external_table(true, true)
940-
} else if self.parser.parse_keyword(Keyword::EXTERNAL) {
945+
} else if self.external_is_followed_by_table(0)
946+
&& self.parser.parse_keyword(Keyword::EXTERNAL)
947+
{
941948
self.parse_create_external_table(false, false)
942-
} else if self
943-
.parser
944-
.parse_keywords(&[Keyword::UNBOUNDED, Keyword::EXTERNAL])
949+
} else if self.external_is_followed_by_table(1)
950+
&& self
951+
.parser
952+
.parse_keywords(&[Keyword::UNBOUNDED, Keyword::EXTERNAL])
945953
{
946954
self.parse_create_external_table(true, false)
947955
} else {
@@ -953,6 +961,23 @@ impl<'a> DFParser<'a> {
953961
}
954962
}
955963

964+
fn external_is_followed_by_table(&self, external_offset: usize) -> bool {
965+
let next_keyword = match self.parser.peek_nth_token(external_offset + 1).token {
966+
Token::Word(word) => word.keyword,
967+
_ => return false,
968+
};
969+
if next_keyword == Keyword::TABLE {
970+
return true;
971+
}
972+
if !matches!(next_keyword, Keyword::TEMP | Keyword::TEMPORARY) {
973+
return false;
974+
}
975+
matches!(
976+
self.parser.peek_nth_token(external_offset + 2).token,
977+
Token::Word(word) if word.keyword == Keyword::TABLE
978+
)
979+
}
980+
956981
fn parse_partitions(&mut self) -> Result<Vec<String>, DataFusionError> {
957982
let mut partitions: Vec<String> = vec![];
958983
if !self.parser.consume_token(&Token::LParen)
@@ -1396,6 +1421,13 @@ mod tests {
13961421
});
13971422
expect_parse_ok(sql, expected)?;
13981423

1424+
let sql = "CREATE EXTERNAL TEMPORARY TABLE t STORED AS CSV LOCATION 'foo.csv'";
1425+
let expected = Statement::CreateExternalTable(CreateExternalTable {
1426+
temporary: true,
1427+
..make_create_external_table("foo.csv")
1428+
});
1429+
expect_parse_ok(sql, expected)?;
1430+
13991431
// positive case: literal comma remains part of a single path
14001432
let sql = "CREATE EXTERNAL TABLE t(c1 int) STORED AS CSV LOCATION 'foo,bar.csv'";
14011433
let expected = Statement::CreateExternalTable(CreateExternalTable {
@@ -1880,6 +1912,31 @@ mod tests {
18801912
Ok(())
18811913
}
18821914

1915+
#[test]
1916+
fn delegate_create_stage_to_snowflake_dialect() -> Result<(), DataFusionError> {
1917+
let sql =
1918+
"CREATE OR REPLACE STAGE stage URL='s3://data.csv' FILE_FORMAT=(TYPE=csv)";
1919+
let dialect = SnowflakeDialect;
1920+
let statements = DFParser::parse_sql_with_dialect(sql, &dialect)?;
1921+
1922+
assert_eq!(statements.len(), 1);
1923+
let Statement::Statement(statement) = &statements[0] else {
1924+
panic!("expected a sqlparser statement, got {:?}", statements[0]);
1925+
};
1926+
assert_eq!(statement.to_string(), sql);
1927+
Ok(())
1928+
}
1929+
1930+
#[test]
1931+
fn parse_standalone_begin_with_snowflake_dialect() -> Result<(), DataFusionError> {
1932+
let dialect = SnowflakeDialect;
1933+
let statements = DFParser::parse_sql_with_dialect("BEGIN", &dialect)?;
1934+
1935+
assert_eq!(statements.len(), 1);
1936+
assert!(matches!(statements[0], Statement::Statement(_)));
1937+
Ok(())
1938+
}
1939+
18831940
#[test]
18841941
fn explain_copy_to_table_to_table() -> Result<(), DataFusionError> {
18851942
let cases = vec![

datafusion/sqllogictest/test_files/decimal.slt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Decimal128(20, 6) 0.00055
121121
query TR
122122
select arrow_typeof(avg(c1)), avg(c1) from decimal_simple;
123123
----
124-
Decimal128(14, 10) 0.0000366666
124+
Decimal128(14, 10) 0.0000366667
125125

126126

127127
query TR
@@ -399,19 +399,19 @@ select c1/c5 from decimal_simple;
399399
----
400400
0.5
401401
0.641025641
402-
0.7142857142
402+
0.7142857143
403403
0.7352941176
404404
0.8
405405
0.8571428571
406-
0.909090909
407-
0.909090909
406+
0.9090909091
407+
0.9090909091
408408
0.9375
409409
0.9615384615
410410
1
411411
1
412412
1.0526315789
413-
1.5151515151
414-
2.7272727272
413+
1.5151515152
414+
2.7272727273
415415

416416

417417
query T
@@ -678,7 +678,7 @@ select * from decimal256_simple where c1 > c5;
678678
query TR
679679
select arrow_typeof(avg(c1)), avg(c1) from decimal256_simple;
680680
----
681-
Decimal256(54, 10) 0.0000366666
681+
Decimal256(54, 10) 0.0000366667
682682

683683
query TR
684684
select arrow_typeof(min(c1)), min(c1) from decimal256_simple where c4=false;

datafusion/sqllogictest/test_files/table_functions.slt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,16 @@ LIMIT 10;
620620
1
621621
1
622622

623-
# Test that unsupported function argument types are properly reported
624-
# rather than being silently dropped (which previously caused a misleading
625-
# "requires 1 to 3 arguments" error instead)
623+
# Named table-function arguments are preserved by the SQL planner.
626624

627-
statement error DataFusion error: Error during planning: Unsupported function argument type: start => 1
625+
query I
628626
SELECT * FROM generate_series(start => 1, stop => 5)
627+
----
628+
1
629+
2
630+
3
631+
4
632+
5
629633

630634
statement error DataFusion error: Error during planning: Unsupported function argument type: \*
631635
SELECT * FROM generate_series(*)

datafusion/sqllogictest/test_files/tpch/answers/q1.slt.part

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ order by
3939
l_returnflag,
4040
l_linestatus;
4141
----
42-
A F 3774200 5320753880.69 5054096266.6828 5256751331.449234 25.537587 36002.123829 0.050144 147790
42+
A F 3774200 5320753880.69 5054096266.6828 5256751331.449234 25.537587 36002.123829 0.050145 147790
4343
N F 95257 133737795.84 127132372.6512 132286291.229445 25.300664 35521.326916 0.049394 3765
44-
N O 7459297 10512270008.9 9986238338.3847 10385578376.585467 25.545537 36000.924688 0.050095 292000
45-
R F 3785523 5337950526.47 5071818532.942 5274405503.049367 25.525943 35994.029214 0.049989 148301
44+
N O 7459297 10512270008.9 9986238338.3847 10385578376.585467 25.545538 36000.924688 0.050096 292000
45+
R F 3785523 5337950526.47 5071818532.942 5274405503.049367 25.525944 35994.029214 0.049989 148301

0 commit comments

Comments
 (0)