当前位置: 首页>>代码示例>>Golang>>正文


Golang Value.Type方法代码示例

本文整理汇总了Golang中github.com/couchbaselabs/query/value.Value.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Value.Type方法的具体用法?Golang Value.Type怎么用?Golang Value.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/couchbaselabs/query/value.Value的用法示例。


在下文中一共展示了Value.Type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Apply

/*
If the input argument type is greater than NULL, we return the complement
of its Truth() method's return type. If Null or missing return the argument
itself.
*/
func (this *Not) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() > value.NULL {
		return value.NewValue(!arg.Truth()), nil
	} else {
		return arg, nil
	}
}
开发者ID:amarantha-k,项目名称:query,代码行数:12,代码来源:logic_not.go

示例2: cumulateSets

/*
Aggregate distinct intermediate results and return them.
If no partial result exists(its value is a null) return the
cumulative value. If the cumulative input value is null,
return the partial value. Get the input partial and cumulative
sets and add the smaller set to the bigger. Return this set.
*/
func cumulateSets(part, cumulative value.Value) (value.Value, error) {
	if part.Type() == value.NULL {
		return cumulative, nil
	} else if cumulative.Type() == value.NULL {
		return part, nil
	}

	pset, e := getSet(part)
	if e != nil {
		return nil, e
	}

	cset, e := getSet(cumulative)
	if e != nil {
		return nil, e
	}

	// Add smaller set to bigger
	var smaller, bigger *value.Set
	if pset.Len() <= cset.Len() {
		smaller, bigger = pset, cset
	} else {
		smaller, bigger = cset, pset
	}

	for _, v := range smaller.Values() {
		bigger.Add(v)
	}

	cumulative.(value.AnnotatedValue).SetAttachment("set", bigger)
	return cumulative, nil
}
开发者ID:amarantha-k,项目名称:query,代码行数:39,代码来源:agg_util.go

示例3: 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
		}
	}
}
开发者ID:amarantha-k,项目名称:query,代码行数:39,代码来源:nav_field.go

示例4: Apply

/*
This method returns an object value. The input of types
missing, null and object return themselves. For all other
values, return an _EMPTY_OBJECT value.
*/
func (this *ToObject) Apply(context Context, arg value.Value) (value.Value, error) {
	switch arg.Type() {
	case value.MISSING, value.NULL, value.OBJECT:
		return arg, nil
	}

	return _EMPTY_OBJECT, nil
}
开发者ID:amarantha-k,项目名称:query,代码行数:13,代码来源:func_type_conv.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:amarantha-k,项目名称:query,代码行数:14,代码来源:arith_neg.go

示例6: Apply

/*
This method takes in an operand value and context and returns a value.
If the type of operand is missing then return it. Call MarshalJSON
to get the bytes, and then use Go's encoding/base64 package to
encode the bytes to string. Create a newValue using the string and
return it.
*/
func (this *Base64) Apply(context Context, operand value.Value) (value.Value, error) {
	if operand.Type() == value.MISSING {
		return operand, nil
	}

	bytes, _ := operand.MarshalJSON() // Ignore errors from BINARY values
	str := base64.StdEncoding.EncodeToString(bytes)
	return value.NewValue(str), nil
}
开发者ID:amarantha-k,项目名称:query,代码行数:16,代码来源:func_meta.go

示例7: Apply

/*
This method takes in an argument value and returns a
lowercase string as value. If the input type is
missing return missing, and if it isnt string then
return null value. Use the ToLower method to
convert the string to lower case on a valid Go type
from the Actual method on the argument value. Return
this lower case string as Value.
*/
func (this *Lower) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if arg.Type() != value.STRING {
		return value.NULL_VALUE, nil
	}

	rv := strings.ToLower(arg.Actual().(string))
	return value.NewValue(rv), nil
}
开发者ID:amarantha-k,项目名称:query,代码行数:19,代码来源:func_str.go

示例8: 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:amarantha-k,项目名称:query,代码行数:15,代码来源:coll_exists.go

示例9: Apply

/*
Evaluates the Is Null comparison operation for expressions.
If the type of input argument is a null value, return true,
if missing return a missing value and by for all other types
return a false value.
*/
func (this *IsNull) Apply(context Context, arg value.Value) (value.Value, error) {
	switch arg.Type() {
	case value.NULL:
		return value.TRUE_VALUE, nil
	case value.MISSING:
		return value.MISSING_VALUE, nil
	default:
		return value.FALSE_VALUE, nil
	}
}
开发者ID:amarantha-k,项目名称:query,代码行数:16,代码来源:comp_null.go

示例10: 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
}
开发者ID:amarantha-k,项目名称:query,代码行数:16,代码来源:func_array.go

示例11: 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:amarantha-k,项目名称:query,代码行数:17,代码来源:func_obj.go

示例12: CumulateInitial

func (this *Sum) 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
	}

	return this.cumulatePart(item, cumulative, context)
}
开发者ID:amarantha-k,项目名称:query,代码行数:12,代码来源:agg_sum.go

示例13: CumulateInitial

/*
Aggregates input data by evaluating operands.For all
values other than Number, return the input value itself.
Call setAdd to compute the intermediate aggregate value
and return it.
*/
func (this *AvgDistinct) 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
	}

	return setAdd(item, cumulative)
}
开发者ID:amarantha-k,项目名称:query,代码行数:18,代码来源:agg_avg_distinct.go

示例14: CumulateInitial

/*
Aggregates input data by evaluating operands. For missing
item values, return the input value itself. Call
cumulatePart to compute the intermediate aggregate value
and return it.
*/
func (this *ArrayAgg) 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.MISSING {
		return cumulative, nil
	}

	return this.cumulatePart(value.NewValue([]interface{}{item}), cumulative, context)
}
开发者ID:amarantha-k,项目名称:query,代码行数:18,代码来源:agg_array.go

示例15: 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:amarantha-k,项目名称:query,代码行数:19,代码来源:agg_avg.go


注:本文中的github.com/couchbaselabs/query/value.Value.Type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。