Esempio n. 1
0
func (s *selectNode) addRender(target parser.SelectExpr, desiredType parser.Type) error {
	// Pre-normalize any VarName so the work is not done twice below.
	if err := target.NormalizeTopLevelVarName(); err != nil {
		return err
	}

	if isStar, cols, typedExprs, err := checkRenderStar(target, s.source.info, s.ivarHelper); err != nil {
		return err
	} else if isStar {
		s.columns = append(s.columns, cols...)
		s.render = append(s.render, typedExprs...)
		s.isStar = true
		return nil
	}

	// When generating an output column name it should exactly match the original
	// expression, so determine the output column name before we perform any
	// manipulations to the expression.
	outputName := getRenderColName(target)

	normalized, err := s.planner.analyzeExpr(target.Expr, s.sourceInfo, s.ivarHelper, desiredType, false, "")
	if err != nil {
		return err
	}

	s.addRenderColumn(normalized, ResultColumn{Name: outputName, Typ: normalized.ResolvedType()})

	return nil
}
Esempio n. 2
0
// computeRender expands a target expression into a result column (or more
// than one, in case there is a star). Whether star expansion occurred
// is indicated by the third return value.
func (p *planner) computeRender(
	target parser.SelectExpr,
	desiredType parser.Type,
	info *dataSourceInfo,
	ivarHelper parser.IndexedVarHelper,
	allowStars bool,
) (columns ResultColumns, exprs []parser.TypedExpr, hasStar bool, err error) {
	// Pre-normalize any VarName so the work is not done twice below.
	if err := target.NormalizeTopLevelVarName(); err != nil {
		return nil, nil, false, err
	}

	if hasStar, cols, typedExprs, err := checkRenderStar(
		target, info, ivarHelper, allowStars); err != nil {
		return nil, nil, false, err
	} else if hasStar {
		return cols, typedExprs, hasStar, nil
	}

	// When generating an output column name it should exactly match the original
	// expression, so determine the output column name before we perform any
	// manipulations to the expression.
	outputName := getRenderColName(target)

	normalized, err := p.analyzeExpr(
		target.Expr, multiSourceInfo{info}, ivarHelper, desiredType, false, "")
	if err != nil {
		return nil, nil, false, err
	}

	return ResultColumns{
		ResultColumn{Name: outputName, Typ: normalized.ResolvedType()},
	}, []parser.TypedExpr{normalized}, false, nil
}