// whereInitWorkingClause initialize a new working graph clause.
554363
func whereInitWorkingClause() ClauseHook {
	var f ClauseHook
	f = func(s *Statement, _ Symbol) (ClauseHook, error) {
		s.ResetWorkingGraphClause()
		return f, nil
	}
	return f
}
647449
func ValidateWorkflow(wf *wfv1.Workflow, opts ValidateOpts) error {
	ctx := wfValidationCtx{
		ValidateOpts: opts,
		wf:           wf,
		globalParams: make(map[string]string),
		results:      make(map[string]bool),
	}
	err := validateWorkflowFieldNames(wf.Spec.Templates)
	if err != nil {
		return errors.Errorf(errors.CodeBadRequest, "spec.templates%s", err.Error())
	}
	if ctx.Lint {
		// if we are just linting we don't care if spec.arguments.parameters.XXX doesn't have an
		// explicit value. workflows without a default value is a desired use case
		err = validateArgumentsFieldNames("spec.arguments.", wf.Spec.Arguments)
	} else {
		err = validateArguments("spec.arguments.", wf.Spec.Arguments)
	}
	if err != nil {
		return err
	}
	ctx.globalParams[common.GlobalVarWorkflowName] = placeholderValue
	ctx.globalParams[common.GlobalVarWorkflowNamespace] = placeholderValue
	ctx.globalParams[common.GlobalVarWorkflowUID] = placeholderValue
	for _, param := range ctx.wf.Spec.Arguments.Parameters {
		ctx.globalParams["workflow.parameters."+param.Name] = placeholderValue
	}

	for k := range ctx.wf.ObjectMeta.Annotations {
		ctx.globalParams["workflow.annotations."+k] = placeholderValue
	}
	for k := range ctx.wf.ObjectMeta.Labels {
		ctx.globalParams["workflow.labels."+k] = placeholderValue
	}

	if ctx.wf.Spec.Entrypoint == "" {
		return errors.New(errors.CodeBadRequest, "spec.entrypoint is required")
	}
	entryTmpl := ctx.wf.GetTemplate(ctx.wf.Spec.Entrypoint)
	if entryTmpl == nil {
		return errors.Errorf(errors.CodeBadRequest, "spec.entrypoint template '%s' undefined", ctx.wf.Spec.Entrypoint)
	}
	err = ctx.validateTemplate(entryTmpl, ctx.wf.Spec.Arguments)
	if err != nil {
		return err
	}
	if ctx.wf.Spec.OnExit != "" {
		exitTmpl := ctx.wf.GetTemplate(ctx.wf.Spec.OnExit)
		if exitTmpl == nil {
			return errors.Errorf(errors.CodeBadRequest, "spec.onExit template '%s' undefined", ctx.wf.Spec.OnExit)
		}
		// now when validating onExit, {{workflow.status}} is now available as a global
		ctx.globalParams[common.GlobalVarWorkflowStatus] = placeholderValue
		err = ctx.validateTemplate(exitTmpl, ctx.wf.Spec.Arguments)
		if err != nil {
			return err
		}
	}
	return nil
}
674977
func (s *Statement) SortedGraphPatternClauses() []*GraphClause {
	var ptrns []*GraphClause
	// Filter empty clauses.
	for _, cls := range s.pattern {
		if cls != nil && !cls.IsEmpty() {
			ptrns = append(ptrns, cls)
		}
	}
	sort.Sort(bySpecificity(ptrns))
	return ptrns
}
1353054
func ParseSortWorkItemsBy(s *string) (SortWorkItemsBy, error) {
	if s == nil {
		// this is the default case
		// which returns workitems with highest execution order
		return SortWorkItemsByDefault, nil
	}

	var sort SortWorkItemsBy
	switch *s {
	case "execution":
		sort = SortWorkItemsByExecutionAsc
	case "-execution":
		sort = SortWorkItemsByExecutionDesc
	case "created":
		sort = SortWorkItemsByCreatedAtAsc
	case "-created":
		sort = SortWorkItemsByCreatedAtDesc
	case "updated":
		sort = SortWorkItemsByUpdatedAtAsc
	case "-updated":
		sort = SortWorkItemsByUpdatedAtDesc
	default:
		return SortWorkItemsBy(""), errors.NewBadParameterError("sort", *s)
	}
	return sort, nil
}
1205333
func checkValidWorkflowVariablePrefix(tag string) bool {
	for _, rootTag := range common.GlobalVarValidWorkflowVariablePrefix {
		if strings.HasPrefix(tag, rootTag) {
			return true
		}
	}
	return false
}
1155428
func doesBindingRuleMatch(rule *structs.ACLBindingRule, selectableVars interface{}) bool {
	if rule.Selector == "" {
		return true // catch-all
	}

	eval, err := bexpr.CreateEvaluatorForType(rule.Selector, nil, selectableVars)
	if err != nil {
		return false // fails to match if selector is invalid
	}

	result, err := eval.Evaluate(selectableVars)
	if err != nil {
		return false // fails to match if evaluation fails
	}

	return result
}
1354724
func ColumnClauseFromColumn(c ColumnElem) ColumnClause {
	return ColumnClause{table: c.table, name: c.name}
}
1298113
func (q *Query) WhereInMulti(where string, values ...interface{}) *Query {
	return q.Where(where, types.InMulti(values...))
}
328833
func TaskCheckStateGreaterThan(t1, t2 *api.Task) bool {
	return t2.Status.State > t1.Status.State
}
549097
func (c *Call) HasConditionArg() bool {
	for _, v := range c.Args {
		if _, ok := v.(*Condition); ok {
			return true
		}
	}
	return false
}
19129
func (p *queryPlan) filterOnExistence(ctx context.Context, cls *semantic.GraphClause, lo *storage.LookupOptions) error {
	data := p.tbl.Rows()
	p.tbl.Truncate()
	var (
		gErr error
		mu   sync.RWMutex
		wg   sync.WaitGroup
	)
	for _, tmp := range data {
		mu.RLock()
		if gErr != nil {
			// Try to stop early if an error occurred and we are still ussuing requests.
			mu.RUnlock()
			break
		}
		mu.RUnlock()
		wg.Add(1)
		go func(r table.Row, cls semantic.GraphClause) {
			defer wg.Done()
			sbj, prd, obj := cls.S, cls.P, cls.O
			// Attempt to rebind the subject.
			if sbj == nil && p.tbl.HasBinding(cls.SBinding) {
				v, ok := r[cls.SBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SBinding)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SBinding, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			if sbj == nil && p.tbl.HasBinding(cls.SAlias) {
				v, ok := r[cls.SAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a node, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				sbj = v.N
			}
			// Attempt to rebind the predicate.
			if prd == nil && p.tbl.HasBinding(cls.PBinding) {
				v, ok := r[cls.PBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.PBinding)
					mu.Unlock()
					return
				}
				if v.P == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.PBinding, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			if prd == nil && p.tbl.HasBinding(cls.PAlias) {
				v, ok := r[cls.PAlias]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.SAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a predicate, got %+v instead", cls.SAlias, v)
					mu.Unlock()
					return
				}
				prd = v.P
			}
			// Attempt to rebind the object.
			if obj == nil && p.tbl.HasBinding(cls.OBinding) {
				v, ok := r[cls.OBinding]
				if !ok {
					mu.Lock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OBinding)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
				}
				obj = co
			}
			if obj == nil && p.tbl.HasBinding(cls.OAlias) {
				v, ok := r[cls.OAlias]
				if !ok {
					mu.Unlock()
					gErr = fmt.Errorf("row %+v misses binding %q", r, cls.OAlias)
					mu.Unlock()
					return
				}
				if v.N == nil {
					mu.Lock()
					gErr = fmt.Errorf("binding %q requires a object, got %+v instead", cls.OAlias, v)
					mu.Unlock()
					return
				}
				co, err := cellToObject(v)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				obj = co
			}
			// Attempt to filter.
			if sbj == nil || prd == nil || obj == nil {
				mu.Lock()
				gErr = fmt.Errorf("failed to fully specify clause %v for row %+v", cls, r)
				mu.Unlock()
				return
			}
			exist := false
			for _, g := range p.stm.InputGraphs() {
				t, err := triple.New(sbj, prd, obj)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				b, err := g.Exist(ctx, t)
				if err != nil {
					mu.Lock()
					gErr = err
					mu.Unlock()
					return
				}
				exist = exist || b
				if exist {
					break
				}
			}
			if exist {
				p.tbl.AddRow(r)
			}
		}(tmp, *cls)
	}
	wg.Wait()
	return gErr
}
967611
func (owl *OngoingWorkLimiter) WaitToStart(ctx context.Context) error {
	select {
	case owl.permits <- struct{}{}:
		return nil
	case <-ctx.Done():
		return ctx.Err()
	}
}
8046
func (pr *PluralRule) Condition() string {
	i := strings.Index(pr.Rule, "@")
	return pr.Rule[:i]
}
1046980
func workflowStatus(wf *wfv1.Workflow) wfv1.NodePhase {
	switch wf.Status.Phase {
	case wfv1.NodeRunning:
		if util.IsWorkflowSuspended(wf) {
			return "Running (Suspended)"
		}
		return wf.Status.Phase
	case wfv1.NodeFailed:
		if util.IsWorkflowTerminated(wf) {
			return "Failed (Terminated)"
		}
		return wf.Status.Phase
	case "", wfv1.NodePending:
		if !wf.ObjectMeta.CreationTimestamp.IsZero() {
			return wfv1.NodePending
		}
		return "Unknown"
	default:
		return wf.Status.Phase
	}
}
871072
func (stmt SelectStmt) Where(conds ...Clause) SelectStmt {
	if len(conds) > 1 {
		// By default, multiple where clauses will be joined will AllOf
		stmt.cond = AllOf(conds...)
	} else if len(conds) == 1 {
		stmt.cond = conds[0]
	}
	return stmt
}
1073628
func (c *GraphClause) Bindings() []string {
	var bs []string
	for k := range c.BindingsMap() {
		bs = append(bs, k)
	}
	return bs
}
1079037
func whereExecutor(whereDecl *parser.Decl, fromTableName string) ([]Predicate, error) {
	var predicates []Predicate
	var err error
	whereDecl.Stringy(0)

	for i := range whereDecl.Decl {
		var p Predicate
		tableName := fromTableName
		cond := whereDecl.Decl[i]

		// 1 PREDICATE
		if cond.Lexeme == "1" {
			predicates = append(predicates, TruePredicate)
			continue
		}

		if len(cond.Decl) == 0 {
			log.Debug("whereExecutor: HUm hum you must be AND or OR: %v", cond)
			continue
		}

		switch cond.Decl[0].Token {
		case parser.EqualityToken, parser.LeftDipleToken, parser.RightDipleToken, parser.LessOrEqualToken, parser.GreaterOrEqualToken:
			log.Debug("whereExecutor: it's = < > <= >=\n")
			break
		case parser.InToken:
			log.Debug("whereExecutor: it's IN\n")
			break
		case parser.IsToken:
			log.Debug("whereExecutor: it's IS token\n")
			log.Debug("whereExecutor: %+v\n", cond.Decl[0])
			break
		default:
			log.Debug("it's the table name ! -> %s", cond.Decl[0].Lexeme)
			tableName = cond.Decl[0].Lexeme
			cond.Decl = cond.Decl[1:]
			break
		}

		p.LeftValue.lexeme = whereDecl.Decl[i].Lexeme

		// Handle IN keyword
		if cond.Decl[0].Token == parser.InToken {
			err := inExecutor(cond.Decl[0], &p)
			if err != nil {
				return nil, err
			}
			p.LeftValue.table = tableName
			predicates = append(predicates, p)
			continue
		}

		// Handle IS NULL and IS NOT NULL
		if cond.Decl[0].Token == parser.IsToken {
			err := isExecutor(cond.Decl[0], &p)
			if err != nil {
				return nil, err
			}
			p.LeftValue.table = tableName
			predicates = append(predicates, p)
			continue
		}

		if len(cond.Decl) < 2 {
			return nil, fmt.Errorf("Malformed predicate \"%s\"", cond.Lexeme)
		}

		// The first element of the list is then the relation of the attribute
		op := cond.Decl[0]
		val := cond.Decl[1]

		p.Operator, err = NewOperator(op.Token, op.Lexeme)
		if err != nil {
			return nil, err
		}
		p.RightValue.lexeme = val.Lexeme
		p.RightValue.valid = true

		p.LeftValue.table = tableName

		predicates = append(predicates, p)
	}

	if len(predicates) == 0 {
		return nil, fmt.Errorf("No predicates provided")
	}

	return predicates, nil
}