//Used internally to determine if the dataset needs to use iteself as a source.
//If the dataset has an order or limit it will select from itself
975329
func (me *Dataset) compoundFromSelf() *Dataset {
	if me.clauses.Order != nil || me.clauses.Limit != nil {
		return me.FromSelf()
	}
	return me.copy()
}
198048
func (me *Dataset) Limit(limit uint) *Dataset {
	ret := me.copy()
	if limit > 0 {
		ret.clauses.Limit = limit
	} else {
		ret.clauses.Limit = nil
	}
	return ret
}
1157523
func (c *Client) GetDatasets(ctx context.Context) ([]*Dataset, error) {
	datasets := make([]*Dataset, 0)
	req, err := c.NewRequest("GET", datasetsPath, nil, nil)
	if err != nil {
		return nil, err
	}

	if err := c.Do(ctx, req, &datasets); err != nil {
		return nil, err
	}

	return datasets, nil
}
815
func (order *TermsOrder) Source() (interface{}, error) {
	source := make(map[string]string)
	if order.Ascending {
		source[order.Field] = "asc"
	} else {
		source[order.Field] = "desc"
	}
	return source, nil
}
482116
func (me *Dataset) isDefaultSelect() bool {
	ret := false
	if me.clauses.Select != nil {
		selects := me.clauses.Select.Columns()
		if len(selects) == 1 {
			if l, ok := selects[0].(LiteralExpression); ok && l.Literal() == "*" {
				ret = true
			}
		}
	}
	return ret
}
1235028
func (a *APIDefinition) IterateResources(it ResourceIterator) error {
	res := make([]*ResourceDefinition, len(a.Resources))
	i := 0
	for _, r := range a.Resources {
		res[i] = r
		i++
	}
	// Iterate parent resources first so that action parameters are
	// finalized prior to child actions needing them.
	isParent := func(p, c *ResourceDefinition) bool {
		par := c.Parent()
		for par != nil {
			if par == p {
				return true
			}
			par = par.Parent()
		}
		return false
	}
	sort.Slice(res, func(i, j int) bool {
		if isParent(res[i], res[j]) {
			return true
		}
		if isParent(res[j], res[i]) {
			return false
		}
		return res[i].Name < res[j].Name
	})
	for _, r := range res {
		if err := it(r); err != nil {
			return err
		}
	}
	return nil
}
682682
func (s *LoadBalancerService) GetLoadBalancerRuleID(name string, opts ...OptionFunc) (string, int, error) {
	p := &ListLoadBalancerRulesParams{}
	p.p = make(map[string]interface{})

	p.p["name"] = name

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return "", -1, err
		}
	}

	l, err := s.ListLoadBalancerRules(p)
	if err != nil {
		return "", -1, err
	}

	if l.Count == 0 {
		return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
	}

	if l.Count == 1 {
		return l.LoadBalancerRules[0].Id, l.Count, nil
	}

	if l.Count > 1 {
		for _, v := range l.LoadBalancerRules {
			if v.Name == name {
				return v.Id, l.Count, nil
			}
		}
	}
	return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
}
190288
func (d *Data) DefineDatasource(alias, value string) (string, error) {
	if alias == "" {
		return "", errors.New("datasource alias must be provided")
	}
	if d.DatasourceExists(alias) {
		return "", nil
	}
	srcURL, err := parseSourceURL(value)
	if err != nil {
		return "", err
	}
	s := &Source{
		Alias:  alias,
		URL:    srcURL,
		header: d.extraHeaders[alias],
	}
	if d.Sources == nil {
		d.Sources = make(map[string]*Source)
	}
	d.Sources[alias] = s
	return "", nil
}
102401
func isSelectAll(query string) bool {
	match, _ := regexp.MatchString("^\\s*?select\\s+?\\*\\s+?.*?$", query)
	return match
}
1136543
func (e *LimitExec) Exec() *flow.Dataset {
	d := e.Src.Exec()

	k := int(e.Count + e.Offset)

	ret := d.LocalLimit("limit", k, 0)
	if len(d.Shards) > 1 {
		ret = ret.MergeTo("merge", 1)
	}
	ret = ret.LocalLimit("limit", int(e.Count), int(e.Offset))
	return ret
}
512477
func Select(dest interface{}, q *gocql.Query) error {
	return Iter(q).Select(dest)
}
578182
func SelectorFromValidatedSet(ls Set) Selector {
	if ls == nil || len(ls) == 0 {
		return internalSelector{}
	}
	var requirements internalSelector
	for label, value := range ls {
		requirements = append(requirements, Requirement{key: label, operator: selection.Equals, strValues: []string{value}})
	}
	// sort to have deterministic string representation
	sort.Sort(ByKey(requirements))
	return requirements
}
434986
func (d *Dataset) Hint(options ...DasetsetHint) *Dataset {
	for _, option := range options {
		option(d)
	}
	return d
}
599419
func (q FuzzyLikeThisQuery) Source() interface{} {
	// {
	//	"fuzzy_like_this" : {
	//    "fields" : ["name.first", "name.last"],
	//    "like_text" : "text like this one",
	//    "max_query_terms" : 12
	// }

	source := make(map[string]interface{})

	query := make(map[string]interface{})
	source["fuzzy_like_this"] = query

	if len(q.fields) > 0 {
		query["fields"] = q.fields
	}
	query["like_text"] = q.likeText

	if q.maxQueryTerms != nil {
		query["max_query_terms"] = *q.maxQueryTerms
	}
	if q.fuzziness != nil {
		query["fuzziness"] = q.fuzziness
	}
	if q.prefixLength != nil {
		query["prefix_length"] = *q.prefixLength
	}
	if q.ignoreTF != nil {
		query["ignore_tf"] = *q.ignoreTF
	}
	if q.boost != nil {
		query["boost"] = *q.boost
	}
	if q.analyzer != "" {
		query["analyzer"] = q.analyzer
	}
	if q.failOnUnsupportedField != nil {
		query["fail_on_unsupported_field"] = *q.failOnUnsupportedField
	}
	if q.queryName != "" {
		query["_name"] = q.queryName
	}

	return source
}
1084224
func checkAffinity(ctx Context, operand string, lVal, rVal interface{}, lFound, rFound bool) bool {
	return checkConstraint(ctx, operand, lVal, rVal, lFound, rFound)
}
481450
func (me *Dataset) As(alias string) *Dataset {
	ret := me.copy()
	ret.clauses.Alias = I(alias)
	return ret
}
425914
func (me *DefaultAdapter) DatasetSql(buf *SqlBuilder, dataset Dataset) error {
	buf.WriteRune(left_paren_rune)
	if buf.IsPrepared {
		if err := dataset.selectSqlWriteTo(buf); err != nil {
			return err
		}
	} else {
		sql, _, err := dataset.Prepared(false).ToSql()
		if err != nil {
			return err
		}
		buf.WriteString(sql)
	}
	buf.WriteRune(right_paren_rune)
	alias := dataset.GetClauses().Alias
	if alias != nil {
		buf.Write(me.AsFragment)
		return me.Literal(buf, alias)
	}
	return nil
}