1use std::any::Any;
18use std::collections::HashMap;
19use std::fmt::{Debug, Display};
20use std::sync::{Arc, Mutex};
21
22use api::greptime_proto::v1::meta::{GrantedRegion as PbGrantedRegion, RegionRole as PbRegionRole};
23use api::region::RegionResponse;
24use async_trait::async_trait;
25use common_error::ext::BoxedError;
26use common_recordbatch::{EmptyRecordBatchStream, MemoryPermit, SendableRecordBatchStream};
27use common_time::Timestamp;
28use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet;
29use datafusion_physical_plan::{DisplayAs, DisplayFormatType};
30use datatypes::schema::SchemaRef;
31use futures::future::join_all;
32use serde::{Deserialize, Serialize};
33use tokio::sync::Semaphore;
34
35use crate::logstore::entry;
36use crate::metadata::RegionMetadataRef;
37use crate::region_request::{
38 BatchRegionDdlRequest, RegionCatchupRequest, RegionOpenRequest, RegionRequest,
39};
40use crate::storage::{FileId, RegionId, ScanRequest, SequenceNumber};
41
42#[derive(Debug, PartialEq, Eq, Clone, Copy)]
44pub enum SettableRegionRoleState {
45 Follower,
46 DowngradingLeader,
47 Leader,
49 StagingLeader,
51}
52
53impl Display for SettableRegionRoleState {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 match self {
56 SettableRegionRoleState::Follower => write!(f, "Follower"),
57 SettableRegionRoleState::DowngradingLeader => write!(f, "Leader(Downgrading)"),
58 SettableRegionRoleState::Leader => write!(f, "Leader"),
59 SettableRegionRoleState::StagingLeader => write!(f, "Leader(Staging)"),
60 }
61 }
62}
63
64impl From<SettableRegionRoleState> for RegionRole {
65 fn from(value: SettableRegionRoleState) -> Self {
66 match value {
67 SettableRegionRoleState::Follower => RegionRole::Follower,
68 SettableRegionRoleState::DowngradingLeader => RegionRole::DowngradingLeader,
69 SettableRegionRoleState::Leader => RegionRole::Leader,
70 SettableRegionRoleState::StagingLeader => RegionRole::Leader, }
72 }
73}
74
75#[derive(Debug, PartialEq, Eq)]
77pub struct SetRegionRoleStateRequest {
78 region_id: RegionId,
79 region_role_state: SettableRegionRoleState,
80}
81
82#[derive(Debug, PartialEq, Eq)]
84pub enum SetRegionRoleStateSuccess {
85 File,
86 Mito {
87 last_entry_id: entry::Id,
88 },
89 Metric {
90 last_entry_id: entry::Id,
91 metadata_last_entry_id: entry::Id,
92 },
93}
94
95impl SetRegionRoleStateSuccess {
96 pub fn file() -> Self {
98 Self::File
99 }
100
101 pub fn mito(last_entry_id: entry::Id) -> Self {
103 SetRegionRoleStateSuccess::Mito { last_entry_id }
104 }
105
106 pub fn metric(last_entry_id: entry::Id, metadata_last_entry_id: entry::Id) -> Self {
108 SetRegionRoleStateSuccess::Metric {
109 last_entry_id,
110 metadata_last_entry_id,
111 }
112 }
113}
114
115impl SetRegionRoleStateSuccess {
116 pub fn last_entry_id(&self) -> Option<entry::Id> {
118 match self {
119 SetRegionRoleStateSuccess::File => None,
120 SetRegionRoleStateSuccess::Mito { last_entry_id } => Some(*last_entry_id),
121 SetRegionRoleStateSuccess::Metric { last_entry_id, .. } => Some(*last_entry_id),
122 }
123 }
124
125 pub fn metadata_last_entry_id(&self) -> Option<entry::Id> {
127 match self {
128 SetRegionRoleStateSuccess::File => None,
129 SetRegionRoleStateSuccess::Mito { .. } => None,
130 SetRegionRoleStateSuccess::Metric {
131 metadata_last_entry_id,
132 ..
133 } => Some(*metadata_last_entry_id),
134 }
135 }
136}
137
138#[derive(Debug)]
140pub enum SetRegionRoleStateResponse {
141 Success(SetRegionRoleStateSuccess),
142 NotFound,
143 InvalidTransition(BoxedError),
144}
145
146impl SetRegionRoleStateResponse {
147 pub fn success(success: SetRegionRoleStateSuccess) -> Self {
149 Self::Success(success)
150 }
151
152 pub fn invalid_transition(error: BoxedError) -> Self {
154 Self::InvalidTransition(error)
155 }
156
157 pub fn is_not_found(&self) -> bool {
159 matches!(self, SetRegionRoleStateResponse::NotFound)
160 }
161
162 pub fn is_invalid_transition(&self) -> bool {
164 matches!(self, SetRegionRoleStateResponse::InvalidTransition(_))
165 }
166}
167
168#[derive(Debug, Clone, PartialEq, Eq)]
169pub struct GrantedRegion {
170 pub region_id: RegionId,
171 pub region_role: RegionRole,
172 pub extensions: HashMap<String, Vec<u8>>,
173}
174
175impl GrantedRegion {
176 pub fn new(region_id: RegionId, region_role: RegionRole) -> Self {
177 Self {
178 region_id,
179 region_role,
180 extensions: HashMap::new(),
181 }
182 }
183}
184
185impl From<GrantedRegion> for PbGrantedRegion {
186 fn from(value: GrantedRegion) -> Self {
187 PbGrantedRegion {
188 region_id: value.region_id.as_u64(),
189 role: PbRegionRole::from(value.region_role).into(),
190 extensions: value.extensions,
191 }
192 }
193}
194
195impl From<PbGrantedRegion> for GrantedRegion {
196 fn from(value: PbGrantedRegion) -> Self {
197 GrantedRegion {
198 region_id: RegionId::from_u64(value.region_id),
199 region_role: value.role().into(),
200 extensions: value.extensions,
201 }
202 }
203}
204
205#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
208pub enum RegionRole {
209 Follower,
211 Leader,
213 DowngradingLeader,
217}
218
219impl Display for RegionRole {
220 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
221 match self {
222 RegionRole::Follower => write!(f, "Follower"),
223 RegionRole::Leader => write!(f, "Leader"),
224 RegionRole::DowngradingLeader => write!(f, "Leader(Downgrading)"),
225 }
226 }
227}
228
229impl RegionRole {
230 pub fn writable(&self) -> bool {
231 matches!(self, RegionRole::Leader)
232 }
233}
234
235impl From<RegionRole> for PbRegionRole {
236 fn from(value: RegionRole) -> Self {
237 match value {
238 RegionRole::Follower => PbRegionRole::Follower,
239 RegionRole::Leader => PbRegionRole::Leader,
240 RegionRole::DowngradingLeader => PbRegionRole::DowngradingLeader,
241 }
242 }
243}
244
245impl From<PbRegionRole> for RegionRole {
246 fn from(value: PbRegionRole) -> Self {
247 match value {
248 PbRegionRole::Leader => RegionRole::Leader,
249 PbRegionRole::Follower => RegionRole::Follower,
250 PbRegionRole::DowngradingLeader => RegionRole::DowngradingLeader,
251 }
252 }
253}
254
255#[derive(Debug)]
257pub enum ScannerPartitioning {
258 Unknown(usize),
260}
261
262impl ScannerPartitioning {
263 pub fn num_partitions(&self) -> usize {
265 match self {
266 ScannerPartitioning::Unknown(num_partitions) => *num_partitions,
267 }
268 }
269}
270
271#[derive(Debug, Clone, Copy, PartialEq, Eq)]
273pub struct PartitionRange {
274 pub start: Timestamp,
276 pub end: Timestamp,
278 pub num_rows: usize,
280 pub identifier: usize,
282}
283
284#[derive(Debug, Default)]
286pub struct ScannerProperties {
287 pub partitions: Vec<Vec<PartitionRange>>,
292
293 append_mode: bool,
295
296 total_rows: usize,
299
300 pub distinguish_partition_range: bool,
302
303 target_partitions: usize,
305
306 logical_region: bool,
308}
309
310impl ScannerProperties {
311 pub fn with_append_mode(mut self, append_mode: bool) -> Self {
313 self.append_mode = append_mode;
314 self
315 }
316
317 pub fn with_total_rows(mut self, total_rows: usize) -> Self {
319 self.total_rows = total_rows;
320 self
321 }
322
323 pub fn new(partitions: Vec<Vec<PartitionRange>>, append_mode: bool, total_rows: usize) -> Self {
325 Self {
326 partitions,
327 append_mode,
328 total_rows,
329 distinguish_partition_range: false,
330 target_partitions: 0,
331 logical_region: false,
332 }
333 }
334
335 pub fn prepare(&mut self, request: PrepareRequest) {
337 if let Some(ranges) = request.ranges {
338 self.partitions = ranges;
339 }
340 if let Some(distinguish_partition_range) = request.distinguish_partition_range {
341 self.distinguish_partition_range = distinguish_partition_range;
342 }
343 if let Some(target_partitions) = request.target_partitions {
344 self.target_partitions = target_partitions;
345 }
346 }
347
348 pub fn num_partitions(&self) -> usize {
350 self.partitions.len()
351 }
352
353 pub fn append_mode(&self) -> bool {
354 self.append_mode
355 }
356
357 pub fn total_rows(&self) -> usize {
358 self.total_rows
359 }
360
361 pub fn is_logical_region(&self) -> bool {
363 self.logical_region
364 }
365
366 pub fn target_partitions(&self) -> usize {
368 if self.target_partitions == 0 {
369 self.num_partitions()
370 } else {
371 self.target_partitions
372 }
373 }
374
375 pub fn set_logical_region(&mut self, logical_region: bool) {
377 self.logical_region = logical_region;
378 }
379}
380
381#[derive(Default)]
383pub struct PrepareRequest {
384 pub ranges: Option<Vec<Vec<PartitionRange>>>,
386 pub distinguish_partition_range: Option<bool>,
388 pub target_partitions: Option<usize>,
390}
391
392impl PrepareRequest {
393 pub fn with_ranges(mut self, ranges: Vec<Vec<PartitionRange>>) -> Self {
395 self.ranges = Some(ranges);
396 self
397 }
398
399 pub fn with_distinguish_partition_range(mut self, distinguish_partition_range: bool) -> Self {
401 self.distinguish_partition_range = Some(distinguish_partition_range);
402 self
403 }
404
405 pub fn with_target_partitions(mut self, target_partitions: usize) -> Self {
407 self.target_partitions = Some(target_partitions);
408 self
409 }
410}
411
412#[derive(Clone, Default)]
414pub struct QueryScanContext {
415 pub explain_verbose: bool,
417}
418
419pub trait RegionScanner: Debug + DisplayAs + Send {
424 fn name(&self) -> &str;
425
426 fn properties(&self) -> &ScannerProperties;
428
429 fn schema(&self) -> SchemaRef;
431
432 fn metadata(&self) -> RegionMetadataRef;
434
435 fn prepare(&mut self, request: PrepareRequest) -> Result<(), BoxedError>;
439
440 fn scan_partition(
445 &self,
446 ctx: &QueryScanContext,
447 metrics_set: &ExecutionPlanMetricsSet,
448 partition: usize,
449 ) -> Result<SendableRecordBatchStream, BoxedError>;
450
451 fn has_predicate_without_region(&self) -> bool;
453
454 fn set_logical_region(&mut self, logical_region: bool);
456}
457
458pub type RegionScannerRef = Box<dyn RegionScanner>;
459
460pub type BatchResponses = Vec<(RegionId, Result<RegionResponse, BoxedError>)>;
461
462#[derive(Debug, Deserialize, Serialize, Default)]
464pub struct RegionStatistic {
465 #[serde(default)]
467 pub num_rows: u64,
468 pub memtable_size: u64,
470 pub wal_size: u64,
472 pub manifest_size: u64,
474 pub sst_size: u64,
476 pub sst_num: u64,
478 #[serde(default)]
480 pub index_size: u64,
481 #[serde(default)]
483 pub manifest: RegionManifestInfo,
484 #[serde(default)]
485 pub written_bytes: u64,
487 #[serde(default)]
491 pub data_topic_latest_entry_id: u64,
492 #[serde(default)]
493 pub metadata_topic_latest_entry_id: u64,
494}
495
496#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
498pub enum RegionManifestInfo {
499 Mito {
500 manifest_version: u64,
501 flushed_entry_id: u64,
502 file_removed_cnt: u64,
504 },
505 Metric {
506 data_manifest_version: u64,
507 data_flushed_entry_id: u64,
508 metadata_manifest_version: u64,
509 metadata_flushed_entry_id: u64,
510 },
511}
512
513impl RegionManifestInfo {
514 pub fn mito(manifest_version: u64, flushed_entry_id: u64, file_removal_rate: u64) -> Self {
516 Self::Mito {
517 manifest_version,
518 flushed_entry_id,
519 file_removed_cnt: file_removal_rate,
520 }
521 }
522
523 pub fn metric(
525 data_manifest_version: u64,
526 data_flushed_entry_id: u64,
527 metadata_manifest_version: u64,
528 metadata_flushed_entry_id: u64,
529 ) -> Self {
530 Self::Metric {
531 data_manifest_version,
532 data_flushed_entry_id,
533 metadata_manifest_version,
534 metadata_flushed_entry_id,
535 }
536 }
537
538 pub fn is_mito(&self) -> bool {
540 matches!(self, RegionManifestInfo::Mito { .. })
541 }
542
543 pub fn is_metric(&self) -> bool {
545 matches!(self, RegionManifestInfo::Metric { .. })
546 }
547
548 pub fn data_flushed_entry_id(&self) -> u64 {
550 match self {
551 RegionManifestInfo::Mito {
552 flushed_entry_id, ..
553 } => *flushed_entry_id,
554 RegionManifestInfo::Metric {
555 data_flushed_entry_id,
556 ..
557 } => *data_flushed_entry_id,
558 }
559 }
560
561 pub fn data_manifest_version(&self) -> u64 {
563 match self {
564 RegionManifestInfo::Mito {
565 manifest_version, ..
566 } => *manifest_version,
567 RegionManifestInfo::Metric {
568 data_manifest_version,
569 ..
570 } => *data_manifest_version,
571 }
572 }
573
574 pub fn metadata_manifest_version(&self) -> Option<u64> {
576 match self {
577 RegionManifestInfo::Mito { .. } => None,
578 RegionManifestInfo::Metric {
579 metadata_manifest_version,
580 ..
581 } => Some(*metadata_manifest_version),
582 }
583 }
584
585 pub fn metadata_flushed_entry_id(&self) -> Option<u64> {
587 match self {
588 RegionManifestInfo::Mito { .. } => None,
589 RegionManifestInfo::Metric {
590 metadata_flushed_entry_id,
591 ..
592 } => Some(*metadata_flushed_entry_id),
593 }
594 }
595
596 pub fn encode_list(manifest_infos: &[(RegionId, Self)]) -> serde_json::Result<Vec<u8>> {
598 serde_json::to_vec(manifest_infos)
599 }
600
601 pub fn decode_list(value: &[u8]) -> serde_json::Result<Vec<(RegionId, Self)>> {
603 serde_json::from_slice(value)
604 }
605}
606
607impl Default for RegionManifestInfo {
608 fn default() -> Self {
609 Self::Mito {
610 manifest_version: 0,
611 flushed_entry_id: 0,
612 file_removed_cnt: 0,
613 }
614 }
615}
616
617impl RegionStatistic {
618 pub fn deserialize_from_slice(value: &[u8]) -> Option<RegionStatistic> {
622 serde_json::from_slice(value).ok()
623 }
624
625 pub fn serialize_to_vec(&self) -> Option<Vec<u8>> {
629 serde_json::to_vec(self).ok()
630 }
631}
632
633impl RegionStatistic {
634 pub fn estimated_disk_size(&self) -> u64 {
636 self.wal_size + self.sst_size + self.manifest_size + self.index_size
637 }
638}
639
640#[derive(Debug)]
642pub enum SyncManifestResponse {
643 NotSupported,
644 Mito {
645 synced: bool,
647 },
648 Metric {
649 metadata_synced: bool,
651 data_synced: bool,
653 new_opened_logical_region_ids: Vec<RegionId>,
656 },
657}
658
659impl SyncManifestResponse {
660 pub fn is_data_synced(&self) -> bool {
662 match self {
663 SyncManifestResponse::NotSupported => false,
664 SyncManifestResponse::Mito { synced } => *synced,
665 SyncManifestResponse::Metric { data_synced, .. } => *data_synced,
666 }
667 }
668
669 pub fn is_supported(&self) -> bool {
671 matches!(self, SyncManifestResponse::NotSupported)
672 }
673
674 pub fn is_mito(&self) -> bool {
676 matches!(self, SyncManifestResponse::Mito { .. })
677 }
678
679 pub fn is_metric(&self) -> bool {
681 matches!(self, SyncManifestResponse::Metric { .. })
682 }
683
684 pub fn new_opened_logical_region_ids(self) -> Option<Vec<RegionId>> {
686 match self {
687 SyncManifestResponse::Metric {
688 new_opened_logical_region_ids,
689 ..
690 } => Some(new_opened_logical_region_ids),
691 _ => None,
692 }
693 }
694}
695
696#[derive(Debug, Clone)]
698pub struct RemapManifestsRequest {
699 pub region_id: RegionId,
701 pub input_regions: Vec<RegionId>,
703 pub region_mapping: HashMap<RegionId, Vec<RegionId>>,
705 pub new_partition_exprs: HashMap<RegionId, String>,
707}
708
709#[derive(Debug, Clone)]
711pub struct RemapManifestsResponse {
712 pub new_manifests: HashMap<RegionId, String>,
714}
715
716#[derive(Debug, Clone)]
718pub struct CopyRegionFromRequest {
719 pub source_region_id: RegionId,
721 pub parallelism: usize,
723}
724
725#[derive(Debug, Clone)]
726pub struct MitoCopyRegionFromResponse {
727 pub copied_file_ids: Vec<FileId>,
729}
730
731#[derive(Debug, Clone)]
732pub struct MetricCopyRegionFromResponse {
733 pub new_opened_logical_region_ids: Vec<RegionId>,
735}
736
737#[derive(Debug, Clone)]
739pub enum CopyRegionFromResponse {
740 Mito(MitoCopyRegionFromResponse),
741 Metric(MetricCopyRegionFromResponse),
742}
743
744impl CopyRegionFromResponse {
745 pub fn into_mito(self) -> Option<MitoCopyRegionFromResponse> {
747 match self {
748 CopyRegionFromResponse::Mito(response) => Some(response),
749 CopyRegionFromResponse::Metric(_) => None,
750 }
751 }
752
753 pub fn into_metric(self) -> Option<MetricCopyRegionFromResponse> {
755 match self {
756 CopyRegionFromResponse::Metric(response) => Some(response),
757 CopyRegionFromResponse::Mito(_) => None,
758 }
759 }
760}
761
762#[async_trait]
763pub trait RegionEngine: Send + Sync {
764 fn name(&self) -> &str;
766
767 async fn handle_batch_open_requests(
769 &self,
770 parallelism: usize,
771 requests: Vec<(RegionId, RegionOpenRequest)>,
772 ) -> Result<BatchResponses, BoxedError> {
773 let semaphore = Arc::new(Semaphore::new(parallelism));
774 let mut tasks = Vec::with_capacity(requests.len());
775
776 for (region_id, request) in requests {
777 let semaphore_moved = semaphore.clone();
778
779 tasks.push(async move {
780 let _permit = semaphore_moved.acquire().await.unwrap();
782 let result = self
783 .handle_request(region_id, RegionRequest::Open(request))
784 .await;
785 (region_id, result)
786 });
787 }
788
789 Ok(join_all(tasks).await)
790 }
791
792 async fn handle_batch_catchup_requests(
793 &self,
794 parallelism: usize,
795 requests: Vec<(RegionId, RegionCatchupRequest)>,
796 ) -> Result<BatchResponses, BoxedError> {
797 let semaphore = Arc::new(Semaphore::new(parallelism));
798 let mut tasks = Vec::with_capacity(requests.len());
799
800 for (region_id, request) in requests {
801 let semaphore_moved = semaphore.clone();
802
803 tasks.push(async move {
804 let _permit = semaphore_moved.acquire().await.unwrap();
806 let result = self
807 .handle_request(region_id, RegionRequest::Catchup(request))
808 .await;
809 (region_id, result)
810 });
811 }
812
813 Ok(join_all(tasks).await)
814 }
815
816 async fn handle_batch_ddl_requests(
817 &self,
818 request: BatchRegionDdlRequest,
819 ) -> Result<RegionResponse, BoxedError> {
820 let requests = request.into_region_requests();
821
822 let mut affected_rows = 0;
823 let mut extensions = HashMap::new();
824
825 for (region_id, request) in requests {
826 let result = self.handle_request(region_id, request).await?;
827 affected_rows += result.affected_rows;
828 extensions.extend(result.extensions);
829 }
830
831 Ok(RegionResponse {
832 affected_rows,
833 extensions,
834 metadata: Vec::new(),
835 })
836 }
837
838 async fn handle_request(
840 &self,
841 region_id: RegionId,
842 request: RegionRequest,
843 ) -> Result<RegionResponse, BoxedError>;
844
845 async fn get_committed_sequence(
847 &self,
848 region_id: RegionId,
849 ) -> Result<SequenceNumber, BoxedError>;
850
851 async fn handle_query(
853 &self,
854 region_id: RegionId,
855 request: ScanRequest,
856 ) -> Result<RegionScannerRef, BoxedError>;
857
858 fn register_query_memory_permit(&self) -> Option<Arc<MemoryPermit>> {
860 None
861 }
862
863 async fn get_metadata(&self, region_id: RegionId) -> Result<RegionMetadataRef, BoxedError>;
865
866 fn region_statistic(&self, region_id: RegionId) -> Option<RegionStatistic>;
868
869 async fn stop(&self) -> Result<(), BoxedError>;
871
872 fn set_region_role(&self, region_id: RegionId, role: RegionRole) -> Result<(), BoxedError>;
878
879 async fn sync_region(
881 &self,
882 region_id: RegionId,
883 manifest_info: RegionManifestInfo,
884 ) -> Result<SyncManifestResponse, BoxedError>;
885
886 async fn remap_manifests(
888 &self,
889 request: RemapManifestsRequest,
890 ) -> Result<RemapManifestsResponse, BoxedError>;
891
892 async fn copy_region_from(
894 &self,
895 region_id: RegionId,
896 request: CopyRegionFromRequest,
897 ) -> Result<CopyRegionFromResponse, BoxedError>;
898
899 async fn set_region_role_state_gracefully(
903 &self,
904 region_id: RegionId,
905 region_role_state: SettableRegionRoleState,
906 ) -> Result<SetRegionRoleStateResponse, BoxedError>;
907
908 fn role(&self, region_id: RegionId) -> Option<RegionRole>;
912
913 fn as_any(&self) -> &dyn Any;
914}
915
916pub type RegionEngineRef = Arc<dyn RegionEngine>;
917
918pub struct SinglePartitionScanner {
920 stream: Mutex<Option<SendableRecordBatchStream>>,
921 schema: SchemaRef,
922 properties: ScannerProperties,
923 metadata: RegionMetadataRef,
924}
925
926impl SinglePartitionScanner {
927 pub fn new(
929 stream: SendableRecordBatchStream,
930 append_mode: bool,
931 metadata: RegionMetadataRef,
932 ) -> Self {
933 let schema = stream.schema();
934 Self {
935 stream: Mutex::new(Some(stream)),
936 schema,
937 properties: ScannerProperties::default().with_append_mode(append_mode),
938 metadata,
939 }
940 }
941}
942
943impl Debug for SinglePartitionScanner {
944 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
945 write!(f, "SinglePartitionScanner: <SendableRecordBatchStream>")
946 }
947}
948
949impl RegionScanner for SinglePartitionScanner {
950 fn name(&self) -> &str {
951 "SinglePartition"
952 }
953
954 fn properties(&self) -> &ScannerProperties {
955 &self.properties
956 }
957
958 fn schema(&self) -> SchemaRef {
959 self.schema.clone()
960 }
961
962 fn prepare(&mut self, request: PrepareRequest) -> Result<(), BoxedError> {
963 self.properties.prepare(request);
964 Ok(())
965 }
966
967 fn scan_partition(
968 &self,
969 _ctx: &QueryScanContext,
970 _metrics_set: &ExecutionPlanMetricsSet,
971 _partition: usize,
972 ) -> Result<SendableRecordBatchStream, BoxedError> {
973 let mut stream = self.stream.lock().unwrap();
974 let result = stream
975 .take()
976 .or_else(|| Some(Box::pin(EmptyRecordBatchStream::new(self.schema.clone()))));
977 Ok(result.unwrap())
978 }
979
980 fn has_predicate_without_region(&self) -> bool {
981 false
982 }
983
984 fn metadata(&self) -> RegionMetadataRef {
985 self.metadata.clone()
986 }
987
988 fn set_logical_region(&mut self, logical_region: bool) {
989 self.properties.set_logical_region(logical_region);
990 }
991}
992
993impl DisplayAs for SinglePartitionScanner {
994 fn fmt_as(&self, _t: DisplayFormatType, f: &mut std::fmt::Formatter) -> std::fmt::Result {
995 write!(f, "{:?}", self)
996 }
997}