MCPcopy
hub / github.com/uber/aresdb / Cast

Function Cast

query/expr/ast.go:636–654  ·  view source on GitHub ↗

Cast returns an expression that casts the input to the desired type. The returned expression AST will be used directly for VM instruction generation of the desired types.

(e Expr, t Type)

Source from the content-addressed store, hash-verified

634// The returned expression AST will be used directly for VM instruction
635// generation of the desired types.
636func Cast(e Expr, t Type) Expr {
637 // Input type is already desired.
638 if e.Type() == t {
639 return e
640 }
641 // Type casting is only required if at least one side is float.
642 // We do not cast (or check for overflow) among boolean, signed and unsigned.
643 if e.Type() != Float && t != Float {
644 return e
645 }
646 // Data type for NumberLiteral can be changed directly.
647 l, _ := e.(*NumberLiteral)
648 if l != nil {
649 l.ExprType = t
650 return l
651 }
652 // Use ParenExpr to respresent a VM type cast.
653 return &ParenExpr{Expr: e, ExprType: t}
654}

Callers 2

RewriteMethod · 0.92
RewriteMethod · 0.92

Calls 1

TypeMethod · 0.65

Tested by

no test coverage detected