TODO(benesch): constructing the canonical CREATE INDEX statement should be the responsibility of the SQL package.
(
index_name: String,
cluster_id: ClusterId,
view_name: FullItemName,
view_desc: &RelationDesc,
keys: &[usize],
)
| 197 | // TODO(benesch): constructing the canonical CREATE INDEX statement should be |
| 198 | // the responsibility of the SQL package. |
| 199 | pub fn index_sql( |
| 200 | index_name: String, |
| 201 | cluster_id: ClusterId, |
| 202 | view_name: FullItemName, |
| 203 | view_desc: &RelationDesc, |
| 204 | keys: &[usize], |
| 205 | ) -> String { |
| 206 | use mz_sql::ast::{Expr, Value}; |
| 207 | |
| 208 | CreateIndexStatement::<Raw> { |
| 209 | name: Some(Ident::new_unchecked(index_name)), |
| 210 | on_name: RawItemName::Name(mz_sql::normalize::unresolve(view_name)), |
| 211 | in_cluster: Some(RawClusterName::Resolved(cluster_id.to_string())), |
| 212 | key_parts: Some( |
| 213 | keys.iter() |
| 214 | .map(|i| match view_desc.get_unambiguous_name(*i) { |
| 215 | Some(n) => Expr::Identifier(vec![Ident::new_unchecked(n.to_string())]), |
| 216 | _ => Expr::Value(Value::Number((i + 1).to_string())), |
| 217 | }) |
| 218 | .collect(), |
| 219 | ), |
| 220 | with_options: vec![], |
| 221 | if_not_exists: false, |
| 222 | } |
| 223 | .to_ast_string_stable() |
| 224 | } |
| 225 | |
| 226 | /// Creates a description of the statement `stmt`. |
| 227 | pub fn describe( |
no test coverage detected