Skip to content

Commit

Permalink
clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Feb 24, 2024
1 parent e2b368a commit e8acd9d
Show file tree
Hide file tree
Showing 49 changed files with 180 additions and 85 deletions.
2 changes: 1 addition & 1 deletion vegafusion-common/src/data/json_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ fn set_column_for_json_rows(
let inner_objs = struct_array_to_jsonmap_array(as_struct_array(array), row_count)?;
rows.iter_mut()
.take(row_count)
.zip(inner_objs.into_iter())
.zip(inner_objs)
.for_each(|(row, obj)| {
row.insert(col_name.to_string(), Value::Object(obj));
});
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-common/src/data/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl ArrayRefHelpers for ArrayRef {
/// Convert ArrayRef into vector of ScalarValues
fn to_scalar_vec(&self) -> std::result::Result<Vec<ScalarValue>, DataFusionError> {
(0..self.len())
.map(|i| Ok(ScalarValue::try_from_array(self, i)?))
.map(|i| ScalarValue::try_from_array(self, i))
.collect::<std::result::Result<Vec<_>, DataFusionError>>()
}

Expand Down
6 changes: 3 additions & 3 deletions vegafusion-common/src/data/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl VegaFusionTable {

pub fn to_record_batch(&self) -> Result<RecordBatch> {
let mut schema = self.schema.clone();
if let Some(batch) = self.batches.get(0) {
if let Some(batch) = self.batches.first() {
schema = batch.schema()
}
concat_batches(&schema, &self.batches)
Expand Down Expand Up @@ -205,7 +205,7 @@ impl VegaFusionTable {
if let serde_json::Value::Array(values) = value {
// Handle special case where array elements are non-object scalars
let mut values = Cow::Borrowed(values);
if let Some(first) = values.get(0) {
if let Some(first) = values.first() {
if let Value::Object(props) = first {
// Handle odd special case where vega will interpret
// [{}, {}] as [{"datum": {}}, {"datum": {}}]
Expand Down Expand Up @@ -298,7 +298,7 @@ impl VegaFusionTable {
let batches_list = PyList::new(py, batch_objects);

// Convert table's schema into pyarrow schema
let schema = if let Some(batch) = self.batches.get(0) {
let schema = if let Some(batch) = self.batches.first() {
// Get schema from first batch if present
batch.schema()
} else {
Expand Down
6 changes: 3 additions & 3 deletions vegafusion-core/src/expression/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ExpressionVisitor for GetInputVariablesVisitor {
/// Collect data and scale identifiers. These show up as a literal string as the first
/// argument to a Data or Scale callable.
fn visit_called_identifier(&mut self, node: &Identifier, args: &[Expression]) {
if let Some(arg0) = args.get(0) {
if let Some(arg0) = args.first() {
if let Ok(arg0) = arg0.as_literal() {
if let Value::String(arg0) = arg0.value() {
// Check data callable
Expand Down Expand Up @@ -157,7 +157,7 @@ impl UpdateVariablesExprVisitor {
impl ExpressionVisitor for UpdateVariablesExprVisitor {
fn visit_called_identifier(&mut self, node: &Identifier, args: &[Expression]) {
if node.name == "modify" {
if let Some(arg0) = args.get(0) {
if let Some(arg0) = args.first() {
if let Ok(arg0) = arg0.as_literal() {
if let Value::String(arg0) = arg0.value() {
// First arg is a string, which holds the name of the output dataset
Expand Down Expand Up @@ -372,7 +372,7 @@ impl<'a> ExpressionVisitor for DatasetsColumnUsageVisitor<'a> {
..
})),
..
}) = node.arguments.get(0)
}) = node.arguments.first()
{
// Resolve data variable
let reference_data_var = Variable::new_data(reference_data_name);
Expand Down
12 changes: 5 additions & 7 deletions vegafusion-core/src/planning/lift_facet_aggregations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ExtractFacetAggregationsVisitor {
}

fn num_children_of_dataset(&self, name: &str, scope: &[u32]) -> usize {
let facet_dataset_var: ScopedVariable = (Variable::new_data(&name), Vec::from(scope));
let facet_dataset_var: ScopedVariable = (Variable::new_data(name), Vec::from(scope));
let Some(facet_dataset_idx) = self.node_indexes.get(&facet_dataset_var) else {
return 0;
};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl MutChartVisitor for ExtractFacetAggregationsVisitor {
let mut lifted_transforms: Vec<TransformSpec> = Vec::new();

let agg = loop {
match child_dataset.transform.get(0).cloned() {
match child_dataset.transform.first().cloned() {
None => {
// End of transforms for this dataset, advance to child dataset if possible
if self.num_children_of_dataset(&child_dataset.name, scope) != 1 {
Expand Down Expand Up @@ -235,11 +235,9 @@ impl MutChartVisitor for ExtractFacetAggregationsVisitor {

// Add lifted aggregate transform, potentially after the joinaggregate transform
lifted_transforms.push(TransformSpec::Aggregate(agg));
} else {
if lifted_transforms.is_empty() {
// No supported transforms found
return Ok(());
}
} else if lifted_transforms.is_empty() {
// No supported transforms found
return Ok(());
}

// Create facet dataset name and increment counter to keep names unique even if the same
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/planning/projection_pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ impl<'a> MutChartVisitor for InsertProjectionVisitor<'a> {
// so we can append a projection transform to limit the columns that are produced
// Note: empty strings here seem to break vega, filter them out
let proj_fields: Vec<_> = sorted(columns)
.filter(|&f| !f.is_empty())
.cloned()
.filter(|f| !f.is_empty())
.map(|f| escape_field(&f))
.collect();

Expand Down
4 changes: 2 additions & 2 deletions vegafusion-core/src/planning/stringify_local_datetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn stringify_local_datetimes(
let server_to_client_datasets: HashSet<_> = comm_plan
.server_to_client
.iter()
.filter(|&var| var.0.namespace == VariableNamespace::Data as i32)
.cloned()
.filter(|var| var.0.namespace == VariableNamespace::Data as i32)
.collect();

let mut visitor = CollectCandidateDatasetMapping::new(
Expand Down Expand Up @@ -407,7 +407,7 @@ impl<'a> MutChartVisitor for StringifyLocalDatetimeFieldsVisitor<'a> {
let source_resolved_var = (source_resolved.var, source_resolved.scope);
if let Some(fields) = self.local_datetime_fields.get(&source_resolved_var) {
for field in sorted(fields) {
let field = unescape_field(&field);
let field = unescape_field(field);
let expr_str = format!("toDate(datum['{field}'], 'local')");
let transforms = &mut data.transform;
let transform = FormulaTransformSpec {
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/spec/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl DataSpec {
} else if self.url.is_some() {
DependencyNodeSupported::PartiallySupported
} else {
match self.transform.get(0) {
match self.transform.first() {
Some(tx) if tx.supported_and_allowed(planner_config, task_scope, scope) => {
DependencyNodeSupported::PartiallySupported
}
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/spec/transform/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl TransformSpecTrait for BinTransformSpec {
let bin_start = self
.as_
.as_ref()
.and_then(|as_| as_.get(0).cloned())
.and_then(|as_| as_.first().cloned())
.unwrap_or_else(|| "bin0".to_string());
let bin_end = self
.as_
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/spec/transform/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl FoldTransformSpec {
pub fn as_(&self) -> Vec<String> {
let as_ = self.as_.clone().unwrap_or_default();
vec![
as_.get(0).cloned().unwrap_or_else(|| "key".to_string()),
as_.first().cloned().unwrap_or_else(|| "key".to_string()),
as_.get(1).cloned().unwrap_or_else(|| "value".to_string()),
]
}
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/spec/transform/pivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TransformSpecTrait for PivotTransformSpec {
.unwrap_or_default()
.iter()
.filter_map(|groupby_field| {
let unescaped = unescape_field(&groupby_field);
let unescaped = unescape_field(groupby_field);
if input_local_datetime_columns.contains(&unescaped) {
Some(unescaped)
} else {
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/spec/transform/timeunit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TimeUnitTransformSpec {
let as0 = self
.as_
.clone()
.and_then(|as_| as_.get(0).cloned())
.and_then(|as_| as_.first().cloned())
.unwrap_or_else(|| "unit0".to_string());
let as1 = self
.as_
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/transform/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Bin {
Ok(Self {
field,
extent: Some(extent_expr),
alias_0: as_.get(0).cloned(),
alias_0: as_.first().cloned(),
alias_1: as_.get(1).cloned(),
anchor: config.anchor,
maxbins: config.maxbins,
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/transform/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Stack {
// Extract aliases
let alias0 = spec
.as_()
.get(0)
.first()
.cloned()
.unwrap_or_else(|| "y0".to_string());
let alias1 = spec
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-core/src/transform/timeunit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl TimeUnit {
.collect();
let signal = transform.signal.clone();

let alias_0 = transform.as_.as_ref().and_then(|v| v.get(0).cloned());
let alias_0 = transform.as_.as_ref().and_then(|v| v.first().cloned());
let alias_1 = transform.as_.as_ref().and_then(|v| v.get(1).cloned());

let timezone = match &transform.timezone {
Expand Down
2 changes: 1 addition & 1 deletion vegafusion-dataframe/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub trait DataFrame: Send + Sync + 'static {
async fn collect_flat(&self) -> Result<RecordBatch> {
let mut arrow_schema = Arc::new(self.schema()) as SchemaRef;
let table = self.collect().await?;
if let Some(batch) = table.batches.get(0) {
if let Some(batch) = table.batches.first() {
arrow_schema = batch.schema()
}
concat_batches(&arrow_schema, table.batches.as_slice())
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/array/indexof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub struct IndexOfUDF {
signature: Signature,
}

impl Default for IndexOfUDF {
fn default() -> Self {
Self::new()
}
}

impl IndexOfUDF {
pub fn new() -> Self {
let signature = Signature::any(2, Volatility::Immutable);
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/array/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct SpanUDF {
signature: Signature,
}

impl Default for SpanUDF {
fn default() -> Self {
Self::new()
}
}

impl SpanUDF {
pub fn new() -> Self {
let signature = Signature::uniform(
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/datetime/date_add_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub struct DateAddTzUDF {
signature: Signature,
}

impl Default for DateAddTzUDF {
fn default() -> Self {
Self::new()
}
}

impl DateAddTzUDF {
pub fn new() -> Self {
let signature = Signature::one_of(
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/datetime/date_part_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub struct DatePartTzUDF {
signature: Signature,
}

impl Default for DatePartTzUDF {
fn default() -> Self {
Self::new()
}
}

impl DatePartTzUDF {
pub fn new() -> Self {
let signature = Signature::one_of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct DateToUtcTimestampUDF {
signature: Signature,
}

impl Default for DateToUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl DateToUtcTimestampUDF {
pub fn new() -> Self {
let signature = Signature::exact(
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/datetime/date_trunc_tz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub struct DateTruncTzUDF {
signature: Signature,
}

impl Default for DateTruncTzUDF {
fn default() -> Self {
Self::new()
}
}

impl DateTruncTzUDF {
pub fn new() -> Self {
let signature = Signature::one_of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ pub struct EpochMsToUtcTimestampUDF {
signature: Signature,
}

impl Default for EpochMsToUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl EpochMsToUtcTimestampUDF {
pub fn new() -> Self {
let signature = Signature::exact(vec![DataType::Int64], Volatility::Immutable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ pub struct FormatTimestampUDF {
signature: Signature,
}

impl Default for FormatTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl FormatTimestampUDF {
pub fn new() -> Self {
let signature = Signature::one_of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub struct FromUtcTimestampUDF {
signature: Signature,
}

impl Default for FromUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl FromUtcTimestampUDF {
pub fn new() -> Self {
let signature = Signature::one_of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ pub struct MakeUtcTimestampUDF {
signature: Signature,
}

impl Default for MakeUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl MakeUtcTimestampUDF {
pub fn new() -> Self {
let signature = Signature::exact(
Expand Down
5 changes: 1 addition & 4 deletions vegafusion-datafusion-udfs/src/udfs/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub fn process_input_datetime(
let array: Int64Array = unary(array, |v| (v as i64) * ms_per_day);
Arc::new(array) as ArrayRef as _
}
DataType::Date64 => {
let int_array = cast(arg, &DataType::Int64).unwrap();
int_array
}
DataType::Date64 => (cast(arg, &DataType::Int64).unwrap()) as _,
DataType::Int64 => arg.clone(),
DataType::Float64 => cast(arg, &DataType::Int64).expect("Failed to cast float to int"),
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ pub struct StrToUtcTimestampUDF {
signature: Signature,
}

impl Default for StrToUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl StrToUtcTimestampUDF {
pub fn new() -> Self {
let signature =
Expand Down
6 changes: 6 additions & 0 deletions vegafusion-datafusion-udfs/src/udfs/datetime/timeunit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ pub struct TimeunitStartUDF {
signature: Signature,
}

impl Default for TimeunitStartUDF {
fn default() -> Self {
Self::new()
}
}

impl TimeunitStartUDF {
pub fn new() -> Self {
let make_sig = |timestamp_dtype: DataType| -> TypeSignature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ pub struct ToUtcTimestampUDF {
signature: Signature,
}

impl Default for ToUtcTimestampUDF {
fn default() -> Self {
Self::new()
}
}

impl ToUtcTimestampUDF {
pub fn new() -> Self {
// Signature should be (Timestamp, UTF8), but specifying Timestamp in the signature
Expand Down
Loading

0 comments on commit e8acd9d

Please sign in to comment.