Skip to content

Commit 0e7a98d

Browse files
committed
Revert to a85804b: Restore dictionary coercion in min_max.rs
1 parent 03b0289 commit 0e7a98d

File tree

6 files changed

+150
-278
lines changed

6 files changed

+150
-278
lines changed

datafusion-cli/tests/snapshots/cli_explain_environment_overrides@explain_plan_environment_overrides.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ exit_code: 0
1818
| logical_plan | [ |
1919
| | { |
2020
| | "Plan": { |
21-
| | "Node Type": "Projection", |
2221
| | "Expressions": [ |
2322
| | "Int64(123)" |
2423
| | ], |
24+
| | "Node Type": "Projection", |
25+
| | "Output": [ |
26+
| | "Int64(123)" |
27+
| | ], |
2528
| | "Plans": [ |
2629
| | { |
2730
| | "Node Type": "EmptyRelation", |
28-
| | "Plans": [], |
29-
| | "Output": [] |
31+
| | "Output": [], |
32+
| | "Plans": [] |
3033
| | } |
31-
| | ], |
32-
| | "Output": [ |
33-
| | "Int64(123)" |
3434
| | ] |
3535
| | } |
3636
| | } |

datafusion/core/tests/sql/aggregates/basic.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -448,35 +448,28 @@ async fn min_max_dictionary_uses_planned_dictionary_path() -> Result<()> {
448448
let ctx =
449449
SessionContext::new_with_config(SessionConfig::new().with_target_partitions(2));
450450

451-
fn dictionary_schema() -> Arc<Schema> {
452-
let dict_type =
453-
DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8));
454-
Arc::new(Schema::new(vec![Field::new("dict", dict_type, true)]))
455-
}
456-
457-
fn dictionary_record_batch(
458-
schema: Arc<Schema>,
459-
values: &[&str],
460-
keys: &[Option<i32>],
461-
) -> Result<RecordBatch> {
462-
Ok(RecordBatch::try_new(
463-
schema,
464-
vec![Arc::new(DictionaryArray::new(
465-
Int32Array::from(keys.to_vec()),
466-
Arc::new(StringArray::from(values.to_vec())),
467-
))],
468-
)?)
469-
}
470-
471-
let schema = dictionary_schema();
472-
473-
let batch1 = dictionary_record_batch(
451+
let dict_type =
452+
DataType::Dictionary(Box::new(DataType::Int32), Box::new(DataType::Utf8));
453+
let schema = Arc::new(Schema::new(vec![Field::new(
454+
"dict",
455+
dict_type.clone(),
456+
true,
457+
)]));
458+
459+
let batch1 = RecordBatch::try_new(
460+
schema.clone(),
461+
vec![Arc::new(DictionaryArray::new(
462+
Int32Array::from(vec![Some(1), Some(1), None]),
463+
Arc::new(StringArray::from(vec!["a", "z", "zz_unused"])),
464+
))],
465+
)?;
466+
let batch2 = RecordBatch::try_new(
474467
schema.clone(),
475-
&["a", "z", "zz_unused"],
476-
&[Some(1), Some(1), None],
468+
vec![Arc::new(DictionaryArray::new(
469+
Int32Array::from(vec![Some(0), Some(1)]),
470+
Arc::new(StringArray::from(vec!["a", "d"])),
471+
))],
477472
)?;
478-
let batch2 =
479-
dictionary_record_batch(schema.clone(), &["a", "d"], &[Some(0), Some(1)])?;
480473
let provider = MemTable::try_new(schema, vec![vec![batch1], vec![batch2]])?;
481474
ctx.register_table("t", Arc::new(provider))?;
482475

datafusion/expr/src/logical_plan/display.rs

Lines changed: 6 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -283,116 +283,6 @@ pub struct PgJsonVisitor<'a, 'b> {
283283
parent_ids: Vec<u32>,
284284
}
285285

286-
const NODE_TYPE_KEY: &str = "Node Type";
287-
const PLANS_KEY: &str = "Plans";
288-
const OUTPUT_KEY: &str = "Output";
289-
290-
fn ordered_keys(map: &serde_json::Map<String, serde_json::Value>) -> Vec<&str> {
291-
let mut keys = map.keys().map(String::as_str).collect::<Vec<_>>();
292-
keys.sort_unstable();
293-
294-
if !map.contains_key(NODE_TYPE_KEY) {
295-
return keys;
296-
}
297-
298-
let mut remaining_keys = Vec::with_capacity(keys.len().saturating_sub(1));
299-
let mut has_plans_key = false;
300-
let mut has_output_key = false;
301-
for key in keys {
302-
match key {
303-
NODE_TYPE_KEY => {}
304-
PLANS_KEY => has_plans_key = true,
305-
OUTPUT_KEY => has_output_key = true,
306-
_ => remaining_keys.push(key),
307-
}
308-
}
309-
310-
let mut ordered_keys = Vec::with_capacity(map.len());
311-
ordered_keys.push(NODE_TYPE_KEY);
312-
ordered_keys.extend(remaining_keys);
313-
if has_plans_key {
314-
ordered_keys.push(PLANS_KEY);
315-
}
316-
if has_output_key {
317-
ordered_keys.push(OUTPUT_KEY);
318-
}
319-
ordered_keys
320-
}
321-
322-
macro_rules! to_json_string {
323-
($value:expr) => {
324-
serde_json::to_string($value).map_err(|e| DataFusionError::External(Box::new(e)))
325-
};
326-
}
327-
328-
fn push_indent(buf: &mut String, indent: usize) {
329-
buf.push_str(&" ".repeat(indent * 2));
330-
}
331-
332-
fn write_delimited_entries(
333-
buf: &mut String,
334-
indent: usize,
335-
open: char,
336-
close: char,
337-
len: usize,
338-
mut write_entry: impl FnMut(usize, &mut String) -> datafusion_common::Result<()>,
339-
) -> datafusion_common::Result<()> {
340-
if len == 0 {
341-
buf.push(open);
342-
buf.push(close);
343-
return Ok(());
344-
}
345-
346-
buf.push(open);
347-
buf.push('\n');
348-
for idx in 0..len {
349-
push_indent(buf, indent + 1);
350-
write_entry(idx, buf)?;
351-
if idx + 1 != len {
352-
buf.push(',');
353-
}
354-
buf.push('\n');
355-
}
356-
push_indent(buf, indent);
357-
buf.push(close);
358-
Ok(())
359-
}
360-
361-
fn write_ordered_json(
362-
value: &serde_json::Value,
363-
buf: &mut String,
364-
indent: usize,
365-
) -> datafusion_common::Result<()> {
366-
match value {
367-
serde_json::Value::Null
368-
| serde_json::Value::Bool(_)
369-
| serde_json::Value::Number(_)
370-
| serde_json::Value::String(_) => {
371-
buf.push_str(&to_json_string!(value)?);
372-
}
373-
serde_json::Value::Array(values) => {
374-
write_delimited_entries(buf, indent, '[', ']', values.len(), |idx, buf| {
375-
write_ordered_json(&values[idx], buf, indent + 1)
376-
})?;
377-
}
378-
serde_json::Value::Object(map) => {
379-
let keys = ordered_keys(map);
380-
write_delimited_entries(buf, indent, '{', '}', keys.len(), |idx, buf| {
381-
let key = keys[idx];
382-
let value = map
383-
.get(key)
384-
.ok_or_else(|| internal_datafusion_err!("Missing key in object!"))?;
385-
386-
buf.push_str(&to_json_string!(key)?);
387-
buf.push_str(": ");
388-
write_ordered_json(value, buf, indent + 1)
389-
})?;
390-
}
391-
}
392-
393-
Ok(())
394-
}
395-
396286
impl<'a, 'b> PgJsonVisitor<'a, 'b> {
397287
pub fn new(f: &'a mut fmt::Formatter<'b>) -> Self {
398288
Self {
@@ -802,9 +692,12 @@ impl<'n> TreeNodeVisitor<'n> for PgJsonVisitor<'_, '_> {
802692
} else {
803693
// This is the root node
804694
let plan = serde_json::json!([{"Plan": current_node}]);
805-
let mut plan_str = String::new();
806-
write_ordered_json(&plan, &mut plan_str, 0)?;
807-
write!(self.f, "{plan_str}")?;
695+
write!(
696+
self.f,
697+
"{}",
698+
serde_json::to_string_pretty(&plan)
699+
.map_err(|e| DataFusionError::External(Box::new(e)))?
700+
)?;
808701
}
809702

810703
Ok(TreeNodeRecursion::Continue)

datafusion/expr/src/logical_plan/plan.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,30 +4593,6 @@ mod tests {
45934593
Ok(())
45944594
}
45954595

4596-
#[test]
4597-
fn test_display_pg_json_values_field_order() -> Result<()> {
4598-
let plan = LogicalPlanBuilder::values(vec![vec![lit(1_i64)]])?.build()?;
4599-
4600-
let output = plan.display_pg_json().to_string();
4601-
let node_type_pos = output
4602-
.find("\"Node Type\": \"Values\"")
4603-
.expect("expected Node Type key in pgjson output");
4604-
let values_pos = output
4605-
.find("\"Values\": \"(Int64(1))\"")
4606-
.expect("expected Values key in pgjson output");
4607-
let plans_pos = output
4608-
.find("\"Plans\": []")
4609-
.expect("expected Plans key in pgjson output");
4610-
let output_pos = output
4611-
.find("\"Output\": [")
4612-
.expect("expected Output key in pgjson output");
4613-
4614-
assert!(node_type_pos < values_pos);
4615-
assert!(values_pos < plans_pos);
4616-
assert!(plans_pos < output_pos);
4617-
Ok(())
4618-
}
4619-
46204596
/// Tests for the Visitor trait and walking logical plan nodes
46214597
#[derive(Debug, Default)]
46224598
struct OkVisitor {

0 commit comments

Comments
 (0)