MCPcopy Create free account
hub / github.com/apache/datafusion / to_json_value

Method to_json_value

datafusion/expr/src/logical_plan/display.rs:303–638  ·  view source on GitHub ↗

Converts a logical plan node to a json object.

(node: &LogicalPlan)

Source from the content-addressed store, hash-verified

301
302 /// Converts a logical plan node to a json object.
303 fn to_json_value(node: &LogicalPlan) -> serde_json::Value {
304 match node {
305 LogicalPlan::EmptyRelation(_) => {
306 json!({
307 "Node Type": "EmptyRelation",
308 })
309 }
310 LogicalPlan::RecursiveQuery(RecursiveQuery { is_distinct, .. }) => {
311 json!({
312 "Node Type": "RecursiveQuery",
313 "Is Distinct": is_distinct,
314 })
315 }
316 LogicalPlan::Values(Values { values, .. }) => {
317 let str_values = values
318 .iter()
319 // limit to only 5 values to avoid horrible display
320 .take(5)
321 .map(|row| {
322 let item = row
323 .iter()
324 .map(|expr| expr.to_string())
325 .collect::<Vec<_>>()
326 .join(", ");
327 format!("({item})")
328 })
329 .collect::<Vec<_>>()
330 .join(", ");
331
332 let eclipse = if values.len() > 5 { "..." } else { "" };
333
334 let values_str = format!("{str_values}{eclipse}");
335 json!({
336 "Node Type": "Values",
337 "Values": values_str
338 })
339 }
340 LogicalPlan::TableScan(TableScan {
341 source,
342 table_name,
343 filters,
344 fetch,
345 ..
346 }) => {
347 let mut object = json!({
348 "Node Type": "TableScan",
349 "Relation Name": table_name.table(),
350 });
351
352 if let Some(s) = table_name.schema() {
353 object["Schema"] = serde_json::Value::String(s.to_string());
354 }
355
356 if let Some(c) = table_name.catalog() {
357 object["Catalog"] = serde_json::Value::String(c.to_string());
358 }
359
360 if !filters.is_empty() {

Callers

nothing calls this directly

Calls 15

collectMethod · 0.80
columnsMethod · 0.80
joinMethod · 0.45
mapMethod · 0.45
takeMethod · 0.45
iterMethod · 0.45
to_stringMethod · 0.45
lenMethod · 0.45
schemaMethod · 0.45
catalogMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected