Skip to content

Commit 996d4fd

Browse files
committed
Fix compiler errors in tests
1 parent 940524c commit 996d4fd

40 files changed

Lines changed: 510 additions & 324 deletions

File tree

datafusion/catalog-listing/src/helpers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ mod tests {
547547
use datafusion_expr::{
548548
case, col, lit, AggregateUDF, Expr, LogicalPlan, ScalarUDF, WindowUDF,
549549
};
550+
use datafusion_expr::registry::MemoryExtensionTypeRegistry;
550551
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
551552
use datafusion_physical_plan::ExecutionPlan;
552553

@@ -1060,6 +1061,10 @@ mod tests {
10601061
unimplemented!()
10611062
}
10621063

1064+
fn extension_types(&self) -> &MemoryExtensionTypeRegistry {
1065+
unimplemented!()
1066+
}
1067+
10631068
fn runtime_env(&self) -> &Arc<RuntimeEnv> {
10641069
unimplemented!()
10651070
}

datafusion/common/src/sort.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
118
use crate::error::{_exec_err, _internal_err};
219
use crate::types::SortOrdering;
320
use crate::Result;
421
use arrow::array::{ArrayRef, DynComparator, UInt32Array};
522
use arrow::compute::{partial_sort, SortColumn, SortOptions};
6-
use std::cmp::Ordering;
723
use arrow::datatypes::DataType;
824
use arrow::row::{RowConverter, SortField};
25+
use std::cmp::Ordering;
926

1027
/// TODO
1128
#[derive(Clone, Debug, Default, Hash, PartialEq, Eq)]
@@ -175,7 +192,8 @@ pub fn lexsort_to_indices(
175192
len = limit.min(len);
176193
}
177194

178-
let compare_items = columns.iter()
195+
let compare_items = columns
196+
.iter()
179197
.map(|c| c.dyn_compartor())
180198
.collect::<Result<Vec<_>>>()?;
181199

@@ -232,7 +250,6 @@ pub(crate) fn lexsort_to_indices_multi_columns(
232250
Ok(indices)
233251
}
234252

235-
236253
/// we can only do this if the T is primitive
237254
#[inline]
238255
fn sort_unstable_by<T, F>(array: &mut [T], limit: usize, cmp: F)

datafusion/core/src/datasource/listing/table.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,6 @@ mod tests {
11991199
test::{columns, object_store::register_test_store},
12001200
};
12011201

1202-
use arrow::compute::SortOptions;
12031202
use arrow::record_batch::RecordBatch;
12041203
use datafusion_common::stats::Precision;
12051204
use datafusion_common::{assert_contains, ScalarValue};
@@ -1211,6 +1210,8 @@ mod tests {
12111210
use crate::test::object_store::{ensure_head_concurrency, make_test_store_and_state};
12121211
use tempfile::TempDir;
12131212
use url::Url;
1213+
use datafusion_common::sort::AdvSortOptions;
1214+
use datafusion_common::types::SortOrdering;
12141215

12151216
#[tokio::test]
12161217
async fn read_single_file() -> Result<()> {
@@ -1319,7 +1320,8 @@ mod tests {
13191320
Ok(vec![LexOrdering::new(
13201321
vec![PhysicalSortExpr {
13211322
expr: physical_col("string_col", &schema).unwrap(),
1322-
options: SortOptions {
1323+
options: AdvSortOptions {
1324+
ordering: SortOrdering::default(),
13231325
descending: false,
13241326
nulls_first: false,
13251327
},

datafusion/core/src/execution/session_state.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,10 @@ impl FunctionRegistry for SessionState {
18641864
}
18651865

18661866
impl ExtensionTypeRegistry for SessionState {
1867-
fn get_extension_type(&self, name: &str) -> datafusion_common::Result<LogicalTypeRef> {
1867+
fn get_extension_type(
1868+
&self,
1869+
name: &str,
1870+
) -> datafusion_common::Result<LogicalTypeRef> {
18681871
self.extension_types.get_extension_type(name)
18691872
}
18701873

datafusion/core/tests/dataframe/mod.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ mod dataframe_functions;
2020
mod describe;
2121
mod test_types;
2222

23-
use arrow::array::{as_union_array, record_batch, Array, ArrayRef, AsArray, BooleanArray, DictionaryArray, FixedSizeListArray, FixedSizeListBuilder, Float32Array, Float64Array, Int32Array, Int32Builder, Int8Array, LargeListArray, ListArray, ListBuilder, RecordBatch, StringArray, StringBuilder, StructBuilder, UInt32Array, UInt32Builder, UnionArray, UnionBuilder};
23+
use arrow::array::{
24+
as_union_array, record_batch, Array, ArrayRef, AsArray, BooleanArray,
25+
DictionaryArray, FixedSizeListArray, FixedSizeListBuilder, Float32Array,
26+
Float64Array, Int32Array, Int32Builder, Int8Array, LargeListArray, ListArray,
27+
ListBuilder, RecordBatch, StringArray, StringBuilder, StructBuilder, UInt32Array,
28+
UInt32Builder, UnionArray, UnionBuilder,
29+
};
2430
use arrow::buffer::ScalarBuffer;
2531
use arrow::datatypes::{
2632
DataType, Field, Float32Type, Float64Type, Int32Type, Int64Type, Schema, SchemaRef,
@@ -3111,7 +3117,8 @@ async fn sort_on_union_with_logical_type() -> Result<()> {
31113117
)?),
31123118
)?;
31133119

3114-
let record_batch = ctx.table("test_table")
3120+
let record_batch = ctx
3121+
.table("test_table")
31153122
.await?
31163123
.sort_by(vec![col("my_union")])?
31173124
.execute_stream()
@@ -3122,8 +3129,14 @@ async fn sort_on_union_with_logical_type() -> Result<()> {
31223129

31233130
let result = as_union_array(record_batch.column_by_name("my_union").unwrap());
31243131
assert_eq!(result.type_ids(), &[0, 0, 1, 1]);
3125-
assert_eq!(result.child(0).as_primitive::<Int64Type>().values(), &[-1, 1]);
3126-
assert_eq!(result.child(1).as_primitive::<Float64Type>().values(), &[3.0, 6.0]);
3132+
assert_eq!(
3133+
result.child(0).as_primitive::<Int64Type>().values(),
3134+
&[-1, 1]
3135+
);
3136+
assert_eq!(
3137+
result.child(1).as_primitive::<Float64Type>().values(),
3138+
&[3.0, 6.0]
3139+
);
31273140

31283141
Ok(())
31293142
}

datafusion/core/tests/fuzz_cases/aggregate_fuzz.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::fuzz_cases::aggregation_fuzzer::{
2323
};
2424

2525
use arrow::array::{types::Int64Type, Array, ArrayRef, AsArray, Int64Array, RecordBatch};
26-
use arrow::compute::{concat_batches, SortOptions};
26+
use arrow::compute::{concat_batches};
2727
use arrow::datatypes::{
2828
DataType, IntervalUnit, TimeUnit, DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE,
2929
DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE,
@@ -51,6 +51,7 @@ use test_utils::{add_empty_batches, StringBatchGenerator};
5151
use rand::rngs::StdRng;
5252
use rand::{thread_rng, Rng, SeedableRng};
5353
use tokio::task::JoinSet;
54+
use datafusion_common::sort::AdvSortOptions;
5455

5556
// ========================================================================
5657
// The new aggregation fuzz tests based on [`AggregationFuzzer`]
@@ -315,7 +316,7 @@ async fn run_aggregate_test(input1: Vec<RecordBatch>, group_by_columns: Vec<&str
315316
for ordering_col in ["a", "b", "c"] {
316317
sort_keys.push(PhysicalSortExpr {
317318
expr: col(ordering_col, &schema).unwrap(),
318-
options: SortOptions::default(),
319+
options: AdvSortOptions::default(),
319320
})
320321
}
321322

datafusion/core/tests/fuzz_cases/equivalence/ordering.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ fn test_ordering_satisfy_with_equivalence_random() -> Result<()> {
3737
const N_RANDOM_SCHEMA: usize = 5;
3838
const N_ELEMENTS: usize = 125;
3939
const N_DISTINCT: usize = 5;
40-
const SORT_OPTIONS: SortOptions = SortOptions {
40+
const SORT_OPTIONS: AdvSortOptions = AdvSortOptions {
41+
ordering: SortOrdering::Default,
4142
descending: false,
4243
nulls_first: false,
4344
};
@@ -63,7 +64,7 @@ fn test_ordering_satisfy_with_equivalence_random() -> Result<()> {
6364
.into_iter()
6465
.map(|expr| PhysicalSortExpr {
6566
expr: Arc::clone(expr),
66-
options: SORT_OPTIONS,
67+
options: SORT_OPTIONS.clone(),
6768
})
6869
.collect::<LexOrdering>();
6970
let expected = is_table_same_after_sort(
@@ -94,7 +95,8 @@ fn test_ordering_satisfy_with_equivalence_complex_random() -> Result<()> {
9495
const N_RANDOM_SCHEMA: usize = 100;
9596
const N_ELEMENTS: usize = 125;
9697
const N_DISTINCT: usize = 5;
97-
const SORT_OPTIONS: SortOptions = SortOptions {
98+
const SORT_OPTIONS: AdvSortOptions = AdvSortOptions {
99+
ordering: SortOrdering::Default,
98100
descending: false,
99101
nulls_first: false,
100102
};
@@ -135,7 +137,7 @@ fn test_ordering_satisfy_with_equivalence_complex_random() -> Result<()> {
135137
.into_iter()
136138
.map(|expr| PhysicalSortExpr {
137139
expr: Arc::clone(expr),
138-
options: SORT_OPTIONS,
140+
options: SORT_OPTIONS.clone(),
139141
})
140142
.collect::<LexOrdering>();
141143
let expected = is_table_same_after_sort(

datafusion/core/tests/fuzz_cases/equivalence/projection.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use crate::fuzz_cases::equivalence::utils::{
1919
apply_projection, create_random_schema, generate_table_for_eq_properties,
2020
is_table_same_after_sort, TestScalarUDF,
2121
};
22-
use arrow::compute::SortOptions;
2322
use datafusion_common::Result;
2423
use datafusion_expr::{Operator, ScalarUDF};
2524
use datafusion_physical_expr::equivalence::ProjectionMapping;
@@ -29,6 +28,8 @@ use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
2928
use datafusion_physical_expr_common::sort_expr::{LexOrdering, PhysicalSortExpr};
3029
use itertools::Itertools;
3130
use std::sync::Arc;
31+
use datafusion_common::sort::AdvSortOptions;
32+
use datafusion_common::types::SortOrdering;
3233

3334
#[test]
3435
fn project_orderings_random() -> Result<()> {
@@ -108,7 +109,8 @@ fn ordering_satisfy_after_projection_random() -> Result<()> {
108109
const N_RANDOM_SCHEMA: usize = 20;
109110
const N_ELEMENTS: usize = 125;
110111
const N_DISTINCT: usize = 5;
111-
const SORT_OPTIONS: SortOptions = SortOptions {
112+
const SORT_OPTIONS: AdvSortOptions = AdvSortOptions {
113+
ordering: SortOrdering::Default,
112114
descending: false,
113115
nulls_first: false,
114116
};

datafusion/core/tests/fuzz_cases/equivalence/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn test_find_longest_permutation_random() -> Result<()> {
7575
.zip(ordering.iter())
7676
.map(|(&idx, sort_expr)| PhysicalSortExpr {
7777
expr: Arc::clone(&exprs[idx]),
78-
options: sort_expr.options,
78+
options: sort_expr.options.clone(),
7979
})
8080
.collect::<LexOrdering>();
8181
assert_eq!(

datafusion/core/tests/fuzz_cases/equivalence/utils.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::cmp::Ordering;
2323
use std::sync::Arc;
2424

2525
use arrow::array::{ArrayRef, Float32Array, Float64Array, RecordBatch, UInt32Array};
26-
use arrow::compute::SortOptions;
26+
use arrow::compute::{SortColumn, SortOptions};
2727
use arrow::compute::{lexsort_to_indices, take_record_batch};
2828
use arrow::datatypes::{DataType, Field, Schema, SchemaRef};
2929
use datafusion_common::utils::{compare_rows, get_row_at_idx};
@@ -38,6 +38,8 @@ use datafusion_physical_expr_common::sort_expr::LexOrdering;
3838

3939
use itertools::izip;
4040
use rand::prelude::*;
41+
use datafusion_common::sort::AdvSortOptions;
42+
use datafusion_common::types::SortOrdering;
4143

4244
pub fn output_schema(
4345
mapping: &ProjectionMapping,
@@ -108,7 +110,8 @@ pub fn create_random_schema(seed: u64) -> Result<(SchemaRef, EquivalenceProperti
108110
let mut rng = StdRng::seed_from_u64(seed);
109111
let mut remaining_exprs = col_exprs[0..4].to_vec(); // only a, b, c, d are sorted
110112

111-
let options_asc = SortOptions {
113+
let options_asc = AdvSortOptions {
114+
ordering: SortOrdering::Default,
112115
descending: false,
113116
nulls_first: false,
114117
};
@@ -121,7 +124,7 @@ pub fn create_random_schema(seed: u64) -> Result<(SchemaRef, EquivalenceProperti
121124
.drain(0..n_sort_expr)
122125
.map(|expr| PhysicalSortExpr {
123126
expr: Arc::clone(expr),
124-
options: options_asc,
127+
options: options_asc.clone(),
125128
})
126129
.collect();
127130

@@ -267,7 +270,7 @@ pub fn is_table_same_after_sort(
267270
let values = expr_result.into_array(new_batch.num_rows())?;
268271
Ok(SortColumn {
269272
values,
270-
options: Some(order_expr.options),
273+
options: Some(order_expr.options.to_arrow().unwrap()),
271274
})
272275
})
273276
.collect::<Result<Vec<_>>>()?;
@@ -390,15 +393,15 @@ pub fn generate_table_for_eq_properties(
390393
.map(
391394
|PhysicalSortExpr {
392395
expr,
393-
options: options,
396+
options,
394397
}| {
395398
let col = expr.as_any().downcast_ref::<Column>().unwrap();
396399
let (idx, _field) = schema.column_with_name(col.name()).unwrap();
397400
let arr = generate_random_array(n_elem, n_distinct);
398401
(
399402
SortColumn {
400403
values: arr,
401-
options: Some(*options),
404+
options: Some(options.to_arrow().unwrap()),
402405
},
403406
idx,
404407
)
@@ -507,7 +510,7 @@ pub fn convert_to_sort_exprs(
507510
.iter()
508511
.map(|(expr, options)| PhysicalSortExpr {
509512
expr: Arc::clone(*expr),
510-
options: *options,
513+
options: AdvSortOptions::with_default_ordering(*options),
511514
})
512515
.collect()
513516
}
@@ -585,7 +588,7 @@ impl ScalarUDFImpl for TestScalarUDF {
585588
}
586589

587590
fn output_ordering(&self, input: &[ExprProperties]) -> Result<SortProperties> {
588-
Ok(input[0].sort_properties)
591+
Ok(input[0].sort_properties.clone())
589592
}
590593

591594
fn invoke_with_args(&self, args: ScalarFunctionArgs) -> Result<ColumnarValue> {

0 commit comments

Comments
 (0)