MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / commonConstantType

Function commonConstantType

pkg/sql/sem/tree/constant.go:439–455  ·  view source on GitHub ↗

commonConstantType returns the most constrained type which is mutually resolvable between a set of provided constants. The function takes a slice of Exprs and indexes, but expects all the indexed Exprs to wrap a Constant. The reason it does no take a slice of Constants instead is to avoid forcing c

(vals []Expr, idxs intsets.Fast)

Source from the content-addressed store, hash-verified

437// Exprs to wrap a Constant. The reason it does no take a slice of Constants
438// instead is to avoid forcing callers to allocate separate slices of Constant.
439func commonConstantType(vals []Expr, idxs intsets.Fast) (*types.T, bool) {
440 var candidates []*types.T
441
442 for i, ok := idxs.Next(0); ok; i, ok = idxs.Next(i + 1) {
443 availableTypes := vals[i].(Constant).DesirableTypes()
444 if candidates == nil {
445 candidates = availableTypes
446 } else {
447 candidates = intersectTypeSlices(candidates, availableTypes)
448 }
449 }
450
451 if len(candidates) > 0 {
452 return candidates[0], true
453 }
454 return nil, false
455}
456
457// StrVal represents a constant string value.
458type StrVal struct {

Callers 2

typeCheckSameTypedConstsFunction · 0.85

Calls 3

intersectTypeSlicesFunction · 0.85
NextMethod · 0.65
DesirableTypesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…