Lower an expression into a instance of a table in the query
(&mut self, expr: pl::Expr)
| 244 | |
| 245 | /// Lower an expression into a instance of a table in the query |
| 246 | fn lower_table_ref(&mut self, expr: pl::Expr) -> Result<rq::TableRef> { |
| 247 | let mut expr = expr; |
| 248 | if expr.lineage.is_none() { |
| 249 | // make sure that type of this expr has been inferred to be a table |
| 250 | expr.lineage = Some(Lineage::default()); |
| 251 | } |
| 252 | |
| 253 | Ok(match expr.kind { |
| 254 | pl::ExprKind::Ident(fq_table_name) => { |
| 255 | // ident that refer to table: create an instance of the table |
| 256 | let id = expr.id.unwrap(); |
| 257 | let tid = *self |
| 258 | .table_mapping |
| 259 | .get(&fq_table_name) |
| 260 | .ok_or_else(|| Error::new_bug(4474))?; |
| 261 | |
| 262 | log::debug!("lowering an instance of table {fq_table_name} (id={id})..."); |
| 263 | |
| 264 | let input_name = expr |
| 265 | .lineage |
| 266 | .as_ref() |
| 267 | .and_then(|f| f.inputs.first()) |
| 268 | .map(|i| i.name.clone()); |
| 269 | let name = input_name.or(Some(fq_table_name.name)); |
| 270 | |
| 271 | self.create_a_table_instance(id, name, tid) |
| 272 | } |
| 273 | pl::ExprKind::TransformCall(_) => { |
| 274 | // pipeline that has to be pulled out into a table |
| 275 | let id = expr.id.unwrap(); |
| 276 | |
| 277 | // create a new table |
| 278 | let tid = self.tid.gen(); |
| 279 | |
| 280 | let relation = self.lower_relation(expr)?; |
| 281 | |
| 282 | let last_transform = &relation.kind.as_pipeline().unwrap().last().unwrap(); |
| 283 | let cids = last_transform.as_select().unwrap().clone(); |
| 284 | |
| 285 | log::debug!("lowering inline table, columns = {:?}", relation.columns); |
| 286 | self.table_buffer.push(TableDecl { |
| 287 | id: tid, |
| 288 | name: None, |
| 289 | relation, |
| 290 | }); |
| 291 | |
| 292 | // return an instance of this new table |
| 293 | let table_ref = self.create_a_table_instance(id, None, tid); |
| 294 | |
| 295 | let redirects = zip(cids, table_ref.columns.iter().map(|(_, c)| *c)).collect(); |
| 296 | self.redirect_mappings(redirects); |
| 297 | |
| 298 | table_ref |
| 299 | } |
| 300 | pl::ExprKind::SString(items) => { |
| 301 | let id = expr.id.unwrap(); |
| 302 | |
| 303 | // create a new table |
no test coverage detected