Example #1
0
func (this *Order) lessThan(v1 value.AnnotatedValue, v2 value.AnnotatedValue) bool {
	var ev1, ev2 value.Value
	var c int
	var e error

	for i, term := range this.plan.Terms() {
		s := this.terms[i]

		sv1 := v1.GetAttachment(s)
		switch sv1 := sv1.(type) {
		case value.Value:
			ev1 = sv1
		default:
			ev1, e = term.Expression().Evaluate(v1, this.context)
			if e != nil {
				this.context.Error(errors.NewEvaluationError(e, "ORDER BY"))
				return false
			}

			v1.SetAttachment(s, ev1)
		}

		sv2 := v2.GetAttachment(s)
		switch sv2 := sv2.(type) {
		case value.Value:
			ev2 = sv2
		default:
			ev2, e = term.Expression().Evaluate(v2, this.context)
			if e != nil {
				this.context.Error(errors.NewEvaluationError(e, "ORDER BY"))
				return false
			}

			v2.SetAttachment(s, ev2)
		}

		c = ev1.Collate(ev2)

		if c == 0 {
			continue
		} else if term.Descending() {
			return c > 0
		} else {
			return c < 0
		}
	}

	return false
}
Example #2
0
func (this *IndexJoin) joinEntry(item value.AnnotatedValue,
	entry *datastore.IndexEntry, context *Context) (found, ok bool) {
	var jv value.AnnotatedValue
	covers := this.plan.Covers()

	if len(covers) == 0 {
		jv, ok = this.fetch(entry, context)
		if jv == nil || !ok {
			return jv != nil, ok
		}
	} else {
		jv = value.NewAnnotatedValue(nil)
		meta := map[string]interface{}{"id": entry.PrimaryKey}
		jv.SetAttachment("meta", meta)

		for i, c := range covers {
			jv.SetCover(c.Text(), entry.EntryKey[i])
		}
	}

	joined := item.Copy().(value.AnnotatedValue)
	joined.SetField(this.plan.Term().Alias(), jv)
	return true, this.sendItem(joined)
}
Example #3
0
func (this *Clone) processItem(item value.AnnotatedValue, context *Context) bool {
	clone := item.CopyForUpdate()
	item.SetAttachment("clone", clone)
	return this.sendItem(item)
}