use of io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType in project trino by trinodb.
the class SubqueryPlanner method planScalarSubquery.
private PlanBuilder planScalarSubquery(PlanBuilder subPlan, Cluster<SubqueryExpression> cluster) {
// Plan one of the predicates from the cluster
SubqueryExpression scalarSubquery = cluster.getRepresentative();
RelationPlan relationPlan = planSubquery(scalarSubquery, subPlan.getTranslations());
PlanBuilder subqueryPlan = newPlanBuilder(relationPlan, analysis, lambdaDeclarationToSymbolMap);
PlanNode root = new EnforceSingleRowNode(idAllocator.getNextId(), subqueryPlan.getRoot());
Type type = analysis.getType(scalarSubquery);
RelationType descriptor = relationPlan.getDescriptor();
List<Symbol> fieldMappings = relationPlan.getFieldMappings();
Symbol column;
if (descriptor.getVisibleFieldCount() > 1) {
column = symbolAllocator.newSymbol("row", type);
ImmutableList.Builder<Expression> fields = ImmutableList.builder();
for (int i = 0; i < descriptor.getAllFieldCount(); i++) {
Field field = descriptor.getFieldByIndex(i);
if (!field.isHidden()) {
fields.add(fieldMappings.get(i).toSymbolReference());
}
}
Expression expression = new Cast(new Row(fields.build()), TypeSignatureTranslator.toSqlType(type));
root = new ProjectNode(idAllocator.getNextId(), root, Assignments.of(column, expression));
} else {
column = getOnlyElement(fieldMappings);
}
return appendCorrelatedJoin(subPlan, root, scalarSubquery.getQuery(), CorrelatedJoinNode.Type.INNER, TRUE_LITERAL, mapAll(cluster, subPlan.getScope(), column));
}
Aggregations