@@ -195,6 +195,9 @@ const EOF_TOKEN: TokenWithSpan = TokenWithSpan {
195195 },
196196};
197197
198+ // Error message constant for pipe operators that require DISTINCT
199+ const EXPECTED_FUNCTION_CALL_MSG: &str = "Expected function call after CALL";
200+
198201/// Composite types declarations using angle brackets syntax can be arbitrary
199202/// nested such that the following declaration is possible:
200203/// `ARRAY<ARRAY<INT>>`
@@ -9965,6 +9968,19 @@ impl<'a> Parser<'a> {
99659968 })
99669969 }
99679970
9971+ /// Parse set quantifier for pipe operators that require DISTINCT (INTERSECT, EXCEPT)
9972+ fn parse_distinct_required_set_quantifier(&mut self, operator_name: &str) -> Result<SetQuantifier, ParserError> {
9973+ if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
9974+ Ok(SetQuantifier::DistinctByName)
9975+ } else if self.parse_keyword(Keyword::DISTINCT) {
9976+ Ok(SetQuantifier::Distinct)
9977+ } else {
9978+ Err(ParserError::ParserError(
9979+ format!("{} pipe operator requires DISTINCT modifier", operator_name),
9980+ ))
9981+ }
9982+ }
9983+
99689984 /// Parse optional alias (with or without AS keyword) for pipe operators
99699985 fn parse_optional_pipe_alias(&mut self) -> Result<Option<Ident>, ParserError> {
99709986 if self.parse_keyword(Keyword::AS) {
@@ -11199,35 +11215,15 @@ impl<'a> Parser<'a> {
1119911215 });
1120011216 }
1120111217 Keyword::INTERSECT => {
11202- // BigQuery INTERSECT pipe operator requires DISTINCT modifier
11203- let set_quantifier =
11204- if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11205- SetQuantifier::DistinctByName
11206- } else if self.parse_keyword(Keyword::DISTINCT) {
11207- SetQuantifier::Distinct
11208- } else {
11209- return Err(ParserError::ParserError(
11210- "INTERSECT pipe operator requires DISTINCT modifier".to_string(),
11211- ));
11212- };
11218+ let set_quantifier = self.parse_distinct_required_set_quantifier("INTERSECT")?;
1121311219 let queries = self.parse_pipe_operator_queries()?;
1121411220 pipe_operators.push(PipeOperator::Intersect {
1121511221 set_quantifier,
1121611222 queries,
1121711223 });
1121811224 }
1121911225 Keyword::EXCEPT => {
11220- // BigQuery EXCEPT pipe operator requires DISTINCT modifier
11221- let set_quantifier =
11222- if self.parse_keywords(&[Keyword::DISTINCT, Keyword::BY, Keyword::NAME]) {
11223- SetQuantifier::DistinctByName
11224- } else if self.parse_keyword(Keyword::DISTINCT) {
11225- SetQuantifier::Distinct
11226- } else {
11227- return Err(ParserError::ParserError(
11228- "EXCEPT pipe operator requires DISTINCT modifier".to_string(),
11229- ));
11230- };
11226+ let set_quantifier = self.parse_distinct_required_set_quantifier("EXCEPT")?;
1123111227 let queries = self.parse_pipe_operator_queries()?;
1123211228 pipe_operators.push(PipeOperator::Except {
1123311229 set_quantifier,
@@ -11239,16 +11235,11 @@ impl<'a> Parser<'a> {
1123911235 let function_expr = self.parse_function(function_name)?;
1124011236 // Extract Function from Expr::Function
1124111237 if let Expr::Function(function) = function_expr {
11242- // Parse optional alias
11243- let alias = if self.parse_keyword(Keyword::AS) {
11244- Some(self.parse_identifier()?)
11245- } else {
11246- None
11247- };
11238+ let alias = self.parse_optional_pipe_alias()?;
1124811239 pipe_operators.push(PipeOperator::Call { function, alias });
1124911240 } else {
1125011241 return Err(ParserError::ParserError(
11251- "Expected function call after CALL" .to_string(),
11242+ EXPECTED_FUNCTION_CALL_MSG .to_string(),
1125211243 ));
1125311244 }
1125411245 }
0 commit comments