示例#1
0
func (this *builder) VisitKeyspaceTerm(node *algebra.KeyspaceTerm) (interface{}, error) {
	node.SetDefaultNamespace(this.namespace)
	keyspace, err := this.getTermKeyspace(node)
	if err != nil {
		return nil, err
	}

	if this.subquery && this.correlated && node.Keys() == nil {
		return nil, errors.NewSubqueryMissingKeysError(node.Keyspace())
	}

	scan, err := this.selectScan(keyspace, node, this.limit)
	if err != nil {
		return nil, err
	}

	this.children = append(this.children, scan)

	if this.coveringScan == nil {
		fetch := plan.NewFetch(keyspace, node)
		this.subChildren = append(this.subChildren, fetch)
	}

	return nil, nil
}
示例#2
0
func (this *builder) beginMutate(keyspace datastore.Keyspace, ksref *algebra.KeyspaceRef,
	keys expression.Expression, indexes algebra.IndexRefs, limit expression.Expression, isDelete bool) error {
	ksref.SetDefaultNamespace(this.namespace)
	term := algebra.NewKeyspaceTerm(ksref.Namespace(), ksref.Keyspace(), nil, ksref.As(), keys, indexes)

	this.children = make([]plan.Operator, 0, 8)
	this.subChildren = make([]plan.Operator, 0, 8)

	if this.where != nil {
		limit = nil
	}

	scan, err := this.selectScan(keyspace, term, limit)
	if err != nil {
		return err
	}

	this.children = append(this.children, scan)

	if this.coveringScan != nil {
		coverer := expression.NewCoverer(this.coveringScan.Covers())
		err = this.cover.MapExpressions(coverer)
		if err != nil {
			return err
		}

		if this.where != nil {
			this.where, err = coverer.Map(this.where)
			if err != nil {
				return err
			}
		}
	} else {
		var fetch plan.Operator
		if isDelete && this.where == nil && isKeyScan(scan) {
			fetch = plan.NewDummyFetch(keyspace, term)
		} else {
			fetch = plan.NewFetch(keyspace, term)
		}
		this.subChildren = append(this.subChildren, fetch)
	}

	if this.where != nil {
		this.subChildren = append(this.subChildren, plan.NewFilter(this.where))
	}

	return nil
}