本文整理汇总了Golang中github.com/couchbaselabs/query/value.Value.Actual方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.Actual方法的具体用法?Golang Value.Actual怎么用?Golang Value.Actual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbaselabs/query/value.Value
的用法示例。
在下文中一共展示了Value.Actual方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Apply
/*
This method evaluates the Field using the first and second value
and returns the result value. If the second operand type is a
missing return a missing value. If it is a string, and the
field is case insensitive, then convert the second operand to
lower case, range through the fields of the first and compare,
each field with the second. When equal, return the value. If
the field is case sensitive, use the Field method to directly
access the field and return it. For all other types, if the
first operand expression is missing, return missing, else return
null.
*/
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
}
}
}
示例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
}
示例3: 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
}
}
示例4: 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
}
return value.NewValue([]interface{}{arg.Actual()}), nil
}
示例5: 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
}
}
示例6: 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
}
}
示例7: Apply
/*
This method takes in two values and returns new value that returns a boolean
value that depicts if the second value is contained within the first. If
either of the input values are missing, return a missing value, and if they
arent strings then return a null value. Use the Contains method from the
string package to return a boolean value that is true if substring (second)
is within the string(first).
*/
func (this *Contains) 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.Contains(first.Actual().(string), second.Actual().(string))
return value.NewValue(rv), nil
}
示例8: 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
}
示例9: Apply
/*
This method returns the length of the input array using
the len method. If the input value is of type missing
return a missing value, and for all non array values
return null.
*/
func (this *ArrayLength) Apply(context Context, arg value.Value) (value.Value, error) {
if arg.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else if arg.Type() != value.ARRAY {
return value.NULL_VALUE, nil
}
aa := arg.Actual().([]interface{})
return value.NewValue(float64(len(aa))), nil
}
示例10: 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)
}
示例11: cumulatePart
/*
Aggregate input partial values into cumulative result number value.
If the partial and current cumulative result are both float64
numbers, add them and return.
*/
func (this *Count) cumulatePart(part, cumulative value.Value, context Context) (value.Value, error) {
actual := part.Actual()
switch actual := actual.(type) {
case float64:
count := cumulative.Actual()
switch count := count.(type) {
case float64:
return value.NewValue(count + actual), nil
default:
return nil, fmt.Errorf("Invalid COUNT %v of type %T.", count, count)
}
default:
return nil, fmt.Errorf("Invalid partial COUNT %v of type %T.", actual, actual)
}
}
示例12: Apply
/*
IN evaluates to TRUE if the right-hand-side first value is an array
and directly contains the left-hand-side second value. If either
of the input operands are missing, return missing value, and
if the second is not an array return null. Range over the elements of the
array and check if any element is equal to the first value, return true.
For all other cases, return false.
*/
func (this *In) 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 second.Type() != value.ARRAY {
return value.NULL_VALUE, nil
}
sa := second.Actual().([]interface{})
for _, s := range sa {
if first.Equals(value.NewValue(s)) {
return value.TRUE_VALUE, nil
}
}
return value.FALSE_VALUE, nil
}
示例13: Apply
/*
This method evaluates the element using the first and second value
and returns the result value. If the second operand type is missing
then return a missing value. If it is a number, check if it is an
absolute number (equal to its trucated value), and return the element
at that index using the Index method. If it isnt a number or missing,
then check the first elements type. If it is missing return missing
otherwise return null value.
*/
func (this *Element) Apply(context Context, first, second value.Value) (value.Value, error) {
switch second.Type() {
case value.NUMBER:
s := second.Actual().(float64)
if s == math.Trunc(s) {
v, _ := first.Index(int(s))
return v, nil
}
case value.MISSING:
return value.MISSING_VALUE, nil
}
if first.Type() == value.MISSING {
return value.MISSING_VALUE, nil
} else {
return value.NULL_VALUE, nil
}
}
示例14: Apply
/*
This method Evaluates the slive using the input args depending on the
number of args. The form source-expr [ start : end ] is called array
slicing. It returns a new array containing a subset of the source,
containing the elements from position start to end-1. The element at
start is included, while the element at end is not. If end is omitted,
all elements from start to the end of the source array are included.
The source is the first argument. If it is missing return a missing
value. The first argument represents start. If missing return missing.
If there are more than 2 arguments, then an end is specified. Check
its type, and if missing return missing value. Since start and end
represent indices, make sure they are integer values and if not return
null value. Call Slice or Slice tail on the source (depending on whether
end is specified) to return the specified slice.
*/
func (this *Slice) Apply(context Context, args ...value.Value) (rv value.Value, re error) {
source := args[0]
if source.Type() == value.MISSING {
return value.MISSING_VALUE, nil
}
start := args[1]
if start.Type() == value.MISSING {
return value.MISSING_VALUE, nil
}
ev := -1
var end value.Value
if len(args) >= 3 {
end = args[2]
if end.Type() == value.MISSING {
return value.MISSING_VALUE, nil
}
ea, ok := end.Actual().(float64)
if !ok || ea != math.Trunc(ea) {
return value.NULL_VALUE, nil
}
ev = int(ea)
}
sa, ok := start.Actual().(float64)
if !ok || sa != math.Trunc(sa) {
return value.NULL_VALUE, nil
}
if source.Type() != value.ARRAY {
return value.NULL_VALUE, nil
}
if end != nil {
rv, _ = source.Slice(int(sa), ev)
} else {
rv, _ = source.SliceTail(int(sa))
}
return
}
示例15: Apply
/*
This method evaluates the mod for the first and second input
values to return a value. If the second value type is a number,
convert to a valid Go type. Check for divide by 0. If true return
a Null value. If the first value is a Number, calculate the mod
and return it. If either of the two values are missing return a
missing value. If not a number and not missing return a NULL value.
*/
func (this *Mod) Apply(context Context, first, second value.Value) (value.Value, error) {
if second.Type() == value.NUMBER {
s := second.Actual().(float64)
if s == 0.0 {
return value.NULL_VALUE, nil
}
if first.Type() == value.NUMBER {
m := math.Mod(first.Actual().(float64), s)
return value.NewValue(m), nil
}
}
if first.Type() == value.MISSING || second.Type() == value.MISSING {
return value.MISSING_VALUE, nil
}
return value.NULL_VALUE, nil
}