Skip to content

Commit

Permalink
chore: remove debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
discord9 committed Nov 18, 2024
1 parent 9b48867 commit 27c3cfc
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 98 deletions.
24 changes: 1 addition & 23 deletions src/datatypes/src/schema/column_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,28 +56,6 @@ pub struct ColumnSchema {
metadata: Metadata,
}

impl PartialOrd for ColumnSchema {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
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!(
Expand Down
2 changes: 1 addition & 1 deletion src/datatypes/src/schema/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 4 additions & 32 deletions src/metric-engine/src/engine/region_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<u32, BTreeSet<ColumnMetadata>> = 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::<HashMap<_, _>>()
.values()
.cloned()
.collect::<Vec<_>>();

let non_eq_columns_with_same_id = id2cnt
.into_iter()
.filter(|(_, v)| v.len() > 1)
.collect::<BTreeMap<_, _>>();

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());
Expand Down
42 changes: 1 addition & 41 deletions src/query/src/datafusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<datafusion_common::tree_node::TreeNodeRecursion>
{
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::<BTreeSet<_>>();

let diff = outer_fields
.difference(&inner_fields)
.collect::<BTreeSet<_>>();
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::<BTreeSet<_>>()
);
}
}
Ok(TreeNodeRecursion::Continue)
}
}
let mut table_source_schema = TableSourceSchema {};
analyzed_plan.visit(&mut table_source_schema).unwrap();
state
.optimizer()
.optimize(analyzed_plan, state, |_, _| {})
Expand Down
2 changes: 1 addition & 1 deletion src/store-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::storage::{ColumnId, RegionId};
pub type Result<T> = std::result::Result<T, MetadataError>;

/// 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,
Expand Down

0 comments on commit 27c3cfc

Please sign in to comment.