MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / index_sql

Function index_sql

src/adapter/src/util.rs:199–224  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

197// TODO(benesch): constructing the canonical CREATE INDEX statement should be
198// the responsibility of the SQL package.
199pub 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`.
227pub fn describe(

Callers 1

Calls 10

unresolveFunction · 0.85
to_ast_string_stableMethod · 0.80
get_unambiguous_nameMethod · 0.80
NameClass · 0.50
ResolvedClass · 0.50
ValueEnum · 0.50
to_stringMethod · 0.45
collectMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected