#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
use crate::ast::{BinaryOperator, Expr};
use crate::dialect::Dialect;
use crate::keywords::Keyword;
use crate::parser::{Parser, ParserError};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SparkSqlDialect;
impl Dialect for SparkSqlDialect {
fn is_delimited_identifier_start(&self, ch: char) -> bool {
matches!(ch, '`')
}
fn is_identifier_start(&self, ch: char) -> bool {
matches!(ch, 'a'..='z' | 'A'..='Z' | '_')
}
fn is_identifier_part(&self, ch: char) -> bool {
matches!(ch, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_')
}
fn supports_filter_during_aggregation(&self) -> bool {
true
}
fn supports_group_by_expr(&self) -> bool {
true
}
fn supports_group_by_with_modifier(&self) -> bool {
true
}
fn supports_lambda_functions(&self) -> bool {
true
}
fn supports_select_wildcard_except(&self) -> bool {
true
}
fn supports_struct_literal(&self) -> bool {
true
}
fn supports_nested_comments(&self) -> bool {
true
}
fn supports_create_table_using(&self) -> bool {
true
}
fn supports_long_type_as_bigint(&self) -> bool {
true
}
fn supports_values_as_table_factor(&self) -> bool {
true
}
fn require_interval_qualifier(&self) -> bool {
true
}
fn supports_bang_not_operator(&self) -> bool {
true
}
fn supports_select_item_multi_column_alias(&self) -> bool {
true
}
fn supports_cte_without_as(&self) -> bool {
true
}
fn supports_map_literal_with_angle_brackets(&self) -> bool {
true
}
fn parse_infix(
&self,
parser: &mut Parser,
expr: &Expr,
_precedence: u8,
) -> Option<Result<Expr, ParserError>> {
if parser.parse_keyword(Keyword::DIV) {
let left = Box::new(expr.clone());
let right = Box::new(match parser.parse_expr() {
Ok(expr) => expr,
Err(e) => return Some(Err(e)),
});
Some(Ok(Expr::BinaryOp {
left,
op: BinaryOperator::MyIntegerDivide,
right,
}))
} else {
None
}
}
}