コード例 #1
0
ファイル: build_mutate.go プロジェクト: amarantha-k/query
func (this *builder) beginMutate(keyspace datastore.Keyspace,
	ksref *algebra.KeyspaceRef, keys, where expression.Expression) error {
	ksref.SetDefaultNamespace(this.namespace)
	term := algebra.NewKeyspaceTerm(ksref.Namespace(), ksref.Keyspace(), nil, ksref.As(), nil)

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

	if keys != nil {
		scan := NewKeyScan(keys)
		this.children = append(this.children, scan)
	} else {
		scan, err := this.selectScan(keyspace, term)
		if err != nil {
			return err
		}

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

	fetch := NewFetch(keyspace, term)
	this.subChildren = append(this.subChildren, fetch)

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

	return nil
}
コード例 #2
0
ファイル: join.go プロジェクト: amarantha-k/query
func (this *Join) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string `json:"#operator"`
		Names string `json:"namespace"`
		Keys  string `json:"keyspace"`
		On    string `json:"on_keys"`
		Outer bool   `json:"outer"`
		As    string `json:"as"`
	}
	var keys_expr expression.Expression

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	if _unmarshalled.On != "" {
		keys_expr, err = parser.Parse(_unmarshalled.On)
		if err != nil {
			return err
		}
	}

	this.outer = _unmarshalled.Outer
	this.term = algebra.NewKeyspaceTerm(_unmarshalled.Names, _unmarshalled.Keys,
		nil, _unmarshalled.As, keys_expr)
	this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)
	return err
}
コード例 #3
0
ファイル: scan.go プロジェクト: amarantha-k/query
func (this *PrimaryScan) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string              `json:"#operator"`
		Index string              `json:"index"`
		Names string              `json:"namespace"`
		Keys  string              `json:"keyspace"`
		Using datastore.IndexType `json:"using"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	k, err := datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)
	if err != nil {
		return err
	}

	this.term = algebra.NewKeyspaceTerm(
		_unmarshalled.Names, _unmarshalled.Keys,
		nil, "", nil)

	indexer, err := k.Indexer(_unmarshalled.Using)
	if err != nil {
		return err
	}

	index, err := indexer.IndexByName(_unmarshalled.Index)
	if err != nil {
		return err
	}

	primary, ok := index.(datastore.PrimaryIndex)
	if ok {
		this.index = primary
		return nil
	}

	return fmt.Errorf("Unable to unmarshal %s as primary index.", _unmarshalled.Index)
}
コード例 #4
0
ファイル: fetch.go プロジェクト: amarantha-k/query
func (this *Fetch) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string `json:"#operator"`
		Proj  string `json:"projection"`
		Names string `json:"namespace"`
		Keys  string `json:"keyspace"`
		As    string `json:"as"`
	}
	var proj_expr expression.Path

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	if _unmarshalled.Proj != "" {
		expr, err := parser.Parse(_unmarshalled.Proj)

		logging.Infop("Fetch", logging.Pair{"_unmarshalled.Proj", _unmarshalled.Proj},
			logging.Pair{"err", err},
			logging.Pair{"expr", expr},
		)
		if err != nil {
			return err
		}

		_proj_expr, is_path := expr.(expression.Path)
		if !is_path {
			return fmt.Errorf("Fetch.UnmarshalJSON: cannot resolve path expression from %s", _unmarshalled.Proj)
		}
		proj_expr = _proj_expr
	}
	this.term = algebra.NewKeyspaceTerm(_unmarshalled.Names, _unmarshalled.Keys,
		proj_expr, _unmarshalled.As, nil)

	this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)

	return err
}
コード例 #5
0
ファイル: scan.go プロジェクト: amarantha-k/query
func (this *IndexScan) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_        string              `json:"#operator"`
		Index    string              `json:"index"`
		Names    string              `json:"namespace"`
		Keys     string              `json:"keyspace"`
		Using    datastore.IndexType `json:"using"`
		Spans    planner.Spans       `json:"spans"`
		Distinct bool                `json:"distinct"`
		Limit    int64               `json:"limit"`
	}

	err := json.Unmarshal(body, &_unmarshalled)
	if err != nil {
		return err
	}

	k, err := datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)
	if err != nil {
		return err
	}

	this.term = algebra.NewKeyspaceTerm(
		_unmarshalled.Names, _unmarshalled.Keys,
		nil, "", nil)
	this.spans = _unmarshalled.Spans
	this.distinct = _unmarshalled.Distinct
	this.limit = _unmarshalled.Limit

	indexer, err := k.Indexer(_unmarshalled.Using)
	if err != nil {
		return err
	}

	this.index, err = indexer.IndexByName(_unmarshalled.Index)
	return err
}