當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Value.Actual方法代碼示例

本文整理匯總了Golang中github.com/couchbase/query/value.Value.Actual方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.Actual方法的具體用法?Golang Value.Actual怎麽用?Golang Value.Actual使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/couchbase/query/value.Value的用法示例。


在下文中一共展示了Value.Actual方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Apply

/*
This method removes all the occurences of the second value from the
first array value.
*/
func (this *ArrayRemove) Apply(context Context, first, second value.Value) (value.Value, error) {
	if first.Type() == value.MISSING {
		return first, nil
	}

	if first.Type() != value.ARRAY {
		return value.NULL_VALUE, nil
	}

	if second.Type() <= value.NULL {
		return first, nil
	}

	fa := first.Actual().([]interface{})
	if len(fa) == 0 {
		return first, nil
	}

	ra := make([]interface{}, 0, len(fa))
	for _, f := range fa {
		if !second.Equals(value.NewValue(f)).Truth() {
			ra = append(ra, f)
		}
	}

	return value.NewValue(ra), nil
}
開發者ID:jmptrader,項目名稱:query,代碼行數:31,代碼來源:func_array.go

示例2: Apply

/*
This method takes in two values and returns a value that
corresponds to the first position of the regular expression
pattern (already set or populated using the second value)
in the first string value, or -1 if it isnt found. If the
input type is missing return missing, and if it isnt
string then return null value. Use the FindStringIndex
method in the regexp package to return a two-element slice
of integers defining the location of the leftmost match in
the string of the regular expression as per the Go Docs. Return
the first element of this slice as a value. If a FindStringIndex
returns nil, then the regexp pattern isnt found. Hence return -1.
*/
func (this *RegexpPosition) Apply(context Context, first, second value.Value) (value.Value, error) {
	if first.Type() == value.MISSING || second.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if first.Type() != value.STRING || second.Type() != value.STRING {
		return value.NULL_VALUE, nil
	}

	f := first.Actual().(string)
	s := second.Actual().(string)

	re := this.re
	if re == nil {
		var err error
		re, err = regexp.Compile(s)
		if err != nil {
			return nil, err
		}
	}

	loc := re.FindStringIndex(f)
	if loc == nil {
		return value.NewValue(-1.0), nil
	}

	return value.NewValue(float64(loc[0])), nil
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:39,代碼來源:func_regexp.go

示例3: Apply

/*
Perform either case-sensitive or case-insensitive field lookup.
*/
func (this *Field) Apply(context Context, first, second value.Value) (value.Value, error) {
	switch second.Type() {
	case value.STRING:
		s := second.Actual().(string)
		v, ok := first.Field(s)

		if !ok && this.caseInsensitive {
			s = strings.ToLower(s)
			fields := first.Fields()
			for f, val := range fields {
				if s == strings.ToLower(f) {
					return value.NewValue(val), nil
				}
			}
		}

		return v, nil
	case value.MISSING:
		return value.MISSING_VALUE, nil
	default:
		if first.Type() == value.MISSING {
			return value.MISSING_VALUE, nil
		} else {
			return value.NULL_VALUE, nil
		}
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:30,代碼來源:nav_field.go

示例4: Apply

/*
This method takes in an object, a name and a value
and returns a new object that contains the name /
attribute pair. If the type of input is missing
then return a missing value, and if not an object
return a null value.
If the key is found, an error is thrown
*/
func (this *ObjectAdd) Apply(context Context, first, second, third value.Value) (value.Value, error) {

	// First must be an object, or we're out
	if first.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if first.Type() != value.OBJECT {
		return value.NULL_VALUE, nil
	}

	// second must be a non empty string
	if second.Type() != value.STRING || second.Actual().(string) == "" {
		return first, nil
	}

	field := second.Actual().(string)

	// we don't overwrite
	_, exists := first.Field(field)
	if exists {
		return value.NULL_VALUE, nil
	}

	// SetField will remove if the attribute is missing, but we don't
	// overwrite anyway, so we might just skip now
	if third.Type() != value.MISSING {
		rv := first.CopyForUpdate()
		rv.SetField(field, third)
		return rv, nil
	}
	return first, nil
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:39,代碼來源:func_obj.go

示例5: Apply

/*
Return the neagation of the input value, if the type of input is a number.
For missing return a missing value, and for all other input types return a
null.
*/
func (this *Neg) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.NUMBER {
		return value.NewValue(-arg.Actual().(float64)), nil
	} else if arg.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else {
		return value.NULL_VALUE, nil
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:14,代碼來源:arith_neg.go

示例6: get

func (this *preparedCache) get(name value.Value) *Prepared {
	if name.Type() != value.STRING || !name.Truth() {
		return nil
	}
	this.RLock()
	rv := this.prepareds[name.Actual().(string)]
	this.RUnlock()
	return rv
}
開發者ID:jmptrader,項目名稱:query,代碼行數:9,代碼來源:prepared.go

示例7: Apply

/*
This method returns the length of the object. If the type of
input is missing then return a missing value, and if not an
object return a null value. Convert it to a valid Go type.
Cast it to a map from string to interface and return its
length by using the len function by casting it to float64.
*/
func (this *ObjectLength) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if arg.Type() != value.OBJECT {
		return value.NULL_VALUE, nil
	}

	oa := arg.Actual().(map[string]interface{})
	return value.NewValue(float64(len(oa))), nil
}
開發者ID:jmptrader,項目名稱:query,代碼行數:17,代碼來源:func_obj.go

示例8: testArrayInsert_eval

func testArrayInsert_eval(e1, e2, e3 Expression, er value.Value, t *testing.T) {
	eai := NewArrayInsert(e1, e2, e3)
	rv, err := eai.Evaluate(nil, nil)
	if err != nil {
		t.Errorf("received error %v", err)
	}
	if er.Collate(rv) != 0 {
		t.Errorf("mismatch received %v expected %v", rv.Actual(), er.Actual())
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:10,代碼來源:func_array_test.go

示例9: Apply

/*
This method takes in two values and returns a value that
corresponds to the second expressions position in the
first.  If the input type is missing return missing, and
if it isnt string then return null value. Use the Index
method defined by the strings package to calculate the
offset position of the second string. Return that value.
*/
func (this *Position) Apply(context Context, first, second value.Value) (value.Value, error) {
	if first.Type() == value.MISSING || second.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if first.Type() != value.STRING || second.Type() != value.STRING {
		return value.NULL_VALUE, nil
	}

	rv := strings.Index(first.Actual().(string), second.Actual().(string))
	return value.NewValue(float64(rv)), nil
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:18,代碼來源:func_str.go

示例10: Apply

/*
This method returns true if he value is an array and contains at least one element.
This is done by checking the length of the array. If the type of input value
is missing then return a missing value, and for all other types return null.
*/
func (this *Exists) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.ARRAY {
		a := arg.Actual().([]interface{})
		return value.NewValue(len(a) > 0), nil
	} else if arg.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else {
		return value.NULL_VALUE, nil
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:15,代碼來源:coll_exists.go

示例11: testObjectRemove

func testObjectRemove(e1, e2 Expression, er value.Value, t *testing.T) {
	eop := NewObjectRemove(e1, e2)
	rv, err := eop.Evaluate(nil, nil)
	if err != nil {
		t.Errorf("received error %v", err)
	}
	if er.Collate(rv) != 0 {
		t.Errorf("mismatch received %v expected %v", rv.Actual(), er.Actual())
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:10,代碼來源:func_obj_test.go

示例12: Apply

/*
Evaluate the difference for the first and second input
values to return a value. If both values are numbers, calculate
the difference and return it. If either of the expressions are
missing then return a missing value. For all other cases return
a null value.
*/
func (this *Sub) Apply(context Context, first, second value.Value) (value.Value, error) {
	if first.Type() == value.NUMBER && second.Type() == value.NUMBER {
		diff := first.Actual().(float64) - second.Actual().(float64)
		return value.NewValue(diff), nil
	} else if first.Type() == value.MISSING || second.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else {
		return value.NULL_VALUE, nil
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:17,代碼來源:arith_sub.go

示例13: Apply

/*
It returns the argument itself if type of the input value is Null,
a value below this (N!QL order) or an Array. Otherwise convert the
argument to a valid Go type ang cast it to a slice of interface.
*/
func (this *ToArray) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() <= value.NULL {
		return arg, nil
	} else if arg.Type() == value.ARRAY {
		return arg, nil
	} else if arg.Type() == value.BINARY {
		return value.NULL_VALUE, nil
	}

	return value.NewValue([]interface{}{arg.Actual()}), nil
}
開發者ID:jmptrader,項目名稱:query,代碼行數:16,代碼來源:func_type_conv.go

示例14: CumulateInitial

/*
Aggregates input data by evaluating operands. For all
values other than Number, return the input value itself. Call
cumulatePart to compute the intermediate aggregate value
and return it.
*/
func (this *Avg) CumulateInitial(item, cumulative value.Value, context Context) (value.Value, error) {
	item, e := this.Operand().Evaluate(item, context)
	if e != nil {
		return nil, e
	}

	if item.Type() != value.NUMBER {
		return cumulative, nil
	}

	part := value.NewValue(map[string]interface{}{"sum": item.Actual(), "count": 1})
	return this.cumulatePart(part, cumulative, context)
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:19,代碼來源:agg_avg.go

示例15: Apply

func (this *Base64Decode) Apply(context Context, operand value.Value) (value.Value, error) {
	if operand.Type() == value.MISSING {
		return operand, nil
	} else if operand.Type() != value.STRING {
		return value.NULL_VALUE, nil
	}

	str, err := base64.StdEncoding.DecodeString(operand.Actual().(string))
	if err != nil {
		return value.NULL_VALUE, nil
	} else {
		return value.NewValue(str), nil
	}
}
開發者ID:pkdevboxy,項目名稱:query,代碼行數:14,代碼來源:func_meta.go


注:本文中的github.com/couchbase/query/value.Value.Actual方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。