// NewEvaluatorSuite creates an EvaluatorSuite to evaluate all the exprs.
// avoidColumnEvaluator can be removed after column pool is supported.
15644
func NewEvaluatorSuite(exprs []Expression, avoidColumnEvaluator bool) *EvaluatorSuite {
	e := &EvaluatorSuite{}

	for i := 0; i < len(exprs); i++ {
		if col, isCol := exprs[i].(*Column); isCol && !avoidColumnEvaluator {
			if e.columnEvaluator == nil {
				e.columnEvaluator = &columnEvaluator{inputIdxToOutputIdxes: make(map[int][]int)}
			}
			inputIdx, outputIdx := col.Index, i
			e.columnEvaluator.inputIdxToOutputIdxes[inputIdx] = append(e.columnEvaluator.inputIdxToOutputIdxes[inputIdx], outputIdx)
			continue
		}
		if e.defaultEvaluator == nil {
			e.defaultEvaluator = &defaultEvaluator{
				outputIdxes: make([]int, 0, len(exprs)),
				exprs:       make([]Expression, 0, len(exprs)),
			}
		}
		e.defaultEvaluator.exprs = append(e.defaultEvaluator.exprs, exprs[i])
		e.defaultEvaluator.outputIdxes = append(e.defaultEvaluator.outputIdxes, i)
	}

	if e.defaultEvaluator != nil {
		e.defaultEvaluator.vectorizable = Vectorizable(e.defaultEvaluator.exprs)
	}
	return e
}
556379
func NewValidator() *Validator {
	var (
		v   = &Validator{seen: make(map[string]*bytes.Buffer)}
		err error
	)
	fm := template.FuncMap{
		"tabs":             Tabs,
		"slice":            toSlice,
		"oneof":            oneof,
		"constant":         constant,
		"goifyAtt":         GoifyAtt,
		"add":              Add,
		"recurseAttribute": v.recurseAttribute,
	}
	v.arrayValT, err = template.New("array").Funcs(fm).Parse(arrayValTmpl)
	if err != nil {
		panic(err)
	}
	v.hashValT, err = template.New("hash").Funcs(fm).Parse(hashValTmpl)
	if err != nil {
		panic(err)
	}
	v.userValT, err = template.New("user").Funcs(fm).Parse(userValTmpl)
	if err != nil {
		panic(err)
	}
	return v
}
556516
func (e *EvaluatorSuite) Run(ctx sessionctx.Context, input, output *chunk.Chunk) error {
	if e.defaultEvaluator != nil {
		err := e.defaultEvaluator.run(ctx, input, output)
		if err != nil {
			return err
		}
	}

	if e.columnEvaluator != nil {
		e.columnEvaluator.run(ctx, input, output)
	}
	return nil
}
733235
func (s *StateStore) nestedUpsertEval(txn *memdb.Txn, index uint64, eval *structs.Evaluation) error {
	// Lookup the evaluation
	existing, err := txn.First("evals", "id", eval.ID)
	if err != nil {
		return fmt.Errorf("eval lookup failed: %v", err)
	}

	// COMPAT 0.7: Upgrade old objects that do not have namespaces
	if eval.Namespace == "" {
		eval.Namespace = structs.DefaultNamespace
	}

	// Update the indexes
	if existing != nil {
		eval.CreateIndex = existing.(*structs.Evaluation).CreateIndex
		eval.ModifyIndex = index
	} else {
		eval.CreateIndex = index
		eval.ModifyIndex = index
	}

	// Update the job summary
	summaryRaw, err := txn.First("job_summary", "id", eval.Namespace, eval.JobID)
	if err != nil {
		return fmt.Errorf("job summary lookup failed: %v", err)
	}
	if summaryRaw != nil {
		js := summaryRaw.(*structs.JobSummary).Copy()
		hasSummaryChanged := false
		for tg, num := range eval.QueuedAllocations {
			if summary, ok := js.Summary[tg]; ok {
				if summary.Queued != num {
					summary.Queued = num
					js.Summary[tg] = summary
					hasSummaryChanged = true
				}
			} else {
				s.logger.Error("unable to update queued for job and task group", "job_id", eval.JobID, "task_group", tg, "namespace", eval.Namespace)
			}
		}

		// Insert the job summary
		if hasSummaryChanged {
			// COMPAT 0.7: Upgrade old objects that do not have namespaces
			if js.Namespace == "" {
				js.Namespace = structs.DefaultNamespace
			}

			js.ModifyIndex = index
			if err := txn.Insert("job_summary", js); err != nil {
				return fmt.Errorf("job summary insert failed: %v", err)
			}
			if err := txn.Insert("index", &IndexEntry{"job_summary", index}); err != nil {
				return fmt.Errorf("index update failed: %v", err)
			}
		}
	}

	// Check if the job has any blocked evaluations and cancel them
	if eval.Status == structs.EvalStatusComplete && len(eval.FailedTGAllocs) == 0 {
		// Get the blocked evaluation for a job if it exists
		iter, err := txn.Get("evals", "job", eval.Namespace, eval.JobID, structs.EvalStatusBlocked)
		if err != nil {
			return fmt.Errorf("failed to get blocked evals for job %q in namespace %q: %v", eval.JobID, eval.Namespace, err)
		}

		var blocked []*structs.Evaluation
		for {
			raw := iter.Next()
			if raw == nil {
				break
			}
			blocked = append(blocked, raw.(*structs.Evaluation))
		}

		// Go through and update the evals
		for _, eval := range blocked {
			newEval := eval.Copy()
			newEval.Status = structs.EvalStatusCancelled
			newEval.StatusDescription = fmt.Sprintf("evaluation %q successful", newEval.ID)
			newEval.ModifyIndex = index

			// COMPAT 0.7: Upgrade old objects that do not have namespaces
			if newEval.Namespace == "" {
				newEval.Namespace = structs.DefaultNamespace
			}

			if err := txn.Insert("evals", newEval); err != nil {
				return fmt.Errorf("eval insert failed: %v", err)
			}
		}
	}

	// Insert the eval
	if err := txn.Insert("evals", eval); err != nil {
		return fmt.Errorf("eval insert failed: %v", err)
	}
	if err := txn.Insert("index", &IndexEntry{"evals", index}); err != nil {
		return fmt.Errorf("index update failed: %v", err)
	}
	return nil
}
1160328
func (s *GetComplianceDetailsByConfigRuleOutput) SetEvaluationResults(v []*EvaluationResult) *GetComplianceDetailsByConfigRuleOutput {
	s.EvaluationResults = v
	return s
}
3557
func newEvalState() *evalState {
	return &evalState{
		status: structs.EvalStatusPending,
		allocs: make(map[string]*allocState),
	}
}
677629
func NewValidationAssertion() (Assertion, Failures) {
	vf := &validationFailer{
		offset:  2,
		details: []FailureDetail{},
		errs:    []error{},
	}
	return NewAssertion(vf), vf
}
1210886
func internalNewEvaluator(ce []ConsumedElement) (Evaluator, []ConsumedElement, error) {
	if len(ce) == 0 {
		return nil, nil, errors.New("cannot create an evaluator from an empty sequence of tokens")
	}
	head, tail := ce[0], ce[1:]
	tkn := head.Token()

	// Not token
	if tkn.Type == lexer.ItemNot {
		tailEval, tailCEs, err := internalNewEvaluator(tail)
		if err != nil {
			return nil, tailCEs, err
		}
		e, err := NewUnaryBooleanExpression(NOT, tailEval)
		if err != nil {
			return nil, tailCEs, err
		}
		return e, tailCEs, nil
	}

	// Binding token
	if tkn.Type == lexer.ItemBinding {
		if len(tail) < 2 {
			return nil, nil, fmt.Errorf("cannot create a binary evaluation operand for %v", ce)
		}
		opTkn, bndTkn := tail[0].Token(), tail[1].Token()
		var op OP
		switch opTkn.Type {
		case lexer.ItemEQ:
			op = EQ
		case lexer.ItemLT:
			op = LT
		case lexer.ItemGT:
			op = GT
		default:
			return nil, nil, fmt.Errorf("cannot create a binary evaluation operand for %v", opTkn)
		}
		if bndTkn.Type == lexer.ItemBinding {
			e, err := NewEvaluationExpression(op, tkn.Text, bndTkn.Text)
			if err != nil {
				return nil, nil, err
			}
			var res []ConsumedElement
			if len(tail) > 2 {
				res = tail[2:]
			}
			return e, res, nil
		}
		return nil, nil, fmt.Errorf("cannot build a binary evaluation operand with right operant %v", bndTkn)
	}

	// LPar Token
	if tkn.Type == lexer.ItemLPar {
		tailEval, ce, err := internalNewEvaluator(tail)
		if err != nil {
			return nil, nil, err
		}
		if len(ce) < 1 {
			return nil, nil, errors.New("incomplete parentesis expression; missing ')'")
		}
		head, tail = ce[0], ce[1:]
		if head.Token().Type != lexer.ItemRPar {
			return nil, nil, fmt.Errorf("missing right parentesis in expression; found %v instead", head)
		}
		if len(tail) > 1 {
			// Binary boolean expression.
			opTkn := tail[0].Token()
			var op OP
			switch opTkn.Type {
			case lexer.ItemAnd:
				op = AND
			case lexer.ItemOr:
				op = OR
			default:
				return nil, nil, fmt.Errorf("cannot create a binary boolean evaluation operand for %v", opTkn)
			}
			rTailEval, ceResTail, err := internalNewEvaluator(tail[1:])
			if err != nil {
				return nil, nil, err
			}
			ev, err := NewBinaryBooleanExpression(op, tailEval, rTailEval)
			if err != nil {
				return nil, nil, err
			}
			return ev, ceResTail, nil
		}
		return tailEval, tail, nil
	}

	var tkns []string
	for _, e := range ce {
		tkns = append(tkns, fmt.Sprintf("%q", e.token.Type))
	}
	return nil, nil, fmt.Errorf("could not create an evaluator for condition {%s}", strings.Join(tkns, ","))
}
1293238
func (p *parser) parseSuite() []Stmt {
	if p.tok == NEWLINE {
		p.nextToken() // consume NEWLINE
		p.consume(INDENT)
		var stmts []Stmt
		for p.tok != OUTDENT && p.tok != EOF {
			stmts = p.parseStmt(stmts)
		}
		p.consume(OUTDENT)
		return stmts
	}

	return p.parseSimpleStmt(nil)
}
389092
func (e *FuncExpr) evalSQLFnNode(r Record) (res *Value, err error) {
	// Handle functions that have phrase arguments
	switch e.getFunctionName() {
	case sqlFnCast:
		expr := e.Cast.Expr
		res, err = expr.castTo(r, strings.ToUpper(e.Cast.CastType))
		return

	case sqlFnSubstring:
		return handleSQLSubstring(r, e.Substring)

	case sqlFnExtract:
		return handleSQLExtract(r, e.Extract)

	case sqlFnTrim:
		return handleSQLTrim(r, e.Trim)

	case sqlFnDateAdd:
		return handleDateAdd(r, e.DateAdd)

	case sqlFnDateDiff:
		return handleDateDiff(r, e.DateDiff)

	}

	// For all simple argument functions, we evaluate the arguments here
	argVals := make([]*Value, len(e.SFunc.ArgsList))
	for i, arg := range e.SFunc.ArgsList {
		argVals[i], err = arg.evalNode(r)
		if err != nil {
			return nil, err
		}
	}

	switch e.getFunctionName() {
	case sqlFnCoalesce:
		return coalesce(argVals)

	case sqlFnNullIf:
		return nullif(argVals[0], argVals[1])

	case sqlFnCharLength, sqlFnCharacterLength:
		return charlen(argVals[0])

	case sqlFnLower:
		return lowerCase(argVals[0])

	case sqlFnUpper:
		return upperCase(argVals[0])

	case sqlFnUTCNow:
		return handleUTCNow()

	case sqlFnToString, sqlFnToTimestamp:
		// TODO: implement
		fallthrough

	default:
		return nil, errNotImplemented
	}
}
478433
func newValueExpr(value interface{}) ast.ValueExpr {
	if ve, ok := value.(*ValueExpr); ok {
		return ve
	}
	ve := &ValueExpr{}
	ve.SetValue(value)
	types.DefaultTypeForValue(value, &ve.Type)
	ve.projectionOffset = -1
	return ve
}
220389
func (e *Expr) EvalInt(context interface{}) (val int, err error) {

	valI, err := e.Eval(context)
	if err != nil {
		return 0, err
	}
	return castInt(valI)
}
1091728
func NewPersistentVolumeClaimEvaluator(f quota.ListerForResourceFunc) quota.Evaluator {
	listFuncByNamespace := generic.ListResourceUsingListerFunc(f, corev1.SchemeGroupVersion.WithResource("persistentvolumeclaims"))
	pvcEvaluator := &pvcEvaluator{listFuncByNamespace: listFuncByNamespace}
	return pvcEvaluator
}
336615
func NewEvaluator(ce []ConsumedElement) (Evaluator, error) {
	e, tailCEs, err := internalNewEvaluator(ce)
	if err != nil {
		return nil, err
	}
	if len(tailCEs) > 1 || (len(tailCEs) == 1 && tailCEs[0].Token().Type != lexer.ItemRPar) {
		return nil, fmt.Errorf("failed to consume all token; left over %v", tailCEs)
	}
	return e, nil
}
290569
func NewEvalEligibility() *EvalEligibility {
	return &EvalEligibility{
		job:                  make(map[string]ComputedClassFeasibility),
		taskGroups:           make(map[string]map[string]ComputedClassFeasibility),
		tgEscapedConstraints: make(map[string]bool),
	}
}
447381
func NewEvalContext(s State, p *structs.Plan, log log.Logger) *EvalContext {
	ctx := &EvalContext{
		state:   s,
		plan:    p,
		logger:  log,
		metrics: new(structs.AllocMetric),
	}
	return ctx
}
617475
func NewErrorPropertyRetrieval(m types.ManagedObjectReference, p []string, e error) ErrorPropertyRetrieval {
	return ErrorPropertyRetrieval{err: e, mor: m, ps: p}
}