Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <pingsutw@apache.org>
  • Loading branch information
pingsutw committed Jun 12, 2024
1 parent 9a1eae8 commit e134719
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions datafusion/core/tests/user_defined/user_defined_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ use datafusion::{
};

use async_trait::async_trait;
use datafusion_common::config::ConfigOptions;
use datafusion_optimizer::analyzer::inline_table_scan::InlineTableScan;
use datafusion_optimizer::AnalyzerRule;
use futures::{Stream, StreamExt};

/// Execute the specified sql and return the resulting record batches
Expand Down Expand Up @@ -246,10 +249,12 @@ async fn topk_plan() -> Result<()> {
fn make_topk_context() -> SessionContext {
let config = SessionConfig::new().with_target_partitions(48);
let runtime = Arc::new(RuntimeEnv::default());
let state = SessionState::new_with_config_rt(config, runtime)
let mut state = SessionState::new_with_config_rt(config, runtime)
.with_query_planner(Arc::new(TopKQueryPlanner {}))
.add_optimizer_rule(Arc::new(TopKOptimizerRule {}));
SessionContext::new_with_state(state)
state.add_analyzer_rule(Arc::new(MyAnalyzerRule {}));
let ctx = SessionContext::new_with_state(state);
ctx.add_analyzer_rule(Arc::new(MyAnalyzerRule {}))
}

// ------ The implementation of the TopK code follows -----
Expand Down Expand Up @@ -619,3 +624,15 @@ impl RecordBatchStream for TopKReader {
self.input.schema()
}
}

struct MyAnalyzerRule {}

impl AnalyzerRule for MyAnalyzerRule {
fn analyze(&self, plan: LogicalPlan, _config: &ConfigOptions) -> Result<LogicalPlan> {
Self::analyze_plan(plan)
}

fn name(&self) -> &str {
"my_analyzer_rule"
}
}

0 comments on commit e134719

Please sign in to comment.