mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-10 14:02:14 +00:00
MsSQL SET for session params (#1646)
This commit is contained in:
parent
0c3b6c0974
commit
3b4dc0f227
7 changed files with 271 additions and 0 deletions
127
src/ast/mod.rs
127
src/ast/mod.rs
|
@ -3437,6 +3437,10 @@ pub enum Statement {
|
|||
/// Snowflake `REMOVE`
|
||||
/// See: <https://docs.snowflake.com/en/sql-reference/sql/remove>
|
||||
Remove(FileStagingCommand),
|
||||
/// MS-SQL session
|
||||
///
|
||||
/// See <https://learn.microsoft.com/en-us/sql/t-sql/statements/set-statements-transact-sql>
|
||||
SetSessionParam(SetSessionParamKind),
|
||||
}
|
||||
|
||||
impl fmt::Display for Statement {
|
||||
|
@ -5024,6 +5028,7 @@ impl fmt::Display for Statement {
|
|||
}
|
||||
Statement::List(command) => write!(f, "LIST {command}"),
|
||||
Statement::Remove(command) => write!(f, "REMOVE {command}"),
|
||||
Statement::SetSessionParam(kind) => write!(f, "SET {kind}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6441,6 +6446,7 @@ pub enum TransactionIsolationLevel {
|
|||
ReadCommitted,
|
||||
RepeatableRead,
|
||||
Serializable,
|
||||
Snapshot,
|
||||
}
|
||||
|
||||
impl fmt::Display for TransactionIsolationLevel {
|
||||
|
@ -6451,6 +6457,7 @@ impl fmt::Display for TransactionIsolationLevel {
|
|||
ReadCommitted => "READ COMMITTED",
|
||||
RepeatableRead => "REPEATABLE READ",
|
||||
Serializable => "SERIALIZABLE",
|
||||
Snapshot => "SNAPSHOT",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -7937,6 +7944,126 @@ impl fmt::Display for TableObject {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum SetSessionParamKind {
|
||||
Generic(SetSessionParamGeneric),
|
||||
IdentityInsert(SetSessionParamIdentityInsert),
|
||||
Offsets(SetSessionParamOffsets),
|
||||
Statistics(SetSessionParamStatistics),
|
||||
}
|
||||
|
||||
impl fmt::Display for SetSessionParamKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SetSessionParamKind::Generic(x) => write!(f, "{x}"),
|
||||
SetSessionParamKind::IdentityInsert(x) => write!(f, "{x}"),
|
||||
SetSessionParamKind::Offsets(x) => write!(f, "{x}"),
|
||||
SetSessionParamKind::Statistics(x) => write!(f, "{x}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct SetSessionParamGeneric {
|
||||
pub names: Vec<String>,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
impl fmt::Display for SetSessionParamGeneric {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} {}", display_comma_separated(&self.names), self.value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct SetSessionParamIdentityInsert {
|
||||
pub obj: ObjectName,
|
||||
pub value: SessionParamValue,
|
||||
}
|
||||
|
||||
impl fmt::Display for SetSessionParamIdentityInsert {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "IDENTITY_INSERT {} {}", self.obj, self.value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct SetSessionParamOffsets {
|
||||
pub keywords: Vec<String>,
|
||||
pub value: SessionParamValue,
|
||||
}
|
||||
|
||||
impl fmt::Display for SetSessionParamOffsets {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"OFFSETS {} {}",
|
||||
display_comma_separated(&self.keywords),
|
||||
self.value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub struct SetSessionParamStatistics {
|
||||
pub topic: SessionParamStatsTopic,
|
||||
pub value: SessionParamValue,
|
||||
}
|
||||
|
||||
impl fmt::Display for SetSessionParamStatistics {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "STATISTICS {} {}", self.topic, self.value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum SessionParamStatsTopic {
|
||||
IO,
|
||||
Profile,
|
||||
Time,
|
||||
Xml,
|
||||
}
|
||||
|
||||
impl fmt::Display for SessionParamStatsTopic {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SessionParamStatsTopic::IO => write!(f, "IO"),
|
||||
SessionParamStatsTopic::Profile => write!(f, "PROFILE"),
|
||||
SessionParamStatsTopic::Time => write!(f, "TIME"),
|
||||
SessionParamStatsTopic::Xml => write!(f, "XML"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum SessionParamValue {
|
||||
On,
|
||||
Off,
|
||||
}
|
||||
|
||||
impl fmt::Display for SessionParamValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SessionParamValue::On => write!(f, "ON"),
|
||||
SessionParamValue::Off => write!(f, "OFF"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue