rypipe_core/engine/
locate.rs1use std::sync::Arc;
2
3use arrow::datatypes::Schema;
4use arrow::record_batch::RecordBatch;
5use rustc_hash::FxHashSet;
6
7use crate::decoder::ColumnarSink;
8use crate::plan::ExecutionPlan;
9use crate::value::Value;
10use crate::Result;
11
12pub struct LocateOnly {
16 pub row_count: usize,
17 pub field_count: usize,
18 pub distinct_fields: FxHashSet<String>,
19 plan: ExecutionPlan,
20}
21
22impl LocateOnly {
23 pub fn new(plan: ExecutionPlan) -> Self {
24 Self {
25 row_count: 0,
26 field_count: 0,
27 distinct_fields: FxHashSet::default(),
28 plan,
29 }
30 }
31
32 pub fn total_fields(&self) -> usize {
34 self.field_count
35 }
36
37 pub fn num_distinct_fields(&self) -> usize {
39 self.distinct_fields.len()
40 }
41}
42
43impl ColumnarSink for LocateOnly {
44 #[inline]
45 fn begin_row(&mut self) {}
46
47 #[inline]
48 fn put_field(&mut self, name: &str, _value: Value<'_>) {
49 self.field_count += 1;
50 if let Some(resolved) = self.plan.resolve_field(name) {
51 self.distinct_fields.insert(resolved.to_owned());
52 }
53 }
54
55 #[inline]
56 fn end_row(&mut self) {
57 self.row_count += 1;
58 }
59
60 #[inline]
61 fn wants(&self, _name: &str) -> bool {
62 true
63 }
64
65 #[inline]
66 fn needs_value(&self) -> bool {
67 false
68 }
69
70 #[inline]
71 fn resolve<'a>(&'a self, name: &'a str) -> Option<&'a str> {
72 self.plan.resolve_field(name)
73 }
74
75 fn finish(&mut self) -> Result<RecordBatch> {
76 let schema = Arc::new(Schema::empty());
77 Ok(RecordBatch::new_empty(schema))
78 }
79}