Skip to content

Commit 4478d6b

Browse files
committed
fmt
1 parent eaf7c8e commit 4478d6b

3 files changed

Lines changed: 209 additions & 139 deletions

File tree

src/ast/query.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,10 @@ pub enum PipeOperator {
27222722
/// Syntax: `|> CALL function_name(args) [AS alias]`
27232723
///
27242724
/// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#call_pipe_operator>
2725-
Call { function: Function, alias: Option<Ident> },
2725+
Call {
2726+
function: Function,
2727+
alias: Option<Ident>,
2728+
},
27262729
/// Pivots data from rows to columns.
27272730
///
27282731
/// Syntax: `|> PIVOT(aggregate_function(column) FOR pivot_column IN (value1, value2, ...)) [AS alias]`

src/parser/mod.rs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11157,7 +11157,8 @@ impl<'a> Parser<'a> {
1115711157
pipe_operators.push(PipeOperator::TableSample { sample });
1115811158
}
1115911159
Keyword::RENAME => {
11160-
let mappings = self.parse_comma_separated(Parser::parse_identifier_with_optional_alias)?;
11160+
let mappings =
11161+
self.parse_comma_separated(Parser::parse_identifier_with_optional_alias)?;
1116111162
pipe_operators.push(PipeOperator::Rename { mappings });
1116211163
}
1116311164
Keyword::UNION => {
@@ -11171,19 +11172,23 @@ impl<'a> Parser<'a> {
1117111172
parser.expect_token(&Token::RParen)?;
1117211173
Ok(query)
1117311174
})?;
11174-
pipe_operators.push(PipeOperator::Union { set_quantifier, queries });
11175+
pipe_operators.push(PipeOperator::Union {
11176+
set_quantifier,
11177+
queries,
11178+
});
1117511179
}
1117611180
Keyword::INTERSECT => {
1117711181
// BigQuery INTERSECT pipe operator requires DISTINCT modifier
11178-
let set_quantifier = if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11179-
SetQuantifier::DistinctByName
11180-
} else if self.parse_keyword(Keyword::DISTINCT) {
11181-
SetQuantifier::Distinct
11182-
} else {
11183-
return Err(ParserError::ParserError(
11184-
"INTERSECT pipe operator requires DISTINCT modifier".to_string()
11185-
));
11186-
};
11182+
let set_quantifier =
11183+
if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11184+
SetQuantifier::DistinctByName
11185+
} else if self.parse_keyword(Keyword::DISTINCT) {
11186+
SetQuantifier::Distinct
11187+
} else {
11188+
return Err(ParserError::ParserError(
11189+
"INTERSECT pipe operator requires DISTINCT modifier".to_string(),
11190+
));
11191+
};
1118711192
// BigQuery INTERSECT pipe operator requires parentheses around queries
1118811193
// Parse comma-separated list of parenthesized queries
1118911194
let queries = self.parse_comma_separated(|parser| {
@@ -11192,19 +11197,23 @@ impl<'a> Parser<'a> {
1119211197
parser.expect_token(&Token::RParen)?;
1119311198
Ok(query)
1119411199
})?;
11195-
pipe_operators.push(PipeOperator::Intersect { set_quantifier, queries });
11200+
pipe_operators.push(PipeOperator::Intersect {
11201+
set_quantifier,
11202+
queries,
11203+
});
1119611204
}
1119711205
Keyword::EXCEPT => {
1119811206
// BigQuery EXCEPT pipe operator requires DISTINCT modifier
11199-
let set_quantifier = if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11200-
SetQuantifier::DistinctByName
11201-
} else if self.parse_keyword(Keyword::DISTINCT) {
11202-
SetQuantifier::Distinct
11203-
} else {
11204-
return Err(ParserError::ParserError(
11205-
"EXCEPT pipe operator requires DISTINCT modifier".to_string()
11206-
));
11207-
};
11207+
let set_quantifier =
11208+
if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11209+
SetQuantifier::DistinctByName
11210+
} else if self.parse_keyword(Keyword::DISTINCT) {
11211+
SetQuantifier::Distinct
11212+
} else {
11213+
return Err(ParserError::ParserError(
11214+
"EXCEPT pipe operator requires DISTINCT modifier".to_string(),
11215+
));
11216+
};
1120811217
// BigQuery EXCEPT pipe operator requires parentheses around queries
1120911218
// Parse comma-separated list of parenthesized queries
1121011219
let queries = self.parse_comma_separated(|parser| {
@@ -11213,7 +11222,10 @@ impl<'a> Parser<'a> {
1121311222
parser.expect_token(&Token::RParen)?;
1121411223
Ok(query)
1121511224
})?;
11216-
pipe_operators.push(PipeOperator::Except { set_quantifier, queries });
11225+
pipe_operators.push(PipeOperator::Except {
11226+
set_quantifier,
11227+
queries,
11228+
});
1121711229
}
1121811230
Keyword::CALL => {
1121911231
let function_name = self.parse_object_name(false)?;
@@ -11229,13 +11241,14 @@ impl<'a> Parser<'a> {
1122911241
pipe_operators.push(PipeOperator::Call { function, alias });
1123011242
} else {
1123111243
return Err(ParserError::ParserError(
11232-
"Expected function call after CALL".to_string()
11244+
"Expected function call after CALL".to_string(),
1123311245
));
1123411246
}
1123511247
}
1123611248
Keyword::PIVOT => {
1123711249
self.expect_token(&Token::LParen)?;
11238-
let aggregate_functions = self.parse_comma_separated(Self::parse_aliased_function_call)?;
11250+
let aggregate_functions =
11251+
self.parse_comma_separated(Self::parse_aliased_function_call)?;
1123911252
self.expect_keyword_is(Keyword::FOR)?;
1124011253
let value_column = self.parse_period_separated(|p| p.parse_identifier())?;
1124111254
self.expect_keyword_is(Keyword::IN)?;
@@ -11251,7 +11264,9 @@ impl<'a> Parser<'a> {
1125111264
} else if self.peek_sub_query() {
1125211265
PivotValueSource::Subquery(self.parse_query()?)
1125311266
} else {
11254-
PivotValueSource::List(self.parse_comma_separated(Self::parse_expr_with_alias)?)
11267+
PivotValueSource::List(
11268+
self.parse_comma_separated(Self::parse_expr_with_alias)?,
11269+
)
1125511270
};
1125611271
self.expect_token(&Token::RParen)?;
1125711272
self.expect_token(&Token::RParen)?;
@@ -11281,24 +11296,24 @@ impl<'a> Parser<'a> {
1128111296
Keyword::UNPIVOT => {
1128211297
// Parse UNPIVOT(value_column FOR name_column IN (column1, column2, ...)) [alias]
1128311298
self.expect_token(&Token::LParen)?;
11284-
11299+
1128511300
// Parse value_column
1128611301
let value_column = self.parse_identifier()?;
11287-
11302+
1128811303
// Parse FOR keyword
1128911304
self.expect_keyword(Keyword::FOR)?;
11290-
11305+
1129111306
// Parse name_column
1129211307
let name_column = self.parse_identifier()?;
11293-
11308+
1129411309
// Parse IN keyword
1129511310
self.expect_keyword(Keyword::IN)?;
11296-
11311+
1129711312
// Parse (column1, column2, ...)
1129811313
self.expect_token(&Token::LParen)?;
1129911314
let unpivot_columns = self.parse_comma_separated(Parser::parse_identifier)?;
1130011315
self.expect_token(&Token::RParen)?;
11301-
11316+
1130211317
self.expect_token(&Token::RParen)?;
1130311318

1130411319
// Parse optional alias (with or without AS keyword)

0 commit comments

Comments
 (0)