datafusion_dft/tui/ui/tabs/
context.rs

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
18use ratatui::{
19    buffer::Buffer,
20    layout::{Constraint, Direction, Layout, Rect},
21    widgets::{Block, Borders, List, Widget},
22};
23
24use crate::tui::App;
25
26pub fn render_physical_optimizers(area: Rect, buf: &mut Buffer, app: &App) {
27    let block = Block::default()
28        .borders(Borders::ALL)
29        .title(" Physical Optimizers ");
30    let context = app.execution.session_ctx();
31    let state_lock = context.state_ref();
32    let state = state_lock.read();
33    let physical_optimizer_names = state.physical_optimizers().iter().map(|opt| opt.name());
34
35    let list = List::new(physical_optimizer_names).block(block);
36    list.render(area, buf)
37}
38
39pub fn render_config(area: Rect, buf: &mut Buffer, app: &App) {
40    let block = Block::default().borders(Borders::ALL).title(" Config ");
41    let context = app.execution.session_ctx();
42    let state_lock = context.state_ref();
43    let state = state_lock.read();
44    let config = state.config();
45    let bloom_filter_pruning = config.parquet_bloom_filter_pruning();
46    let parquet_row_group_pruning = config.parquet_pruning();
47
48    let config_options = vec![
49        format!("Bloom filter pruning: {}", bloom_filter_pruning),
50        format!("Parquet row group pruning: {}", parquet_row_group_pruning),
51    ];
52
53    let list = List::new(config_options).block(block);
54    list.render(area, buf)
55}
56
57pub fn render_context(area: Rect, buf: &mut Buffer, app: &App) {
58    let constraints = vec![Constraint::Percentage(50), Constraint::Percentage(50)];
59    let [physical_optimizers_area, config_area] =
60        Layout::new(Direction::Vertical, constraints).areas(area);
61    render_physical_optimizers(physical_optimizers_area, buf, app);
62    render_config(config_area, buf, app);
63}