diff --git a/src/datatypes/src/schema/column_schema.rs b/src/datatypes/src/schema/column_schema.rs index 21ad5e4fd5d1..c1e2df846918 100644 --- a/src/datatypes/src/schema/column_schema.rs +++ b/src/datatypes/src/schema/column_schema.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::{BTreeMap, HashMap}; +use std::collections::HashMap; use std::fmt; use std::str::FromStr; @@ -56,28 +56,6 @@ pub struct ColumnSchema { metadata: Metadata, } -impl PartialOrd for ColumnSchema { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for ColumnSchema { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.name - .cmp(&other.name) - .then_with(|| self.data_type.cmp(&other.data_type)) - .then_with(|| self.is_nullable.cmp(&other.is_nullable)) - .then_with(|| self.is_time_index.cmp(&other.is_time_index)) - .then_with(|| self.default_constraint.cmp(&other.default_constraint)) - .then_with(|| { - let left = BTreeMap::from_iter(self.metadata.iter()); - let right = BTreeMap::from_iter(other.metadata.iter()); - left.cmp(&right) - }) - } -} - impl fmt::Debug for ColumnSchema { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( diff --git a/src/datatypes/src/schema/constraint.rs b/src/datatypes/src/schema/constraint.rs index 090776313a1d..faf08a1bb8c3 100644 --- a/src/datatypes/src/schema/constraint.rs +++ b/src/datatypes/src/schema/constraint.rs @@ -29,7 +29,7 @@ pub const CURRENT_TIMESTAMP_FN: &str = "current_timestamp()"; pub const NOW_FN: &str = "now()"; /// Column's default constraint. -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ColumnDefaultConstraint { // A function invocation // TODO(dennis): we save the function expression here, maybe use a struct in future. diff --git a/src/metric-engine/src/engine/region_metadata.rs b/src/metric-engine/src/engine/region_metadata.rs index ac4049aa4c4b..9f00235e9682 100644 --- a/src/metric-engine/src/engine/region_metadata.rs +++ b/src/metric-engine/src/engine/region_metadata.rs @@ -14,7 +14,7 @@ //! Implementation of retrieving logical region's region metadata. -use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::collections::HashMap; use store_api::metadata::ColumnMetadata; use store_api::storage::RegionId; @@ -65,42 +65,14 @@ impl MetricEngineInner { .cloned() .unwrap_or_default() .into_iter(); - - let merged_columns = logical_column_metadata - .clone() + let mut dedup_columns = logical_column_metadata .into_iter() - .chain(existing_columns.clone().into_iter()); - - let mut id2cnt: BTreeMap> = BTreeMap::new(); - - let mut dedup_columns = merged_columns - .map(|c| { - id2cnt - .entry(c.column_id) - .and_modify(|e| { - e.insert(c.clone()); - }) - .or_insert(BTreeSet::from([c.clone()])); - (c.column_id, c) - }) + .chain(existing_columns) + .map(|c| (c.column_id, c)) .collect::>() .values() .cloned() .collect::>(); - - let non_eq_columns_with_same_id = id2cnt - .into_iter() - .filter(|(_, v)| v.len() > 1) - .collect::>(); - - if !non_eq_columns_with_same_id.is_empty() { - panic!( - "Found {} duplicated column ids: {:?}", - non_eq_columns_with_same_id.len(), - non_eq_columns_with_same_id - ); - } - // Sort columns on column name to ensure the order dedup_columns.sort_unstable_by(|c1, c2| c1.column_schema.name.cmp(&c2.column_schema.name)); mutable_state.set_logical_columns(logical_region_id, dedup_columns.clone()); diff --git a/src/query/src/datafusion.rs b/src/query/src/datafusion.rs index 8eea0688777b..f295a2c9b3bb 100644 --- a/src/query/src/datafusion.rs +++ b/src/query/src/datafusion.rs @@ -18,7 +18,7 @@ mod error; mod planner; use std::any::Any; -use std::collections::{BTreeSet, HashMap}; +use std::collections::HashMap; use std::sync::Arc; use async_trait::async_trait; @@ -35,7 +35,6 @@ use common_telemetry::tracing; use datafusion::physical_plan::analyze::AnalyzeExec; use datafusion::physical_plan::coalesce_partitions::CoalescePartitionsExec; use datafusion::physical_plan::ExecutionPlan; -use datafusion_common::tree_node::{TreeNode, TreeNodeRecursion, TreeNodeVisitor}; use datafusion_common::ResolvedTableReference; use datafusion_expr::{DmlStatement, LogicalPlan as DfLogicalPlan, LogicalPlan, WriteOp}; use datatypes::prelude::VectorRef; @@ -290,45 +289,6 @@ impl DatafusionQueryEngine { { analyzed_plan.clone() } else { - struct TableSourceSchema {} - impl TreeNodeVisitor<'_> for TableSourceSchema { - type Node = LogicalPlan; - fn f_down( - &mut self, - node: &Self::Node, - ) -> datafusion_common::Result - { - if let LogicalPlan::TableScan(table_scan) = node { - let schema = table_scan.source.schema(); - - // found field in outer schema but not in inner schema - let outer_fields: BTreeSet<_> = - table_scan.projected_schema.fields().into_iter().collect(); - let inner_fields = schema.fields().iter().collect::>(); - - let diff = outer_fields - .difference(&inner_fields) - .collect::>(); - if !diff.is_empty() { - common_telemetry::error!("TableScan.source.schema: {:?}", &schema); - common_telemetry::error!( - "Projected==table_source?: {:?}", - schema.as_ref() == table_scan.projected_schema.as_arrow() - ); - common_telemetry::error!("logical - phy: {:?}", diff); - common_telemetry::error!( - "phy - logical: {:?}", - inner_fields - .difference(&outer_fields) - .collect::>() - ); - } - } - Ok(TreeNodeRecursion::Continue) - } - } - let mut table_source_schema = TableSourceSchema {}; - analyzed_plan.visit(&mut table_source_schema).unwrap(); state .optimizer() .optimize(analyzed_plan, state, |_, _| {}) diff --git a/src/store-api/src/metadata.rs b/src/store-api/src/metadata.rs index 38dd27e63a6b..3a06b111d8f6 100644 --- a/src/store-api/src/metadata.rs +++ b/src/store-api/src/metadata.rs @@ -40,7 +40,7 @@ use crate::storage::{ColumnId, RegionId}; pub type Result = std::result::Result; /// Metadata of a column. -#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct ColumnMetadata { /// Schema of this column. Is the same as `column_schema` in [SchemaRef]. pub column_schema: ColumnSchema,