Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Blizzara committed Jul 17, 2024
1 parent b8f45bb commit f188667
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
19 changes: 6 additions & 13 deletions datafusion/substrait/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@ use substrait::proto::extensions::simple_extension_declaration::{
};
use substrait::proto::extensions::SimpleExtensionDeclaration;

#[derive(Default)]
pub struct Extensions {
pub functions: HashMap<u32, String>,
pub types: HashMap<u32, String>,
pub type_variations: HashMap<u32, String>,
}

impl Extensions {
pub fn new() -> Self {
Self {
functions: HashMap::new(),
types: HashMap::new(),
type_variations: HashMap::new(),
}
}

pub fn register_function(&mut self, function_name: String) -> u32 {
let function_name = function_name.to_lowercase();

Expand Down Expand Up @@ -107,10 +100,10 @@ impl TryFrom<&Vec<SimpleExtensionDeclaration>> for Extensions {
}
}

impl Into<Vec<SimpleExtensionDeclaration>> for Extensions {
fn into(self) -> Vec<SimpleExtensionDeclaration> {
impl From<Extensions> for Vec<SimpleExtensionDeclaration> {
fn from(val: Extensions) -> Vec<SimpleExtensionDeclaration> {
let mut extensions = vec![];
for (f_anchor, f_name) in self.functions {
for (f_anchor, f_name) in val.functions {
let function_extension = ExtensionFunction {
extension_uri_reference: u32::MAX,
function_anchor: f_anchor,
Expand All @@ -122,7 +115,7 @@ impl Into<Vec<SimpleExtensionDeclaration>> for Extensions {
extensions.push(simple_extension);
}

for (t_anchor, t_name) in self.types {
for (t_anchor, t_name) in val.types {
let type_extension = ExtensionType {
extension_uri_reference: u32::MAX, // We don't register proper extension URIs yet
type_anchor: t_anchor,
Expand All @@ -134,7 +127,7 @@ impl Into<Vec<SimpleExtensionDeclaration>> for Extensions {
extensions.push(simple_extension);
}

for (tv_anchor, tv_name) in self.type_variations {
for (tv_anchor, tv_name) in val.type_variations {
let type_variation_extension = ExtensionTypeVariation {
extension_uri_reference: u32::MAX, // We don't register proper extension URIs yet
type_variation_anchor: tv_anchor,
Expand Down
16 changes: 11 additions & 5 deletions datafusion/substrait/src/logical_plan/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ use crate::variation_const::{
DATE_32_TYPE_VARIATION_REF, DATE_64_TYPE_VARIATION_REF,
DECIMAL_128_TYPE_VARIATION_REF, DECIMAL_256_TYPE_VARIATION_REF,
DEFAULT_CONTAINER_TYPE_VARIATION_REF, DEFAULT_TYPE_VARIATION_REF,
INTERVAL_DAY_TIME_TYPE_REF, INTERVAL_MONTH_DAY_NANO_TYPE_NAME,
INTERVAL_MONTH_DAY_NANO_TYPE_REF, INTERVAL_YEAR_MONTH_TYPE_REF,
LARGE_CONTAINER_TYPE_VARIATION_REF, TIMESTAMP_MICRO_TYPE_VARIATION_REF,
TIMESTAMP_MILLI_TYPE_VARIATION_REF, TIMESTAMP_NANO_TYPE_VARIATION_REF,
TIMESTAMP_SECOND_TYPE_VARIATION_REF, UNSIGNED_INTEGER_TYPE_VARIATION_REF,
INTERVAL_MONTH_DAY_NANO_TYPE_NAME, LARGE_CONTAINER_TYPE_VARIATION_REF,
TIMESTAMP_MICRO_TYPE_VARIATION_REF, TIMESTAMP_MILLI_TYPE_VARIATION_REF,
TIMESTAMP_NANO_TYPE_VARIATION_REF, TIMESTAMP_SECOND_TYPE_VARIATION_REF,
UNSIGNED_INTEGER_TYPE_VARIATION_REF,
};
#[allow(deprecated)]
use crate::variation_const::{
INTERVAL_DAY_TIME_TYPE_REF, INTERVAL_MONTH_DAY_NANO_TYPE_REF,
INTERVAL_YEAR_MONTH_TYPE_REF,
};
use datafusion::common::scalar::ScalarStructBuilder;
use datafusion::logical_expr::expr::InList;
Expand Down Expand Up @@ -1500,6 +1504,7 @@ fn from_substrait_type(
}
} else {
// Kept for backwards compatibility, new plans should include the extension instead
#[allow(deprecated)]
match u.type_reference {
// Kept for backwards compatibility, use IntervalYear instead
INTERVAL_YEAR_MONTH_TYPE_REF => {
Expand Down Expand Up @@ -1848,6 +1853,7 @@ fn from_substrait_literal(
}
} else {
// Kept for backwards compatibility - new plans should include extension instead
#[allow(deprecated)]
match user_defined.type_reference {
// Kept for backwards compatibility, use IntervalYearToMonth instead
INTERVAL_YEAR_MONTH_TYPE_REF => {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/substrait/src/logical_plan/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use substrait::{

/// Convert DataFusion LogicalPlan to Substrait Plan
pub fn to_substrait_plan(plan: &LogicalPlan, ctx: &SessionContext) -> Result<Box<Plan>> {
let mut extensions = Extensions::new();
let mut extensions = Extensions::default();
// Parse relation nodes
// Generate PlanRel(s)
// Note: Only 1 relation tree is currently supported
Expand Down

0 comments on commit f188667

Please sign in to comment.