func (this *InitialGroup) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string "#operator" Keys []string "group_keys" Aggs []string "aggregates" } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.keys = make(expression.Expressions, len(_unmarshalled.Keys)) for i, key := range _unmarshalled.Keys { key_expr, err := parser.Parse(key) if err != nil { return err } this.keys[i] = key_expr } this.aggregates = make(algebra.Aggregates, len(_unmarshalled.Aggs)) for i, agg := range _unmarshalled.Aggs { agg_expr, err := parser.Parse(agg) if err != nil { return err } this.aggregates[i], _ = agg_expr.(algebra.Aggregate) } return nil }
func init() { qpServer = startQueryport("localhost:9998", serverCallb) ns := &namespace{ name: "default", keyspaceCache: make(map[string]datastore.Keyspace), } ks := &keyspace{ namespace: ns, name: "default", indexes: make(map[string]datastore.Index), } expr, err := parser.Parse(`gender`) if err != nil { log.Fatal(err) } equalKey := expression.Expressions{expr} expr, err = parser.Parse(`name`) if err != nil { log.Fatal(err) } rangeKey := expression.Expressions{expr} whereKey, err := parser.Parse("(30 < `age`)") if err != nil { log.Fatal(err) } index, _ = new2iIndex( "testindex", equalKey, rangeKey, whereKey, "gsi", ks) index.setHost([]string{"localhost:9998"}) }
func (this *SendUpsert) 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 nil }
func (this *Range) UnmarshalJSON(body []byte) error { var _unmarshalled struct { Low []string High []string Inclusion datastore.Inclusion } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Low != nil { this.Low = make(expression.Expressions, len(_unmarshalled.Low)) for l, lowExpr := range _unmarshalled.Low { this.Low[l], err = parser.Parse(lowExpr) if err != nil { return err } } } if _unmarshalled.High != nil { this.High = make(expression.Expressions, len(_unmarshalled.High)) for h, hiExpr := range _unmarshalled.High { this.High[h], err = parser.Parse(hiExpr) if err != nil { return err } } } this.Inclusion = _unmarshalled.Inclusion return nil }
func (this *IndexScan) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Index string `json:"index"` Namespace string `json:"namespace"` Keyspace string `json:"keyspace"` Using datastore.IndexType `json:"using"` Spans Spans `json:"spans"` Distinct bool `json:"distinct"` Limit string `json:"limit"` Covers []string `json:"covers"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } k, err := datastore.GetKeyspace(_unmarshalled.Namespace, _unmarshalled.Keyspace) if err != nil { return err } this.term = algebra.NewKeyspaceTerm( _unmarshalled.Namespace, _unmarshalled.Keyspace, nil, "", nil, nil) this.spans = _unmarshalled.Spans this.distinct = _unmarshalled.Distinct if _unmarshalled.Limit != "" { this.limit, err = parser.Parse(_unmarshalled.Limit) if err != nil { return err } } if _unmarshalled.Covers != nil { this.covers = make(expression.Covers, len(_unmarshalled.Covers)) for i, c := range _unmarshalled.Covers { expr, err := parser.Parse(c) if err != nil { return err } this.covers[i] = expression.NewCover(expr) } } indexer, err := k.Indexer(_unmarshalled.Using) if err != nil { return err } this.index, err = indexer.IndexByName(_unmarshalled.Index) return err }
func (this *Span) UnmarshalJSON(body []byte) error { var _unmarshalled struct { Seek []string Range *Range } _unmarshalled.Range = &this.Range err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Seek != nil { this.Seek = make(expression.Expressions, len(_unmarshalled.Seek)) for j, seekExpr := range _unmarshalled.Seek { this.Seek[j], err = parser.Parse(seekExpr) if err != nil { return err } } } return nil }
// Condition implement Index{} interface. func (si *secondaryIndex) Condition() expression.Expression { if si != nil && si.whereExpr != "" { expr, _ := parser.Parse(si.whereExpr) return expr } return nil }
func (this *SendUpdate) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Keys string `json:"keyspace"` Names string `json:"namespace"` Alias string `json:"alias"` Limit string `json:"limit"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.alias = _unmarshalled.Alias if _unmarshalled.Limit != "" { this.limit, err = parser.Parse(_unmarshalled.Limit) if err != nil { return err } } this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys) return err }
func (this *Let) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Bindings []struct { _ string `json:"type"` Var string `json:"variable"` Expr string `json:"variable"` Desc bool `json:"descend"` } `json:"bindings"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.bindings = make(expression.Bindings, len(_unmarshalled.Bindings)) for i, binding := range _unmarshalled.Bindings { expr, err := parser.Parse(binding.Expr) if err != nil { return err } if binding.Desc { this.bindings[i] = expression.NewDescendantBinding(binding.Var, expr) } else { this.bindings[i] = expression.NewBinding(binding.Var, expr) } } return nil }
/* Unmarshals byte array. */ func UnmarshalUpdateFor(body []byte) (*algebra.UpdateFor, error) { var _unmarshalled struct { Bindings json.RawMessage `json:"bindings"` When string `json:"when"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } bindings, err := unmarshal.UnmarshalBindings(_unmarshalled.Bindings) if err != nil { return nil, err } var when expression.Expression if _unmarshalled.When != "" { when, err = parser.Parse(_unmarshalled.When) if err != nil { return nil, err } } return algebra.NewUpdateFor(bindings, when), nil }
func (this *Unnest) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Outer bool `json:"outer"` Expr string `json:"expr"` As string `json:"as"` } var expr expression.Expression err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Expr != "" { expr, err = parser.Parse(_unmarshalled.Expr) if err != nil { return err } } this.term = algebra.NewUnnest(nil, _unmarshalled.Outer, expr, _unmarshalled.As) this.alias = _unmarshalled.As return err }
func (this *ValueScan) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Values string `json:"values"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Values == "" { return nil } expr, err := parser.Parse(_unmarshalled.Values) if err != nil { return err } array, ok := expr.(*expression.ArrayConstruct) if !ok { return fmt.Errorf("Invalid VALUES expression %s", _unmarshalled.Values) } this.values, err = algebra.NewPairs(array) return err }
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, nil) this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys) return err }
func UnmarshalBindings(body []byte) (expression.Bindings, error) { var _unmarshalled []struct { Var string `json:"variable"` Expr string `json:"expr"` Desc bool `json:"descend"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } bindings := make(expression.Bindings, len(_unmarshalled)) for i, binding := range _unmarshalled { expr, err := parser.Parse(binding.Expr) if err != nil { return nil, err } if binding.Desc { bindings[i] = expression.NewDescendantBinding(binding.Var, expr) } else { bindings[i] = expression.NewBinding(binding.Var, expr) } } return bindings, nil }
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) 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, nil) this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys) return err }
// SeekKey implement Index{} interface. func (si *secondaryIndex) SeekKey() expression.Expressions { if si != nil && si.partnExpr != "" { expr, _ := parser.Parse(si.partnExpr) return expression.Expressions{expr} } return nil }
/* Unmarshals byte array. */ func UnmarshalUnsetTerm(body []byte) (*algebra.UnsetTerm, error) { var _unmarshalled struct { Path string `json:"path"` For json.RawMessage `json:"path_for"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } path_expr, err := parser.Parse(_unmarshalled.Path) if err != nil { return nil, err } path, is_path := path_expr.(expression.Path) if !is_path { return nil, fmt.Errorf("UnmarshalUnsetTerm: cannot resolve path expression from %s", _unmarshalled.Path) } var updateFor *algebra.UpdateFor if len(_unmarshalled.For) > 0 { updateFor, err = UnmarshalUpdateFor(_unmarshalled.For) if err != nil { return nil, err } } return algebra.NewUnsetTerm(path, updateFor), nil }
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 }
/* Unmarshals byte array. */ func UnmarshalSetTerms(body []byte) (algebra.SetTerms, error) { var _unmarshalled []struct { Path string `json:"path"` Value string `json:"value"` For json.RawMessage `json:"path_for"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } terms := make(algebra.SetTerms, len(_unmarshalled)) for i, term := range _unmarshalled { path_expr, err := parser.Parse(term.Path) if err != nil { return nil, err } path, is_path := path_expr.(expression.Path) if !is_path { return nil, fmt.Errorf("UnmarshalSetTerms: cannot resolve path expression from %s", term.Path) } value, err := parser.Parse(term.Value) if err != nil { return nil, err } var updateFor *algebra.UpdateFor if len(term.For) > 0 { updateFor, err = UnmarshalUpdateFor(term.For) if err != nil { return nil, err } } terms[i] = algebra.NewSetTerm(path, value, updateFor) } return terms, nil }
// RangeKey implement Index{} interface. func (si *secondaryIndex) RangeKey() expression.Expressions { if si != nil && si.secExprs != nil { exprs := make(expression.Expressions, 0, len(si.secExprs)) for _, exprS := range si.secExprs { expr, _ := parser.Parse(exprS) exprs = append(exprs, expr) } return exprs } return nil }
// CompileN1QLExpression will take expressions defined in N1QL's DDL statement // and compile them for evaluation. func CompileN1QLExpression(expressions []string) ([]interface{}, error) { cExprs := make([]interface{}, 0, len(expressions)) for _, expr := range expressions { cExpr, err := qparser.Parse(expr) if err != nil { logging.Errorf("CompileN1QLExpression() %v: %v\n", expr, err) return nil, err } cExprs = append(cExprs, cExpr) } return cExprs, nil }
func (this *Order) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Terms []struct { Expr string `json:"expr"` Desc bool `json:"desc"` } `json:"sort_terms"` offsetExpr string `json:"offset"` limitExpr string `json:"limit"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.terms = make(algebra.SortTerms, len(_unmarshalled.Terms)) for i, term := range _unmarshalled.Terms { expr, err := parser.Parse(term.Expr) if err != nil { return err } this.terms[i] = algebra.NewSortTerm(expr, term.Desc) } if offsetExprStr := _unmarshalled.offsetExpr; offsetExprStr != "" { offsetExpr, err := parser.Parse(offsetExprStr) if err != nil { return err } this.offset = NewOffset(offsetExpr) } if limitExprStr := _unmarshalled.limitExpr; limitExprStr != "" { limitExpr, err := parser.Parse(limitExprStr) if err != nil { return err } this.limit = NewLimit(limitExpr) } return nil }
func (this *Offset) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Expr string `json:"expr"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.expr, err = parser.Parse(_unmarshalled.Expr) return err }
func (this *Unset) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` UnsetTerms []struct { Path string `json:"path"` Expr string `json:"expr"` } `json:"unset_terms"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } terms := make([]*algebra.UnsetTerm, len(_unmarshalled.UnsetTerms)) for i, UnsetTerm := range _unmarshalled.UnsetTerms { path_expr, err := parser.Parse(UnsetTerm.Path) if err != nil { return err } path, is_path := path_expr.(expression.Path) if !is_path { return fmt.Errorf("Unset.UnmarshalJSON: cannot resolve path expression from %s", UnsetTerm.Path) } // is expr needed in Unset? _, err = parser.Parse(UnsetTerm.Expr) if err != nil { return err } terms[i] = algebra.NewUnsetTerm(path, nil) } this.node = algebra.NewUnset(terms) return nil }
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"` Limit string `json:"limit"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Limit != "" { this.limit, err = parser.Parse(_unmarshalled.Limit) if err != nil { return err } } this.keyspace, err = datastore.GetKeyspace(_unmarshalled.Names, _unmarshalled.Keys) if err != nil { return err } this.term = algebra.NewKeyspaceTerm( _unmarshalled.Names, _unmarshalled.Keys, nil, "", nil, nil) indexer, err := this.keyspace.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) }
func (this *Filter) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Condition string `json:"condition"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Condition != "" { this.cond, err = parser.Parse(_unmarshalled.Condition) } return err }
func (this *KeyScan) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Keys string `json:"keys"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } if _unmarshalled.Keys != "" { this.keys, err = parser.Parse(_unmarshalled.Keys) } return err }
func (this *InitialProject) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Terms []*struct { Expr string `json:"expr"` As string `json:"as"` Star bool `json:"star"` } `json:"result_terms"` Distinct bool `json:"distinct"` Raw bool `json:"raw"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } terms := make(algebra.ResultTerms, len(_unmarshalled.Terms)) for i, term_data := range _unmarshalled.Terms { var expr expression.Expression if term_data.Expr != "" { expr, err = parser.Parse(term_data.Expr) if err != nil { return err } } terms[i] = algebra.NewResultTerm(expr, term_data.Star, term_data.As) } projection := algebra.NewProjection(_unmarshalled.Distinct, terms) results := projection.Terms() project_terms := make(ProjectTerms, len(results)) for i, res := range results { project_terms[i] = &ProjectTerm{ result: res, } } this.projection = projection this.terms = project_terms return nil }
func UnmarshalBinding(body []byte) (*expression.Binding, error) { var _unmarshalled struct { Var string `json:"variable"` Expr string `json:"expr"` Desc bool `json:"descend"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return nil, err } expr, err := parser.Parse(_unmarshalled.Expr) if err != nil { return nil, err } if _unmarshalled.Desc { return expression.NewDescendantBinding(_unmarshalled.Var, expr), nil } else { return expression.NewBinding(_unmarshalled.Var, expr), nil } }
func (this *Order) UnmarshalJSON(body []byte) error { var _unmarshalled struct { _ string `json:"#operator"` Terms []struct { Expr string `json:"expr"` Desc bool `json:"desc"` } `json:"sort_terms"` } err := json.Unmarshal(body, &_unmarshalled) if err != nil { return err } this.terms = make(algebra.SortTerms, len(_unmarshalled.Terms)) for i, term := range _unmarshalled.Terms { expr, err := parser.Parse(term.Expr) if err != nil { return err } this.terms[i] = algebra.NewSortTerm(expr, term.Desc) } return nil }