Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
py committed Jan 14, 2025
1 parent d77f6c0 commit 05815c5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
13 changes: 5 additions & 8 deletions crates/query-engine/sql/src/sql/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn false_expr() -> Expression {
/// Generate a column expression refering to a specific table.
pub fn make_column(
table: TableReference,
name: ColumnName,
name: &ColumnName,
alias: ColumnAlias,
) -> (ColumnAlias, Expression) {
let name = ColumnName(format!("{}{}{}", "`", name.0, "`"));
Expand All @@ -74,7 +74,7 @@ pub fn make_column(
)
}
/// Create column aliases using this function so we build everything in one place.
pub fn make_column_alias(name: String) -> ColumnAlias {
pub fn make_column_alias(name: &str) -> ColumnAlias {
let name = format!("{}{}{}", "`", name, "`");
ColumnAlias { name }
}
Expand Down Expand Up @@ -487,7 +487,7 @@ pub fn select_rowset_with_variables(
elements: vec![OrderByElement {
target: Expression::ColumnReference(ColumnReference::AliasedColumn {
table: variables_table_reference,
column: make_column_alias(VARIABLE_ORDER_FIELD.to_string()),
column: make_column_alias(VARIABLE_ORDER_FIELD),
}),
direction: OrderByDirection::Asc,
}],
Expand Down Expand Up @@ -759,11 +759,8 @@ pub fn select_row_as_json_with_default(
pub fn from_variables(alias: TableAlias) -> From {
let expression = Expression::Value(Value::Variable(VARIABLES_OBJECT_PLACEHOLDER.to_string()));
let columns: Vec<(ColumnAlias, ScalarType)> = vec![
(
make_column_alias(VARIABLE_ORDER_FIELD.to_string()),
int4_type(),
),
(make_column_alias(VARIABLES_FIELD.to_string()), jsonb_type()),
(make_column_alias(VARIABLE_ORDER_FIELD), int4_type()),
(make_column_alias(VARIABLES_FIELD), jsonb_type()),
];

From::JsonbToRecordset {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn translate(
distinct,
field_path: _,
} => {
let count_column_alias = sql::helpers::make_column_alias(column.to_string());
let count_column_alias = sql::helpers::make_column_alias(&column.to_string());
if *distinct {
sql::ast::Expression::Count(sql::ast::CountType::Distinct(
sql::ast::ColumnReference::AliasedColumn {
Expand All @@ -47,7 +47,7 @@ pub fn translate(
args: vec![sql::ast::Expression::ColumnReference(
sql::ast::ColumnReference::AliasedColumn {
table: table.clone(),
column: sql::helpers::make_column_alias(column.to_string()),
column: sql::helpers::make_column_alias(&column.to_string()),
},
)],
},
Expand All @@ -56,7 +56,7 @@ pub fn translate(
}
};
Ok((
sql::helpers::make_column_alias(alias.to_string()),
sql::helpers::make_column_alias(&alias.to_string()),
expression,
))
})
Expand Down
11 changes: 4 additions & 7 deletions crates/query-engine/translation/src/translation/query/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) fn translate_fields(
env,
current_table,
&column,
sql::helpers::make_column_alias(alias.to_string()),
sql::helpers::make_column_alias(&alias.to_string()),
&fields_info,
),
models::Field::Column {
Expand All @@ -54,7 +54,7 @@ pub(crate) fn translate_fields(
arguments,
} => {
let table_alias = state.make_relationship_table_alias(alias.as_str());
let column_alias = sql::helpers::make_column_alias(alias.to_string());
let column_alias = sql::helpers::make_column_alias(&alias.to_string());
let column_name = sql::ast::ColumnReference::AliasedColumn {
table: sql::ast::TableReference::AliasedTable(table_alias.clone()),
column: column_alias.clone(),
Expand Down Expand Up @@ -184,11 +184,8 @@ fn uppack_and_wrap_fields_scalar_type(
) -> Result<(sql::ast::ColumnAlias, sql::ast::Expression), Error> {
let column_info = fields_info.lookup_column(column)?;
let column_type_representation = env.lookup_type_representation(scalar_type);
let (final_alias, expression) = sql::helpers::make_column(
current_table.reference.clone(),
column_info.name.clone(),
alias,
);
let (final_alias, expression) =
sql::helpers::make_column(current_table.reference.clone(), &column_info.name, alias);
Ok((
final_alias,
wrap_in_type_representation(expression, column_type_representation),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ pub fn translate_exists_in_collection(
root::make_from_clause_and_reference(&collection, &arguments, env, state, None)?;

// CockroachDB doesn't like empty selects, so we do "SELECT 1 as 'one' ..."
let column_alias = sql::helpers::make_column_alias("one".to_string());
let column_alias = sql::helpers::make_column_alias("one");

let select_cols = vec![(
column_alias,
Expand Down Expand Up @@ -590,7 +590,7 @@ pub fn translate_exists_in_collection(
)?;

// CockroachDB doesn't like empty selects, so we do "SELECT 1 as 'one' ..."
let column_alias = sql::helpers::make_column_alias("one".to_string());
let column_alias = sql::helpers::make_column_alias("one");

let select_cols = vec![(
column_alias,
Expand Down Expand Up @@ -730,13 +730,13 @@ fn make_unnest_subquery(
let subquery_reference = sql::ast::TableReference::AliasedTable(subquery_alias.clone());
let subquery_from = sql::ast::From::Unnest {
expression,
column: sql::helpers::make_column_alias("value".to_string()),
column: sql::helpers::make_column_alias("value"),
alias: subquery_alias,
};
let mut subquery = sql::helpers::simple_select(vec![sql::helpers::make_column(
subquery_reference,
sql::ast::ColumnName("value".to_string()),
sql::helpers::make_column_alias("value".to_string()),
&sql::ast::ColumnName("value".to_string()),
sql::helpers::make_column_alias("value"),
)]);
subquery.from = Some(subquery_from);
sql::ast::Expression::CorrelatedSubSelect(Box::new(subquery))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn translate(
let json_select = sql::helpers::select_rowset(
(
state.make_table_alias("universe".to_string()),
sql::helpers::make_column_alias("universe".to_string()),
sql::helpers::make_column_alias("universe"),
),
(
state.make_table_alias("rows".to_string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ fn process_path_element_for_order_by_targets(
let selected_column = collection.lookup_column(source_col)?;
// we are going to deliberately use the table column name and not an alias we get from
// the query request because this is internal to the sorting mechanism.
let selected_column_alias = sql::helpers::make_column_alias(selected_column.name.0);
let selected_column_alias =
sql::helpers::make_column_alias(&selected_column.name.0);
// we use the real name of the column as an alias as well.
Ok(OrderByRelationshipColumn {
alias: selected_column_alias.clone(),
Expand Down Expand Up @@ -662,7 +663,7 @@ fn translate_targets(
// we are going to deliberately use the table column name and not an alias we get from
// the query request because this is internal to the sorting mechanism.
let selected_column_alias =
sql::helpers::make_column_alias(selected_column.name.0);
sql::helpers::make_column_alias(&selected_column.name.0);

// we use the real name of the column as an alias as well.
Ok::<OrderBySelectExpression, Error>(OrderBySelectExpression {
Expand All @@ -689,7 +690,7 @@ fn translate_targets(
.map(|element| {
match &element.element {
Aggregate::CountStarAggregate => {
let column_alias = sql::helpers::make_column_alias("count".to_string());
let column_alias = sql::helpers::make_column_alias("count");
Ok(OrderBySelectExpression {
index: element.index,
direction: element.direction,
Expand All @@ -705,7 +706,7 @@ fn translate_targets(
// we are going to deliberately use the table column name and not an alias we get from
// the query request because this is internal to the sorting mechanism.
let selected_column_alias =
sql::helpers::make_column_alias(selected_column.name.0);
sql::helpers::make_column_alias(&selected_column.name.0);
// we use the real name of the column as an alias as well.
Ok(OrderBySelectExpression {
index: element.index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn translate_variable(
) -> Result<sql::ast::Expression, Error> {
let variables_reference = Expression::ColumnReference(ColumnReference::AliasedColumn {
table: variables_table,
column: sql::helpers::make_column_alias(sql::helpers::VARIABLES_FIELD.to_string()),
column: sql::helpers::make_column_alias(sql::helpers::VARIABLES_FIELD),
});

// We use the binop '->' to project (as jsonb) the value of a variable from the data column of
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn translate_projected_variable(
// ```
database::Type::ArrayType(type_name) => {
let array_table = state.make_table_alias("array".to_string());
let element_column = sql::helpers::make_column_alias("element".to_string());
let element_column = sql::helpers::make_column_alias("element");

let from_arr = sql::ast::From::JsonbArrayElements {
expression: exp,
Expand Down

0 comments on commit 05815c5

Please sign in to comment.