mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
feat(query): prepare native raw series without execution
Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
+133
-95
@@ -19,6 +19,10 @@ mod json_expr_planner;
|
||||
mod pg_oid_alias_expr_planner;
|
||||
mod planner;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "datafusion/raw_series_admission_tests.rs"]
|
||||
mod raw_series_admission_tests;
|
||||
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -53,6 +57,7 @@ use datafusion_expr::{
|
||||
};
|
||||
use datatypes::prelude::VectorRef;
|
||||
use datatypes::schema::Schema;
|
||||
use datatypes::series::raw::RawSeriesOrdering;
|
||||
use futures_util::StreamExt;
|
||||
use session::context::QueryContextRef;
|
||||
use snafu::{OptionExt, ResultExt, ensure};
|
||||
@@ -67,10 +72,11 @@ pub use crate::datafusion::planner::DfContextProviderAdapter;
|
||||
use crate::dist_plan::{
|
||||
DistPlannerOptions, MergeScanLogicalPlan, RemoteDynFilterReceiverInjectorRef,
|
||||
};
|
||||
use crate::dummy_catalog::DummyTableProvider;
|
||||
use crate::error::{
|
||||
CatalogSnafu, CreateRecordBatchSnafu, MissingTableMutationHandlerSnafu,
|
||||
MissingTimestampColumnSnafu, QueryExecutionSnafu, Result, TableMutationSnafu,
|
||||
TableNotFoundSnafu, TableReadOnlySnafu, UnsupportedExprSnafu,
|
||||
TableNotFoundSnafu, TableReadOnlySnafu, UnimplementedSnafu, UnsupportedExprSnafu,
|
||||
};
|
||||
use crate::executor::QueryExecutor;
|
||||
use crate::metrics::{
|
||||
@@ -202,7 +208,113 @@ pub struct DatafusionQueryEngine {
|
||||
plugins: Plugins,
|
||||
}
|
||||
|
||||
struct PreparedRawSeries {
|
||||
context: QueryEngineContext,
|
||||
plan: Arc<dyn ExecutionPlan>,
|
||||
ordering: RawSeriesOrdering,
|
||||
}
|
||||
|
||||
impl DatafusionQueryEngine {
|
||||
async fn prepare_raw_series_plan(
|
||||
&self,
|
||||
plan: LogicalPlan,
|
||||
query_ctx: QueryContextRef,
|
||||
binding: &RawSeriesRequest,
|
||||
) -> Result<Option<PreparedRawSeries>> {
|
||||
if let Some(hint) = query_ctx.extension(QUERY_PARALLELISM_HINT)
|
||||
&& hint.parse::<usize>().ok() != Some(1)
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
if query_ctx
|
||||
.extension(INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY)
|
||||
.is_some()
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let LogicalPlan::TableScan(scan) = &plan else {
|
||||
return Ok(None);
|
||||
};
|
||||
if scan.fetch.is_some()
|
||||
|| scan.projection.is_none()
|
||||
|| !scan.statistics_requests.is_empty()
|
||||
|| scan.filters.iter().any(|e| !raw_expr_supported(e))
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
let Some(source) = scan.source.downcast_ref::<DefaultTableSource>() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(provider) = source.table_provider.downcast_ref::<DummyTableProvider>() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let Some(provider) = provider.clone_for_raw_series() else {
|
||||
return Ok(None);
|
||||
};
|
||||
let replacement = Arc::new(provider);
|
||||
let new_source = Arc::new(DefaultTableSource::new(replacement));
|
||||
let mut scan = scan.clone();
|
||||
scan.source = new_source;
|
||||
let plan = LogicalPlan::TableScan(scan);
|
||||
|
||||
let normal_ctx = self.engine_context(query_ctx.clone());
|
||||
let mut state = normal_ctx.state().clone();
|
||||
let config = state.config().clone().with_target_partitions(1);
|
||||
*state.config_mut() = config;
|
||||
let mut ctx = QueryEngineContext::new(state, query_ctx.clone());
|
||||
let physical = self.create_physical_plan(&mut ctx, &plan).await?;
|
||||
let physical = self.optimize_physical_plan(&mut ctx, physical)?;
|
||||
let cooperative = (physical.as_ref() as &dyn Any).downcast_ref::<CooperativeExec>();
|
||||
let scan_candidate = cooperative.map_or(&physical, |plan| plan.input());
|
||||
if scan_candidate.name() != REGION_SCAN_EXEC_NAME {
|
||||
common_telemetry::debug!(
|
||||
"Raw series physical plan rejected: root={}, scan candidate={}",
|
||||
physical.name(),
|
||||
scan_candidate.name(),
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
let Some(scan) = (scan_candidate.as_ref() as &dyn Any).downcast_ref::<RegionScanExec>()
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let ranges = scan.get_partition_ranges();
|
||||
let prepared = Arc::new(
|
||||
scan.with_new_partitions(vec![ranges], 1)
|
||||
.map_err(BoxedError::new)
|
||||
.context(QueryExecutionSnafu)?,
|
||||
);
|
||||
let Some(native) = prepared.clone().try_to_bound_series_scan(binding)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
let ordering = native.raw_series_ordering();
|
||||
let native_plan: Arc<dyn ExecutionPlan> = native;
|
||||
let native_plan = if cooperative.is_some() {
|
||||
physical.replace_children(
|
||||
vec![native_plan],
|
||||
ReplaceChildrenOptions::new(ChildrenPropertiesMode::Recompute),
|
||||
)?
|
||||
} else {
|
||||
native_plan
|
||||
};
|
||||
let wrapped = if let Some(wrapper) = self.plugins.get::<PhysicalPlanWrapperRef>() {
|
||||
wrapper.wrap(native_plan.clone(), query_ctx)
|
||||
} else {
|
||||
native_plan.clone()
|
||||
};
|
||||
if !Arc::ptr_eq(&native_plan, &wrapped)
|
||||
|| native_plan.schema() != wrapped.schema()
|
||||
|| wrapped.properties().output_partitioning().partition_count() != 1
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(PreparedRawSeries {
|
||||
context: ctx,
|
||||
plan: wrapped,
|
||||
ordering,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn new(state: Arc<QueryEngineState>, plugins: Plugins) -> Self {
|
||||
Self { state, plugins }
|
||||
}
|
||||
@@ -580,111 +692,37 @@ impl QueryEngine for DatafusionQueryEngine {
|
||||
}
|
||||
}
|
||||
|
||||
async fn prepare_raw_series(
|
||||
&self,
|
||||
plan: LogicalPlan,
|
||||
query_ctx: QueryContextRef,
|
||||
binding: RawSeriesRequest,
|
||||
) -> Result<Option<RawSeriesOrdering>> {
|
||||
Ok(self
|
||||
.prepare_raw_series_plan(plan, query_ctx, &binding)
|
||||
.await?
|
||||
.map(|prepared| prepared.ordering))
|
||||
}
|
||||
|
||||
async fn execute_raw_series(
|
||||
&self,
|
||||
plan: LogicalPlan,
|
||||
query_ctx: QueryContextRef,
|
||||
binding: RawSeriesRequest,
|
||||
) -> Result<Output> {
|
||||
use crate::dummy_catalog::DummyTableProvider;
|
||||
use crate::error::{QueryExecutionSnafu, UnimplementedSnafu};
|
||||
|
||||
let unsupported = || {
|
||||
UnimplementedSnafu {
|
||||
let Some(prepared) = self
|
||||
.prepare_raw_series_plan(plan, query_ctx, &binding)
|
||||
.await?
|
||||
else {
|
||||
return Err(UnimplementedSnafu {
|
||||
operation: "unsupported native raw-series plan".to_string(),
|
||||
}
|
||||
.build()
|
||||
.build());
|
||||
};
|
||||
if let Some(hint) = query_ctx.extension(QUERY_PARALLELISM_HINT)
|
||||
&& hint.parse::<usize>().ok() != Some(1)
|
||||
{
|
||||
return Err(unsupported());
|
||||
}
|
||||
if query_ctx
|
||||
.extension(INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY)
|
||||
.is_some()
|
||||
{
|
||||
return Err(unsupported());
|
||||
}
|
||||
let LogicalPlan::TableScan(scan) = &plan else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
if scan.fetch.is_some()
|
||||
|| scan.projection.is_none()
|
||||
|| !scan.statistics_requests.is_empty()
|
||||
|| scan.filters.iter().any(|e| !raw_expr_supported(e))
|
||||
{
|
||||
return Err(unsupported());
|
||||
}
|
||||
let Some(source) = scan.source.downcast_ref::<DefaultTableSource>() else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
let Some(provider) = source.table_provider.downcast_ref::<DummyTableProvider>() else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
let Some(provider) = provider.clone_for_raw_series() else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
let replacement = Arc::new(provider);
|
||||
let new_source = Arc::new(DefaultTableSource::new(replacement));
|
||||
let mut scan = scan.clone();
|
||||
scan.source = new_source;
|
||||
let plan = LogicalPlan::TableScan(scan);
|
||||
|
||||
let normal_ctx = self.engine_context(query_ctx.clone());
|
||||
let mut state = normal_ctx.state().clone();
|
||||
let config = state.config().clone().with_target_partitions(1);
|
||||
*state.config_mut() = config;
|
||||
let mut ctx = QueryEngineContext::new(state, query_ctx.clone());
|
||||
let physical = self.create_physical_plan(&mut ctx, &plan).await?;
|
||||
let physical = self.optimize_physical_plan(&mut ctx, physical)?;
|
||||
let cooperative = (physical.as_ref() as &dyn Any).downcast_ref::<CooperativeExec>();
|
||||
let scan_candidate = cooperative.map_or(&physical, |plan| plan.input());
|
||||
if scan_candidate.name() != REGION_SCAN_EXEC_NAME {
|
||||
common_telemetry::debug!(
|
||||
"Raw series physical plan rejected: root={}, scan candidate={}",
|
||||
physical.name(),
|
||||
scan_candidate.name(),
|
||||
);
|
||||
return Err(unsupported());
|
||||
}
|
||||
let Some(scan) = (scan_candidate.as_ref() as &dyn Any).downcast_ref::<RegionScanExec>()
|
||||
else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
let ranges = scan.get_partition_ranges();
|
||||
let prepared = Arc::new(
|
||||
scan.with_new_partitions(vec![ranges], 1)
|
||||
.map_err(BoxedError::new)
|
||||
.context(QueryExecutionSnafu)?,
|
||||
);
|
||||
let Some(native) = prepared.clone().try_to_bound_series_scan(&binding)? else {
|
||||
return Err(unsupported());
|
||||
};
|
||||
let native_plan: Arc<dyn ExecutionPlan> = native;
|
||||
let native_plan = if cooperative.is_some() {
|
||||
physical.replace_children(
|
||||
vec![native_plan],
|
||||
ReplaceChildrenOptions::new(ChildrenPropertiesMode::Recompute),
|
||||
)?
|
||||
} else {
|
||||
native_plan
|
||||
};
|
||||
let wrapped = if let Some(wrapper) = self.plugins.get::<PhysicalPlanWrapperRef>() {
|
||||
wrapper.wrap(native_plan.clone(), query_ctx)
|
||||
} else {
|
||||
native_plan.clone()
|
||||
};
|
||||
if !Arc::ptr_eq(&native_plan, &wrapped)
|
||||
|| native_plan.schema() != wrapped.schema()
|
||||
|| wrapped.properties().output_partitioning().partition_count() != 1
|
||||
{
|
||||
return Err(unsupported());
|
||||
}
|
||||
let stream = self.execute_stream(&ctx, &wrapped)?;
|
||||
let stream = self.execute_stream(&prepared.context, &prepared.plan)?;
|
||||
Ok(Output::new(
|
||||
OutputData::Stream(stream),
|
||||
OutputMeta::new_with_plan(wrapped),
|
||||
OutputMeta::new_with_plan(prepared.plan),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// Copyright 2023 Greptime Team
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use common_query::request::{
|
||||
INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY, RawSeriesRequest,
|
||||
};
|
||||
use datafusion::datasource::DefaultTableSource;
|
||||
use datafusion_expr::{LogicalPlan, LogicalPlanBuilder, col, lit};
|
||||
use session::context::{QueryContext, QueryContextBuilder};
|
||||
use store_api::storage::RegionId;
|
||||
|
||||
use crate::QueryEngineRef;
|
||||
use crate::datafusion::QUERY_PARALLELISM_HINT;
|
||||
use crate::options::QueryOptions;
|
||||
use crate::query_engine::QueryEngineFactory;
|
||||
|
||||
async fn engine() -> QueryEngineRef {
|
||||
QueryEngineFactory::new(
|
||||
catalog::memory::new_memory_catalog_manager().unwrap(),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
false,
|
||||
QueryOptions::default(),
|
||||
)
|
||||
.query_engine()
|
||||
}
|
||||
|
||||
fn mock_scan() -> (LogicalPlan, RawSeriesRequest) {
|
||||
let provider = crate::optimizer::test_util::mock_table_provider(RegionId::new(1, 1));
|
||||
let metadata = provider.region_metadata();
|
||||
let source = Arc::new(DefaultTableSource::new(Arc::new(provider)));
|
||||
let scan = LogicalPlanBuilder::scan("raw", source, Some(vec![2]))
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
let binding = RawSeriesRequest {
|
||||
version: 1,
|
||||
physical_metadata: metadata.as_ref().clone(),
|
||||
metric_name: "m".to_string(),
|
||||
logical_tags: vec![],
|
||||
field_ids: vec![3],
|
||||
};
|
||||
(scan, binding)
|
||||
}
|
||||
|
||||
async fn assert_rejected(
|
||||
engine: &QueryEngineRef,
|
||||
plan: LogicalPlan,
|
||||
ctx: Arc<QueryContext>,
|
||||
binding: RawSeriesRequest,
|
||||
) {
|
||||
assert!(
|
||||
engine
|
||||
.prepare_raw_series(plan.clone(), ctx.clone(), binding.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none()
|
||||
);
|
||||
let error = match engine.execute_raw_series(plan, ctx, binding).await {
|
||||
Err(error) => error,
|
||||
Ok(_) => panic!("unsupported raw-series plan was accepted"),
|
||||
};
|
||||
assert!(matches!(
|
||||
error,
|
||||
crate::error::Error::Unimplemented { operation, .. }
|
||||
if operation == "unsupported native raw-series plan"
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn raw_series_admission_rejects_invalid_parallelism_hints() {
|
||||
let engine = engine().await;
|
||||
let (scan, binding) = mock_scan();
|
||||
for hint in ["invalid", "0", "2"] {
|
||||
let ctx = Arc::new(
|
||||
QueryContextBuilder::default()
|
||||
.set_extension(QUERY_PARALLELISM_HINT.to_string(), hint.to_string())
|
||||
.build(),
|
||||
);
|
||||
assert_rejected(&engine, scan.clone(), ctx, binding.clone()).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn raw_series_admission_rejects_dynamic_filters_and_parent_plans() {
|
||||
let engine = engine().await;
|
||||
let (scan, binding) = mock_scan();
|
||||
let ctx = Arc::new(
|
||||
QueryContextBuilder::default()
|
||||
.set_extension(
|
||||
INITIAL_REMOTE_DYN_FILTER_REGISTRATIONS_EXTENSION_KEY.to_string(),
|
||||
"malformed marker".to_string(),
|
||||
)
|
||||
.build(),
|
||||
);
|
||||
assert_rejected(&engine, scan.clone(), ctx, binding.clone()).await;
|
||||
|
||||
let parent = LogicalPlanBuilder::from(scan)
|
||||
.filter(col("v0").gt(lit(0.0)))
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
let ctx = Arc::new(
|
||||
QueryContextBuilder::default()
|
||||
.set_extension(QUERY_PARALLELISM_HINT.to_string(), "1".to_string())
|
||||
.build(),
|
||||
);
|
||||
assert_rejected(&engine, parent, ctx, binding).await;
|
||||
}
|
||||
@@ -33,6 +33,7 @@ use common_query::request::RawSeriesRequest;
|
||||
use datafusion::catalog::TableFunction;
|
||||
use datafusion::dataframe::DataFrame;
|
||||
use datafusion_expr::{AggregateUDF, LogicalPlan, WindowUDF};
|
||||
use datatypes::series::raw::RawSeriesOrdering;
|
||||
pub use default_serializer::{DefaultPlanDecoder, DefaultSerializer};
|
||||
use partition::manager::PartitionRuleManagerRef;
|
||||
use session::context::QueryContextRef;
|
||||
@@ -78,6 +79,18 @@ pub trait QueryEngine: Send + Sync {
|
||||
/// Execute the given [`LogicalPlan`].
|
||||
async fn execute(&self, plan: LogicalPlan, query_ctx: QueryContextRef) -> Result<Output>;
|
||||
|
||||
/// Non-consumingly checks whether a native single-region raw-series scan is supported.
|
||||
/// Returns its ordering on support, `None` when explicitly unsupported, and propagates errors.
|
||||
/// This point-in-time check does not reserve a plan; execution revalidates support.
|
||||
async fn prepare_raw_series(
|
||||
&self,
|
||||
_plan: LogicalPlan,
|
||||
_query_ctx: QueryContextRef,
|
||||
_binding: RawSeriesRequest,
|
||||
) -> Result<Option<RawSeriesOrdering>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Execute a native single-region raw-series scan.
|
||||
async fn execute_raw_series(
|
||||
&self,
|
||||
|
||||
@@ -56,6 +56,7 @@ use datafusion_physical_expr::{
|
||||
use datatypes::arrow::datatypes::SchemaRef as ArrowSchemaRef;
|
||||
use datatypes::compute::SortOptions;
|
||||
use datatypes::series::frame::RawLabelMode;
|
||||
use datatypes::series::raw::RawSeriesOrdering;
|
||||
use datatypes::series::samples::SeriesSchema;
|
||||
use futures::{Stream, StreamExt};
|
||||
use store_api::metric_engine_consts::DATA_SCHEMA_TSID_COLUMN_NAME;
|
||||
@@ -474,10 +475,11 @@ impl RegionScanExec {
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let ordering = scanner.raw_series_ordering();
|
||||
let arrow_schema = raw_series_frame_schema_with_ordering(
|
||||
&schema,
|
||||
raw_label_mode(&label_source),
|
||||
scanner.raw_series_ordering(),
|
||||
ordering,
|
||||
)?;
|
||||
let partition_count = scanner.properties().num_partitions().max(1);
|
||||
let properties = Arc::new(PlanProperties::new(
|
||||
@@ -492,6 +494,7 @@ impl RegionScanExec {
|
||||
label_source,
|
||||
series_schema: schema,
|
||||
arrow_schema,
|
||||
ordering,
|
||||
properties,
|
||||
})))
|
||||
}
|
||||
@@ -504,6 +507,7 @@ pub struct SeriesScanExec {
|
||||
label_source: RawLabelSource,
|
||||
series_schema: Arc<SeriesSchema>,
|
||||
arrow_schema: ArrowSchemaRef,
|
||||
ordering: RawSeriesOrdering,
|
||||
properties: Arc<PlanProperties>,
|
||||
}
|
||||
|
||||
@@ -532,6 +536,11 @@ impl SeriesScanExec {
|
||||
&self.series_schema
|
||||
}
|
||||
|
||||
/// Returns the producer ordering captured when this scan was prepared.
|
||||
pub fn raw_series_ordering(&self) -> RawSeriesOrdering {
|
||||
self.ordering
|
||||
}
|
||||
|
||||
pub fn query_load_region_id(&self) -> Option<u64> {
|
||||
self.scan.query_load_region_id()
|
||||
}
|
||||
|
||||
@@ -1098,3 +1098,51 @@ fn bound_series_scan_uses_open_scanner_metadata_without_execution() {
|
||||
assert_eq!(state.lock().unwrap().raw_calls, 0);
|
||||
assert_eq!(state.lock().unwrap().legacy_calls, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn raw_series_admission_captures_scanner_ordering_before_execution() {
|
||||
for ordering in [
|
||||
RawSeriesOrdering::ReadKeyThenTime,
|
||||
RawSeriesOrdering::Contiguous,
|
||||
] {
|
||||
let schema = series_schema();
|
||||
let chunk = chunk(&schema);
|
||||
let (scan, state) = fixture(Some(schema), vec![chunk]);
|
||||
{
|
||||
let mut state = state.lock().unwrap();
|
||||
state.planned_ordering = Some(ordering);
|
||||
state.stream_ordering = Some(ordering);
|
||||
}
|
||||
|
||||
let plan = scan
|
||||
.try_to_series_scan(RawLabelSource::Explicit)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(plan.raw_series_ordering(), ordering);
|
||||
assert_eq!(
|
||||
raw_series_frame_ordering(plan.schema().as_ref()).unwrap(),
|
||||
ordering
|
||||
);
|
||||
{
|
||||
let state = state.lock().unwrap();
|
||||
assert_eq!(state.preflights, 1);
|
||||
assert_eq!(state.raw_calls, 0);
|
||||
assert_eq!(state.legacy_calls, 0);
|
||||
assert_eq!(state.polls, 0);
|
||||
assert_eq!(state.drops, 0);
|
||||
}
|
||||
|
||||
state.lock().unwrap().planned_ordering = Some(match ordering {
|
||||
RawSeriesOrdering::ReadKeyThenTime => RawSeriesOrdering::Contiguous,
|
||||
RawSeriesOrdering::Contiguous => RawSeriesOrdering::ReadKeyThenTime,
|
||||
});
|
||||
assert_eq!(plan.raw_series_ordering(), ordering);
|
||||
assert!(plan.execute(0, context()).is_err());
|
||||
let state = state.lock().unwrap();
|
||||
assert_eq!(state.preflights, 2);
|
||||
assert_eq!(state.raw_calls, 0);
|
||||
assert_eq!(state.legacy_calls, 0);
|
||||
assert_eq!(state.polls, 0);
|
||||
assert_eq!(state.drops, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1226,11 +1226,14 @@ async fn assert_raw_entrypoint_wrapper_contract(
|
||||
use query::query_engine::QueryEngineFactory;
|
||||
use std::any::Any;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::{Mutex, Weak};
|
||||
use table::table::scan::SeriesScanExec;
|
||||
|
||||
struct TestWrapper {
|
||||
identity: bool,
|
||||
calls: Arc<AtomicUsize>,
|
||||
prepared_ordering: Arc<Mutex<Option<RawSeriesOrdering>>>,
|
||||
prepared_plan: Arc<Mutex<Option<Weak<dyn ExecutionPlan>>>>,
|
||||
}
|
||||
|
||||
impl PhysicalPlanWrapper for TestWrapper {
|
||||
@@ -1240,6 +1243,13 @@ async fn assert_raw_entrypoint_wrapper_contract(
|
||||
_ctx: QueryContextRef,
|
||||
) -> Arc<dyn ExecutionPlan> {
|
||||
self.calls.fetch_add(1, Ordering::SeqCst);
|
||||
if let Some(root) = (origin.as_ref() as &dyn Any).downcast_ref::<CooperativeExec>()
|
||||
&& let Some(child) =
|
||||
(root.input().as_ref() as &dyn Any).downcast_ref::<SeriesScanExec>()
|
||||
{
|
||||
*self.prepared_ordering.lock().unwrap() = Some(child.raw_series_ordering());
|
||||
*self.prepared_plan.lock().unwrap() = Some(Arc::downgrade(&origin));
|
||||
}
|
||||
if self.identity {
|
||||
origin
|
||||
} else {
|
||||
@@ -1273,11 +1283,15 @@ async fn assert_raw_entrypoint_wrapper_contract(
|
||||
.build()
|
||||
.unwrap();
|
||||
let calls = Arc::new(AtomicUsize::new(0));
|
||||
let prepared_ordering = Arc::new(Mutex::new(None));
|
||||
let prepared_plan = Arc::new(Mutex::new(None));
|
||||
let plugins_for = |identity| {
|
||||
let plugins = Plugins::new();
|
||||
plugins.insert(Arc::new(TestWrapper {
|
||||
identity,
|
||||
calls: calls.clone(),
|
||||
prepared_ordering: prepared_ordering.clone(),
|
||||
prepared_plan: prepared_plan.clone(),
|
||||
}) as PhysicalPlanWrapperRef);
|
||||
plugins
|
||||
};
|
||||
@@ -1297,6 +1311,42 @@ async fn assert_raw_entrypoint_wrapper_contract(
|
||||
};
|
||||
|
||||
let identity_engine = make_engine(true);
|
||||
assert_eq!(
|
||||
Some(RawSeriesOrdering::ReadKeyThenTime),
|
||||
identity_engine
|
||||
.prepare_raw_series(scan.clone(), query_ctx.clone(), binding.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(1, calls.load(Ordering::SeqCst));
|
||||
assert_eq!(
|
||||
Some(RawSeriesOrdering::ReadKeyThenTime),
|
||||
*prepared_ordering.lock().unwrap()
|
||||
);
|
||||
assert!(
|
||||
prepared_plan
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.upgrade()
|
||||
.is_none(),
|
||||
"preparation should release its physical plan"
|
||||
);
|
||||
let mut mismatched_binding = binding.clone();
|
||||
mismatched_binding.physical_metadata.schema_version += 1;
|
||||
let binding_error = identity_engine
|
||||
.prepare_raw_series(scan.clone(), query_ctx.clone(), mismatched_binding)
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
binding_error
|
||||
.to_string()
|
||||
.contains("Raw-series metadata mismatch")
|
||||
);
|
||||
calls.store(0, Ordering::SeqCst);
|
||||
*prepared_ordering.lock().unwrap() = None;
|
||||
*prepared_plan.lock().unwrap() = None;
|
||||
let identity_output = identity_engine
|
||||
.execute_raw_series(scan.clone(), query_ctx.clone(), binding.clone())
|
||||
.await
|
||||
@@ -1370,9 +1420,20 @@ async fn assert_raw_entrypoint_wrapper_contract(
|
||||
);
|
||||
|
||||
calls.store(0, Ordering::SeqCst);
|
||||
*prepared_ordering.lock().unwrap() = None;
|
||||
*prepared_plan.lock().unwrap() = None;
|
||||
let wrapped_engine = make_engine(false);
|
||||
assert_eq!(
|
||||
None,
|
||||
wrapped_engine
|
||||
.prepare_raw_series(scan.clone(), query_ctx.clone(), binding.clone())
|
||||
.await
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(1, calls.load(Ordering::SeqCst));
|
||||
calls.store(0, Ordering::SeqCst);
|
||||
let raw_error = match wrapped_engine
|
||||
.execute_raw_series(scan.clone(), query_ctx.clone(), binding)
|
||||
.execute_raw_series(scan.clone(), query_ctx.clone(), binding.clone())
|
||||
.await
|
||||
{
|
||||
Err(error) => error,
|
||||
|
||||
Reference in New Issue
Block a user