Expand a select item node.
| 1330 | |
| 1331 | // Expand a select item node. |
| 1332 | void PASS1_expand_select_node(DsqlCompilerScratch* dsqlScratch, ExprNode* node, ValueListNode* list, |
| 1333 | bool hide_using) |
| 1334 | { |
| 1335 | FieldNode* fieldNode; |
| 1336 | |
| 1337 | //// TODO: LocalTableSourceNode |
| 1338 | if (auto rseNode = nodeAs<RseNode>(node)) |
| 1339 | { |
| 1340 | ValueListNode* sub_items = rseNode->dsqlSelectList; |
| 1341 | |
| 1342 | if (sub_items) // AB: Derived table support |
| 1343 | { |
| 1344 | NestConst<ValueExprNode>* ptr = sub_items->items.begin(); |
| 1345 | |
| 1346 | for (const NestConst<ValueExprNode>* const end = sub_items->items.end(); ptr != end; ++ptr) |
| 1347 | { |
| 1348 | // Create a new alias else mappings would be mangled. |
| 1349 | NestConst<ValueExprNode> select_item = *ptr; |
| 1350 | |
| 1351 | // select-item should always be a derived field! |
| 1352 | |
| 1353 | DerivedFieldNode* derivedField; |
| 1354 | |
| 1355 | if (!(derivedField = nodeAs<DerivedFieldNode>(select_item))) |
| 1356 | { |
| 1357 | // Internal dsql error: alias type expected by PASS1_expand_select_node |
| 1358 | ERRD_post(Arg::Gds(isc_sqlerr) << Arg::Num(-104) << |
| 1359 | Arg::Gds(isc_dsql_command_err) << |
| 1360 | Arg::Gds(isc_dsql_derived_alias_select)); |
| 1361 | } |
| 1362 | |
| 1363 | dsql_ctx* context = derivedField->context; |
| 1364 | DEV_BLKCHK(context, dsql_type_ctx); |
| 1365 | |
| 1366 | if (!hide_using || context->getImplicitJoinField(derivedField->name, select_item)) |
| 1367 | list->add(select_item); |
| 1368 | } |
| 1369 | } |
| 1370 | else // joins |
| 1371 | { |
| 1372 | RecSourceListNode* streamList = rseNode->dsqlStreams; |
| 1373 | |
| 1374 | for (NestConst<RecordSourceNode>* ptr = streamList->items.begin(); |
| 1375 | ptr != streamList->items.end(); |
| 1376 | ++ptr) |
| 1377 | { |
| 1378 | PASS1_expand_select_node(dsqlScratch, *ptr, list, true); |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | else if (auto procNode = nodeAs<ProcedureSourceNode>(node)) |
| 1383 | { |
| 1384 | dsql_ctx* context = procNode->dsqlContext; |
| 1385 | |
| 1386 | if (context->ctx_procedure) |
| 1387 | { |
| 1388 | for (dsql_fld* field = context->ctx_procedure->prc_outputs; field; field = field->fld_next) |
| 1389 | { |
no test coverage detected