iffyio commented on code in PR #1732: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1732#discussion_r1962898767
########## src/ast/mod.rs: ########## @@ -8591,6 +8591,61 @@ pub enum CopyIntoSnowflakeKind { Location, } +/// Index Field +/// +/// This structure used here [`MySQL` CREATE INDEX][1], [`PostgreSQL` CREATE INDEX][2], [`MySQL` CREATE TABLE][3]. +/// +/// [1]: https://dev.mysql.com/doc/refman/8.3/en/create-index.html +/// [2]: https://www.postgresql.org/docs/17/sql-createindex.html +/// [3]: https://dev.mysql.com/doc/refman/8.3/en/create-table.html + +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub struct IndexField { + pub expr: IndexExpr, + /// Optional `ASC` or `DESC` + pub asc: Option<bool>, +} + +impl fmt::Display for IndexField { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.expr)?; + match self.asc { + Some(true) => write!(f, " ASC")?, + Some(false) => write!(f, " DESC")?, + None => (), + } + Ok(()) + } +} + +#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub enum IndexExpr { + Column(Ident), + /// Mysql specific syntax + /// + /// See [Mysql documentation](https://dev.mysql.com/doc/refman/8.3/en/create-index.html) + /// for more details. + ColumnPrefix { + column: Ident, + length: u64, + }, + Functional(Box<Expr>), +} Review Comment: would it be possible to replace this with an `Expr` instead? The docs seems to suggest that arbitrary expressions are allowed, from the docs ```sql CREATE TABLE t1 (col1 INT, col2 INT, INDEX func_index ((ABS(col1)))); CREATE INDEX idx1 ON t1 ((col1 + col2)); CREATE INDEX idx2 ON t1 ((col1 + col2), (col1 - col2), col1); ALTER TABLE t1 ADD INDEX ((col1 * 40) DESC); ``` this would let us reuse existing code and representation, maybe even replace `IndexField` with `OrderByExpr` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org