Skip to content

Support DISTINCT for SetOperator #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
unvalley opened this issue Oct 26, 2022 · 1 comment · Fixed by #689
Closed

Support DISTINCT for SetOperator #688

unvalley opened this issue Oct 26, 2022 · 1 comment · Fixed by #689

Comments

@unvalley
Copy link
Contributor

unvalley commented Oct 26, 2022

I’d like to parse UNION DISTINCT using BigQuery and MySQL dialect.
This is not included in standard.

BigQuery Reference: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax?hl=ja#set_operators
MySQL Reference: https://dev.mysql.com/doc/refman/8.0/en/union.html

I'm not familiar with other dialects, if other dialects allow UNION DISTINCT, please comment.

@unvalley
Copy link
Contributor Author

unvalley commented Oct 26, 2022

And I'm working on this.

below are what I'm doing (if it's not reasonable change, please let me know).

I'm changing all(bool) field in SetOperation to op_option(Option<SetOperatorOption>).

/// src/ast/query.rs
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum SetOperatorOption {
    All,
    Distinct,
}

impl fmt::Display for SetOperatorOption {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SetOperatorOption::All => write!(f, " ALL"),
            SetOperatorOption::Distinct => write!(f, " DISTINCT"),
        }
    }
}

// ~
pub enum SetExpr {
    // ~
    /// UNION/EXCEPT/INTERSECT of two queries
    SetOperation {
        op: SetOperator,
        op_option: Option<SetOperatorOption>,
        left: Box<SetExpr>,
        right: Box<SetExpr>,
    },
    Values(Values),
}

@unvalley unvalley changed the title Support UNION DISTINCT Support DISTINCT for SetOperator Nov 5, 2022
@alamb alamb closed this as completed in #689 Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant