mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-12-01 07:04:09 +00:00
fix(query): decline the native route where no raw scan exists
Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
@@ -166,6 +166,22 @@ impl PromPlanner {
|
||||
return Ok(None);
|
||||
};
|
||||
let table = self.table_from_source(&scan.source)?;
|
||||
let table_meta = &table.table_info().meta;
|
||||
// The region's raw-series preflight refuses these, and the physical layer turns that refusal into an error, so decline this route here instead.
|
||||
let time_index_type = table_meta
|
||||
.schema
|
||||
.timestamp_column()
|
||||
.map(|column| &column.data_type);
|
||||
if time_index_type
|
||||
!= Some(&datatypes::prelude::ConcreteDataType::timestamp_millisecond_datatype())
|
||||
|| table_meta
|
||||
.options
|
||||
.extra_options
|
||||
.get(store_api::mito_engine_options::APPEND_MODE_KEY)
|
||||
.is_some_and(|value| value.eq_ignore_ascii_case("true"))
|
||||
{
|
||||
return Ok(None);
|
||||
}
|
||||
// FusedSeries evaluates each region independently, so partition keys must identify a series.
|
||||
if !table
|
||||
.table_info()
|
||||
|
||||
@@ -908,6 +908,25 @@ async fn build_test_table_provider_with_partition_columns(
|
||||
num_tag: usize,
|
||||
num_field: usize,
|
||||
partition_key_indices: Vec<usize>,
|
||||
) -> DfTableSourceProvider {
|
||||
build_test_table_provider_with_options(
|
||||
table_name_tuples,
|
||||
num_tag,
|
||||
num_field,
|
||||
partition_key_indices,
|
||||
ConcreteDataType::timestamp_millisecond_datatype(),
|
||||
false,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn build_test_table_provider_with_options(
|
||||
table_name_tuples: &[(String, String)],
|
||||
num_tag: usize,
|
||||
num_field: usize,
|
||||
partition_key_indices: Vec<usize>,
|
||||
timestamp_type: ConcreteDataType,
|
||||
append_mode: bool,
|
||||
) -> DfTableSourceProvider {
|
||||
let catalog_list = MemoryCatalogManager::with_default_setup();
|
||||
for (schema_name, table_name) in table_name_tuples {
|
||||
@@ -920,12 +939,8 @@ async fn build_test_table_provider_with_partition_columns(
|
||||
));
|
||||
}
|
||||
columns.push(
|
||||
ColumnSchema::new(
|
||||
"timestamp".to_string(),
|
||||
ConcreteDataType::timestamp_millisecond_datatype(),
|
||||
false,
|
||||
)
|
||||
.with_time_index(true),
|
||||
ColumnSchema::new("timestamp".to_string(), timestamp_type.clone(), false)
|
||||
.with_time_index(true),
|
||||
);
|
||||
for i in 0..num_field {
|
||||
columns.push(ColumnSchema::new(
|
||||
@@ -941,6 +956,17 @@ async fn build_test_table_provider_with_partition_columns(
|
||||
.partition_key_indices(partition_key_indices.clone())
|
||||
.value_indices((num_tag + 1..num_tag + 1 + num_field).collect())
|
||||
.next_column_id(1024)
|
||||
.options(table::requests::TableOptions {
|
||||
extra_options: if append_mode {
|
||||
HashMap::from([(
|
||||
store_api::mito_engine_options::APPEND_MODE_KEY.to_string(),
|
||||
"true".to_string(),
|
||||
)])
|
||||
} else {
|
||||
HashMap::new()
|
||||
},
|
||||
..Default::default()
|
||||
})
|
||||
.build()
|
||||
.unwrap();
|
||||
let table_info = TableInfoBuilder::default()
|
||||
@@ -1714,6 +1740,70 @@ async fn native_fused_time_partitioned_table_falls_back() {
|
||||
assert!(display.contains("PromRangeManipulate"), "{display}");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_fused_non_millisecond_time_index_falls_back() {
|
||||
let table_provider = build_test_table_provider_with_options(
|
||||
&[(DEFAULT_SCHEMA_NAME.to_string(), "some_metric".to_string())],
|
||||
1,
|
||||
1,
|
||||
vec![],
|
||||
ConcreteDataType::timestamp_microsecond_datatype(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
let native =
|
||||
build_native_fused_plan_with_provider("rate(some_metric[5m])", true, table_provider).await;
|
||||
let fallback_provider = build_test_table_provider_with_options(
|
||||
&[(DEFAULT_SCHEMA_NAME.to_string(), "some_metric".to_string())],
|
||||
1,
|
||||
1,
|
||||
vec![],
|
||||
ConcreteDataType::timestamp_microsecond_datatype(),
|
||||
false,
|
||||
)
|
||||
.await;
|
||||
let without_flag =
|
||||
build_native_fused_plan_with_provider("rate(some_metric[5m])", false, fallback_provider)
|
||||
.await;
|
||||
assert!(!native.display_indent().to_string().contains("FusedSeries"));
|
||||
assert_eq!(
|
||||
native.display_indent().to_string(),
|
||||
without_flag.display_indent().to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_fused_append_mode_table_falls_back() {
|
||||
let table_provider = build_test_table_provider_with_options(
|
||||
&[(DEFAULT_SCHEMA_NAME.to_string(), "some_metric".to_string())],
|
||||
1,
|
||||
1,
|
||||
vec![],
|
||||
ConcreteDataType::timestamp_millisecond_datatype(),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
let native =
|
||||
build_native_fused_plan_with_provider("rate(some_metric[5m])", true, table_provider).await;
|
||||
let fallback_provider = build_test_table_provider_with_options(
|
||||
&[(DEFAULT_SCHEMA_NAME.to_string(), "some_metric".to_string())],
|
||||
1,
|
||||
1,
|
||||
vec![],
|
||||
ConcreteDataType::timestamp_millisecond_datatype(),
|
||||
true,
|
||||
)
|
||||
.await;
|
||||
let without_flag =
|
||||
build_native_fused_plan_with_provider("rate(some_metric[5m])", false, fallback_provider)
|
||||
.await;
|
||||
assert!(!native.display_indent().to_string().contains("FusedSeries"));
|
||||
assert_eq!(
|
||||
native.display_indent().to_string(),
|
||||
without_flag.display_indent().to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn native_fused_tag_partitioned_table_still_plans_fused_series() {
|
||||
let table_provider = build_test_table_provider_with_partition_columns(
|
||||
|
||||
Reference in New Issue
Block a user