コード例 #1
0
ファイル: build_scan.go プロジェクト: mschoch/query
func (this *builder) selectScan(keyspace datastore.Keyspace, node *algebra.KeyspaceTerm,
	limit expression.Expression) (op plan.Operator, err error) {
	keys := node.Keys()
	if keys != nil {
		switch keys := keys.(type) {
		case *expression.ArrayConstruct:
			this.maxParallelism = util.MaxInt(1, len(keys.Operands()))
		case *algebra.NamedParameter, *algebra.PositionalParameter:
			this.maxParallelism = 0
		default:
			this.maxParallelism = 1
		}

		return plan.NewKeyScan(keys), nil
	}

	this.maxParallelism = 0 // Use default parallelism for index scans

	secondary, primary, err := this.buildScan(keyspace, node, limit)
	if err != nil {
		return nil, err
	}

	if secondary != nil {
		return secondary, nil
	} else {
		return primary, nil
	}
}
コード例 #2
0
ファイル: build_upsert.go プロジェクト: pkdevboxy/query
func (this *builder) VisitUpsert(stmt *algebra.Upsert) (interface{}, error) {
	ksref := stmt.KeyspaceRef()
	ksref.SetDefaultNamespace(this.namespace)

	keyspace, err := this.getNameKeyspace(ksref.Namespace(), ksref.Keyspace())
	if err != nil {
		return nil, err
	}

	children := make([]plan.Operator, 0, 4)

	if stmt.Values() != nil {
		children = append(children, plan.NewValueScan(stmt.Values()))
		this.maxParallelism = util.MaxInt(1, len(stmt.Values()))
	} else if stmt.Select() != nil {
		sel, err := stmt.Select().Accept(this)
		if err != nil {
			return nil, err
		}

		children = append(children, sel.(plan.Operator))
	} else {
		return nil, fmt.Errorf("UPSERT missing both VALUES and SELECT.")
	}

	subChildren := make([]plan.Operator, 0, 4)
	subChildren = append(subChildren, plan.NewSendUpsert(keyspace, ksref.Alias(), stmt.Key(), stmt.Value()))

	if stmt.Returning() != nil {
		subChildren = append(subChildren, plan.NewInitialProject(stmt.Returning()), plan.NewFinalProject())
	} else {
		subChildren = append(subChildren, plan.NewDiscard())
	}

	parallel := plan.NewParallel(plan.NewSequence(subChildren...), this.maxParallelism)
	children = append(children, parallel)
	return plan.NewSequence(children...), nil
}