Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/polyglot-sql/src/dialects/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4305,14 +4305,14 @@ impl Dialect {
if let Expression::Count(ref c) = e {
// Build COUNT_BIG(...) as an AggregateFunction
let args = if c.star {
vec![Expression::Star(crate::expressions::Star {
vec![Expression::Star(Box::new(crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})]
}))]
} else if let Some(ref this) = c.this {
vec![this.clone()]
} else {
Expand Down Expand Up @@ -9799,14 +9799,14 @@ impl Dialect {
}));

// Outer: SELECT ARRAY_AGG(*) FROM (inner_subquery)
let star = Expression::Star(Star {
let star = Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: vec![],
span: None,
});
}));
let array_agg = Expression::ArrayAgg(Box::new(AggFunc {
this: star,
distinct: false,
Expand Down
57 changes: 31 additions & 26 deletions crates/polyglot-sql/src/dialects/normalization/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,15 @@ pub(super) fn normalize_root(expression: Expression, context: &NormalizationCont
inferred_type: None,
}));
let mut new_select = crate::expressions::Select::new();
new_select.expressions = vec![Expression::Star(crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})];
new_select.expressions =
vec![Expression::Star(Box::new(crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
}))];
new_select.from = Some(crate::expressions::From {
expressions: vec![values_subquery],
});
Expand Down Expand Up @@ -476,14 +477,14 @@ pub(super) fn normalize_root(expression: Expression, context: &NormalizationCont
Expression::Values(Box::new(values))
};
let mut anchor = Select::new();
anchor.expressions = vec![Expression::Star(Star {
anchor.expressions = vec![Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})];
}))];
anchor.from = Some(From {
expressions: vec![source],
});
Expand Down Expand Up @@ -744,14 +745,16 @@ pub(super) fn rewrite(
new_ct.constraints.clear();
// Build: SELECT * FROM b LIMIT 0
let select = Expression::Select(Box::new(crate::expressions::Select {
expressions: vec![Expression::Star(crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})],
expressions: vec![Expression::Star(Box::new(
crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
},
))],
from: Some(crate::expressions::From {
expressions: vec![Expression::Table(Box::new(source_table))],
}),
Expand Down Expand Up @@ -789,14 +792,16 @@ pub(super) fn rewrite(
aliased_source.alias = Some(Identifier::new("temp"));
// Build: SELECT TOP 0 * INTO a FROM b AS temp
let select = Expression::Select(Box::new(crate::expressions::Select {
expressions: vec![Expression::Star(crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})],
expressions: vec![Expression::Star(Box::new(
crate::expressions::Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
},
))],
from: Some(crate::expressions::From {
expressions: vec![Expression::Table(Box::new(aliased_source))],
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/polyglot-sql/src/dialects/tsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,14 +1603,14 @@ impl TSQLDialect {
let predicate = Self::rewrite_column_qualifier(predicate, &outer_alias, &inner_alias)?;

let mut select = Select::new();
select.expressions = vec![Expression::Star(Star {
select.expressions = vec![Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})];
}))];
select.from = Some(crate::expressions::From {
expressions: vec![source],
});
Expand Down
6 changes: 3 additions & 3 deletions crates/polyglot-sql/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub enum Expression {
Identifier(Identifier),
Column(Box<Column>),
Table(Box<TableRef>),
Star(Star),
Star(Box<Star>),
/// Snowflake braced wildcard syntax: {*}, {tbl.*}, {* EXCLUDE (...)}, {* ILIKE '...'}
BracedWildcard(Box<Expression>),

Expand Down Expand Up @@ -1829,14 +1829,14 @@ impl Expression {

/// Create a wildcard star (`*`) expression with no EXCEPT/REPLACE/RENAME modifiers.
pub fn star() -> Self {
Expression::Star(Star {
Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})
}))
}

/// Wrap this expression in an `AS` alias (e.g. `expr AS name`).
Expand Down
8 changes: 4 additions & 4 deletions crates/polyglot-sql/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5190,7 +5190,7 @@ impl Generator {
};

// Build the outer select: SELECT * EXCLUDE (cols) FROM (inner)
let star = Expression::Star(crate::expressions::Star {
let star = Expression::Star(Box::new(crate::expressions::Star {
table: None,
except: Some(
exclude
Expand All @@ -5206,7 +5206,7 @@ impl Generator {
rename: None,
trailing_comments: Vec::new(),
span: None,
});
}));

let outer_select = Select {
vertica: None,
Expand Down Expand Up @@ -7661,14 +7661,14 @@ impl Generator {
let (limit, fetch) = split_set_limit(limit);
let mut outer_select = Select {
vertica: None,
expressions: vec![Expression::Star(Star {
expressions: vec![Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})],
}))],
from: Some(From {
expressions: vec![Expression::Subquery(Box::new(subquery))],
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/polyglot-sql/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,14 +1614,14 @@ fn to_node_inner(

let mut child = LineageNode::new(
format!("{}.*", name),
Expression::Star(crate::expressions::Star {
Expression::Star(Box::new(crate::expressions::Star {
table: star.table.clone(),
except: None,
replace: None,
rename: None,
trailing_comments: vec![],
span: None,
}),
})),
source_info.expression.as_ref().clone(),
);
apply_source_info_context(&mut child, name, source_info);
Expand Down
4 changes: 2 additions & 2 deletions crates/polyglot-sql/src/optimizer/isolate_table_selects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ fn maybe_wrap_table(expression: Expression, schema: Option<&dyn Schema>) -> Expr
fn wrap_table_in_subquery(table: TableRef, alias_name: &str) -> Expression {
// Build: SELECT * FROM <table>
let inner_select = Select::new()
.column(Expression::Star(Star {
.column(Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
}))
})))
.from(Expression::Table(Box::new(table)));

// Wrap the SELECT in a Subquery with the original alias
Expand Down
15 changes: 9 additions & 6 deletions crates/polyglot-sql/src/optimizer/qualify_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,28 +572,31 @@ fn is_passthrough_star_select(select: &Select) -> bool {
}

fn is_plain_star(expression: &Expression) -> bool {
let Expression::Star(star) = expression else {
return false;
};
matches!(
expression,
Expression::Star(Star {
**star,
Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments,
ref trailing_comments,
span: None,
}) if trailing_comments.is_empty()
} if trailing_comments.is_empty()
)
}

fn plain_star_expression() -> Expression {
Expression::Star(Star {
Expression::Star(Box::new(Star {
table: None,
except: None,
replace: None,
rename: None,
trailing_comments: Vec::new(),
span: None,
})
}))
}

fn is_plain_unaliased_subquery(subquery: &Subquery) -> bool {
Expand Down
Loading
Loading