Skip to content

Commit

Permalink
Rename FieldSpec members to make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mwylde committed Oct 31, 2024
1 parent a0bff68 commit 5a326b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions crates/arroyo-planner/src/extension/table_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ impl TableSourceExtension {
.fields
.iter()
.filter_map(|field| match field {
FieldSpec::StructField(field) | FieldSpec::MetadataField { field, .. } => {
FieldSpec::Struct(field) | FieldSpec::Metadata { field, .. } => {
Some((Some(name.clone()), Arc::new(field.clone())).into())
}
FieldSpec::VirtualField { .. } => None,
FieldSpec::Virtual { .. } => None,
})
.collect::<Vec<_>>();
let base_schema = Arc::new(schema_from_df_fields(&physical_fields).unwrap());
Expand Down
14 changes: 6 additions & 8 deletions crates/arroyo-planner/src/rewriters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ impl<'a> SourceRewriter<'a> {
.find_map(|f| {
if f.field().name() == &watermark_field {
return match f {
FieldSpec::StructField(field)
| FieldSpec::MetadataField { field, .. } => {
FieldSpec::Struct(field) | FieldSpec::Metadata { field, .. } => {
Some(Expr::Column(Column {
relation: None,
name: field.name().to_string(),
}))
}
FieldSpec::VirtualField { expression, .. } => Some(expression.clone()),
FieldSpec::Virtual { expression, .. } => Some(expression.clone()),
};
}
None
Expand Down Expand Up @@ -87,13 +86,13 @@ impl<'a> SourceRewriter<'a> {
.fields
.iter()
.map(|field| match field {
FieldSpec::StructField(field) | FieldSpec::MetadataField { field, .. } => {
FieldSpec::Struct(field) | FieldSpec::Metadata { field, .. } => {
Expr::Column(Column {
relation: Some(qualifier.clone()),
name: field.name().to_string(),
})
}
FieldSpec::VirtualField { field, expression } => expression
FieldSpec::Virtual { field, expression } => expression
.clone()
.alias_qualified(Some(qualifier.clone()), field.name().to_string()),
})
Expand All @@ -111,14 +110,13 @@ impl<'a> SourceRewriter<'a> {
.find_map(|f| {
if f.field().name() == &event_time_field {
return match f {
FieldSpec::StructField(field)
| FieldSpec::MetadataField { field, .. } => {
FieldSpec::Struct(field) | FieldSpec::Metadata { field, .. } => {
Some(Expr::Column(Column {
relation: Some(qualifier.clone()),
name: field.name().to_string(),
}))
}
FieldSpec::VirtualField { expression, .. } => Some(expression.clone()),
FieldSpec::Virtual { expression, .. } => Some(expression.clone()),
};
}
None
Expand Down
41 changes: 20 additions & 21 deletions crates/arroyo-planner/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,37 @@ pub struct ConnectorTable {

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum FieldSpec {
StructField(Field),
MetadataField { field: Field, key: String },
VirtualField { field: Field, expression: Expr },
Struct(Field),
Metadata { field: Field, key: String },
Virtual { field: Field, expression: Expr },
}

impl FieldSpec {
fn is_virtual(&self) -> bool {
match self {
FieldSpec::StructField(_) | FieldSpec::MetadataField { .. } => false,
FieldSpec::VirtualField { .. } => true,
FieldSpec::Struct(_) | FieldSpec::Metadata { .. } => false,
FieldSpec::Virtual { .. } => true,
}
}
pub fn field(&self) -> &Field {
match self {
FieldSpec::StructField(f) => f,
FieldSpec::MetadataField { field, .. } => field,
FieldSpec::VirtualField { field, .. } => field,
FieldSpec::Struct(f) => f,
FieldSpec::Metadata { field, .. } => field,
FieldSpec::Virtual { field, .. } => field,
}
}

fn metadata_key(&self) -> Option<&str> {
match &self {
FieldSpec::MetadataField { key, .. } => Some(key.as_str()),
FieldSpec::Metadata { key, .. } => Some(key.as_str()),
_ => None,
}
}
}

impl From<Field> for FieldSpec {
fn from(value: Field) -> Self {
FieldSpec::StructField(value)
FieldSpec::Struct(value)
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ impl From<Connection> for ConnectorTable {
.schema
.fields
.iter()
.map(|f| FieldSpec::StructField(f.clone().into()))
.map(|f| FieldSpec::Struct(f.clone().into()))
.collect(),
config: value.config,
description: value.description,
Expand Down Expand Up @@ -226,15 +226,15 @@ impl ConnectorTable {
fields = fields
.into_iter()
.map(|field_spec| match &field_spec {
FieldSpec::StructField(struct_field) => match struct_field.data_type() {
FieldSpec::Struct(struct_field) => match struct_field.data_type() {
DataType::Timestamp(_, None) => {
FieldSpec::StructField(struct_field.clone().with_data_type(
FieldSpec::Struct(struct_field.clone().with_data_type(
DataType::Timestamp(arrow_schema::TimeUnit::Microsecond, None),
))
}
_ => field_spec,
},
FieldSpec::MetadataField { .. } | FieldSpec::VirtualField { .. } => {
FieldSpec::Metadata { .. } | FieldSpec::Virtual { .. } => {
unreachable!("delta lake is only a sink, can't have virtual fields")
}
})
Expand All @@ -259,10 +259,9 @@ impl ConnectorTable {
let df_struct_type =
DataType::Struct(fields.iter().map(|f| f.field().clone()).collect());
let before_field_spec =
FieldSpec::StructField(Field::new("before", df_struct_type.clone(), true));
let after_field_spec =
FieldSpec::StructField(Field::new("after", df_struct_type, true));
let op_field_spec = FieldSpec::StructField(Field::new("op", DataType::Utf8, false));
FieldSpec::Struct(Field::new("before", df_struct_type.clone(), true));
let after_field_spec = FieldSpec::Struct(Field::new("after", df_struct_type, true));
let op_field_spec = FieldSpec::Struct(Field::new("op", DataType::Utf8, false));
input_to_schema_fields = vec![before_field_spec, after_field_spec, op_field_spec];
}

Expand Down Expand Up @@ -619,18 +618,18 @@ impl Table {
df_expr.visit(&mut metadata_finder)?;

if let Some(key) = metadata_finder.key {
Ok(FieldSpec::MetadataField {
Ok(FieldSpec::Metadata {
field: struct_field,
key,
})
} else {
Ok(FieldSpec::VirtualField {
Ok(FieldSpec::Virtual {
field: struct_field,
expression: df_expr,
})
}
} else {
Ok(FieldSpec::StructField(struct_field))
Ok(FieldSpec::Struct(struct_field))
}
})
.collect::<Result<Vec<_>>>()
Expand Down

0 comments on commit 5a326b3

Please sign in to comment.