Beispiel #1
0
func (this *SendInsert) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_         string `json:"#operator"`
		KeyExpr   string `json:"key"`
		ValueExpr string `json:"value"`
		Keys      string `json:"keyspace"`
		Names     string `json:"namespace"`
		Alias     string `json:"alias"`
	}

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

	if _unmarshalled.KeyExpr != "" {
		this.key, err = parser.Parse(_unmarshalled.KeyExpr)
		if err != nil {
			return err
		}
	}

	if _unmarshalled.ValueExpr != "" {
		this.value, err = parser.Parse(_unmarshalled.ValueExpr)
		if err != nil {
			return err
		}
	}

	this.alias = _unmarshalled.Alias
	this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)
	return err
}
Beispiel #2
0
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
}
Beispiel #3
0
func (this *Merge) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_      string               `json:"#operator"`
		Keys   string               `json:"keyspace"`
		Names  string               `json:"namespace"`
		KRef   *algebra.KeyspaceRef `json:"keyspaceRef"`
		Key    string               `json:"key"`
		Update json.RawMessage      `json:"update"`
		Delete json.RawMessage      `json:"delete"`
		Insert json.RawMessage      `json:"insert"`
	}

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

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

	if _unmarshalled.Key != "" {
		this.key, err = parser.Parse(_unmarshalled.Key)
		if err != nil {
			return err
		}
	}

	ops := []json.RawMessage{
		_unmarshalled.Update,
		_unmarshalled.Delete,
		_unmarshalled.Insert,
	}
	for i, child := range ops {
		var op_type struct {
			Operator string `json:"#operator"`
		}

		err = json.Unmarshal(child, &op_type)
		if err != nil {
			return err
		}

		switch i {
		case 0:
			this.update, err = MakeOperator(op_type.Operator, child)
		case 1:
			this.delete, err = MakeOperator(op_type.Operator, child)
		case 2:
			this.insert, err = MakeOperator(op_type.Operator, child)
		}
		return err
	}

	return err
}
Beispiel #4
0
func (this *CreatePrimaryIndex) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string                      `json:"#operator"`
		Keys  string                      `json:"keyspace"`
		Names string                      `json:"namespace"`
		Node  *algebra.CreatePrimaryIndex `json:"node"`
	}

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

	this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys)
	return err
}
Beispiel #5
0
func (this *CountScan) UnmarshalJSON(body []byte) error {
	var _unmarshalled struct {
		_     string `json:"#operator"`
		Names string `json:"namespace"`
		Keys  string `json:"keyspace"`
	}

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

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

	return err
}
Beispiel #6
0
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)
}
Beispiel #7
0
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
}
Beispiel #8
0
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
}