• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang value.NewValue函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/couchbase/query/value.NewValue函数的典型用法代码示例。如果您正苦于以下问题:Golang NewValue函数的具体用法?Golang NewValue怎么用?Golang NewValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: Signature

/*
Returns the shape of the union result. If the two sub results
are equal return the first value. If either of the inputs
to the union setop are not objects then return the _JSON_SIGNATURE.
Range through the two objects and check for equality and return
object value.
*/
func (this *unionSubresult) Signature() value.Value {
	first := this.first.Signature()
	second := this.second.Signature()

	if first.Equals(second).Truth() {
		return first
	}

	if first.Type() != value.OBJECT ||
		second.Type() != value.OBJECT {
		return _JSON_SIGNATURE
	}

	rv := first.Copy()
	sa := second.Actual().(map[string]interface{})
	for k, v := range sa {
		cv, ok := rv.Field(k)
		if ok {
			if !value.NewValue(cv).Equals(value.NewValue(v)).Truth() {
				rv.SetField(k, _JSON_SIGNATURE)
			}
		} else {
			rv.SetField(k, v)
		}
	}

	return rv
}
开发者ID:mschoch,项目名称:query,代码行数:35,代码来源:set_op.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: BenchmarkN1QLCollateMap

func BenchmarkN1QLCollateMap(b *testing.B) {
	v := qv.NewValue(testcases[0].text)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.Collate(qv.NewValue(testcases[0].text))
	}
}
开发者ID:prataprc,项目名称:indexing,代码行数:7,代码来源:n1qlcollate_test.go


示例4: Apply

/*
It returns a string based on the input expr value. Values
missing, null and strings return themselves. False, true
(boolean) and numbers return their string representation.
This is done using the Sprint method defined in fmt for Go.
All other values map to null.
*/
func (this *ToString) Apply(context Context, arg value.Value) (value.Value, error) {
	switch arg.Type() {
	case value.MISSING, value.NULL, value.STRING:
		return arg, nil
	case value.BOOLEAN:
		return value.NewValue(fmt.Sprint(arg.Actual())), nil
	case value.NUMBER:
		f := arg.Actual().(float64)
		if f == -0 {
			f = 0
		}

		s := strconv.FormatFloat(f, 'f', -1, 64)
		return value.NewValue(s), nil
	case value.BINARY:
		raw, ok := arg.Actual().([]byte)
		if !ok {
			return value.NULL_VALUE, nil
		}

		s := string(raw)
		return value.NewValue(s), nil
	default:
		return value.NULL_VALUE, nil
	}
}
开发者ID:pkdevboxy,项目名称:query,代码行数:33,代码来源:func_type_conv.go


示例5: Test2iScanRange

func Test2iScanRange(t *testing.T) {
	c.LogIgnore()
	//c.SetLogLevel(c.LogLevelDebug)
	low, high := value.NewValue("aaaa"), value.NewValue("zzzz")
	span := &datastore.Span{
		Range: &datastore.Range{
			Low:       value.Values{low},
			High:      value.Values{high},
			Inclusion: datastore.BOTH,
		},
	}
	conn := datastore.NewIndexConnection(nil)
	entrych := conn.EntryChannel()
	quitch := conn.StopChannel()

	go index.Scan("", span, false, 10000, conn)

	count := 0
loop:
	for {
		select {
		case _, ok := <-entrych:
			if !ok {
				break loop
			}
			count++
		case <-quitch:
			break loop
		}
	}
	if count != 20000 {
		t.Fatal("failed ScanRange() - ", count)
	}
}
开发者ID:pkdevboxy,项目名称:query,代码行数:34,代码来源:secondary_index_test.go


示例6: 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


示例7: EvaluateForIndex

func (this *All) EvaluateForIndex(item value.Value, context Context) (value.Value, value.Values, error) {
	val, vals, err := this.array.EvaluateForIndex(item, context)
	if err != nil {
		return val, vals, err
	}

	if vals != nil {
		return nil, vals, nil
	}

	var rv value.Values
	act := val.Actual()
	switch act := act.(type) {
	case []interface{}:
		rv = make(value.Values, len(act))
		for i, a := range act {
			rv[i] = value.NewValue(a)
		}
	case nil:
		if val.Type() == value.NULL {
			rv = _NULL_ARRAY
		}
		// Else MISSING, return rv=nil
	default:
		// Coerce scalar into array
		rv = value.Values{value.NewValue(act)}
	}

	return nil, rv, nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:30,代码来源:index_all.go


示例8: Evaluate

func (this *Any) Evaluate(item value.Value, context Context) (value.Value, error) {
	missing := false
	null := false

	barr := make([][]interface{}, len(this.bindings))
	for i, b := range this.bindings {
		bv, err := b.Expression().Evaluate(item, context)
		if err != nil {
			return nil, err
		}

		if b.Descend() {
			buffer := make([]interface{}, 0, 256)
			bv = value.NewValue(bv.Descendants(buffer))
		}

		switch bv.Type() {
		case value.ARRAY:
			barr[i] = bv.Actual().([]interface{})
		case value.MISSING:
			missing = true
		default:
			null = true
		}
	}

	if missing {
		return value.MISSING_VALUE, nil
	}

	if null {
		return value.NULL_VALUE, nil
	}

	n := -1
	for _, b := range barr {
		if n < 0 || len(b) < n {
			n = len(b)
		}
	}

	for i := 0; i < n; i++ {
		cv := value.NewScopeValue(make(map[string]interface{}, len(this.bindings)), item)
		for j, b := range this.bindings {
			cv.SetField(b.Variable(), barr[j][i])
		}

		sv, err := this.satisfies.Evaluate(cv, context)
		if err != nil {
			return nil, err
		}

		if sv.Truth() {
			return value.NewValue(true), nil
		}
	}

	return value.NewValue(false), nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:59,代码来源:coll_any.go


示例9: TestObjectRemove_remove

func TestObjectRemove_remove(t *testing.T) {

	/* tests insert of value in array at start */
	e1 := NewConstant(value.NewValue(map[string]interface{}{"f1": 1, "f2": 2}))
	e2 := NewConstant("f2")
	er := value.NewValue(map[string]interface{}{"f1": 1})
	testObjectRemove(e1, e2, er, t)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:8,代码来源:func_obj_test.go


示例10: BenchmarkN1QLCollateFloat

func BenchmarkN1QLCollateFloat(b *testing.B) {
	jsonb := []byte(`1234567890.001234556`)
	v := qv.NewValue(jsonb)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.Collate(qv.NewValue(jsonb))
	}
}
开发者ID:prataprc,项目名称:indexing,代码行数:8,代码来源:n1qlcollate_test.go


示例11: TestObjectAdd_remove

func TestObjectAdd_remove(t *testing.T) {

	/* tests insert of value in array at start */
	e1 := NewConstant(value.NewValue(map[string]interface{}{"f1": 1, "f2": 2}))
	e2 := NewConstant("f2")
	e3 := NewConstant(value.MISSING_VALUE)
	er := value.NewValue(value.NULL_VALUE)
	testObjectAdd(e1, e2, e3, er, false, t)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:9,代码来源:func_obj_test.go


示例12: BenchmarkN1QLCollateArray

func BenchmarkN1QLCollateArray(b *testing.B) {
	jsonb := []byte(
		`[123456789, 123456789.1234567879, "hello world", true, false, null]`)
	v := qv.NewValue(jsonb)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		v.Collate(qv.NewValue(jsonb))
	}
}
开发者ID:prataprc,项目名称:indexing,代码行数:9,代码来源:n1qlcollate_test.go


示例13: TestObjectPut_replace

func TestObjectPut_replace(t *testing.T) {

	/* tests insert of value in array at start */
	e1 := NewConstant(value.NewValue(map[string]interface{}{"f1": 1, "f2": 2}))
	e2 := NewConstant("f2")
	e3 := NewConstant(3)
	er := value.NewValue(map[string]interface{}{"f1": 1, "f2": 3})
	testObjectPut(e1, e2, e3, er, t)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:9,代码来源:func_obj_test.go


示例14: TestMockIndex

func TestMockIndex(t *testing.T) {
	s, err := NewDatastore("mock:")
	if err != nil {
		t.Fatalf("failed to create store: %v", err)
	}

	p, err := s.NamespaceById("p0")
	if err != nil || p == nil {
		t.Fatalf("expected namespace p0")
	}

	b, err := p.KeyspaceById("b0")
	if err != nil || b == nil {
		t.Fatalf("expected keyspace b0")
	}

	// Do a scan from keys 4 to 6 with Inclusion set to NEITHER - expect 1 result with key 5
	lo := []value.Value{value.NewValue("4")}
	hi := []value.Value{value.NewValue("6")}
	span := &datastore.Span{Range: datastore.Range{Inclusion: datastore.NEITHER, Low: lo, High: hi}}
	items, err := doIndexScan(t, b, span)

	if err != nil {
		t.Fatalf("unexpected error in scan: %v", err)
	}

	if len(items) != 1 {
		t.Fatalf("unexpected number of items in scan: %d", len(items))
	}

	if items[0].PrimaryKey != "5" {
		t.Fatalf("unexpected key in result: %v", items[0].PrimaryKey)
	}

	// Do a scan from keys 4 to 6 with Inclusion set to BOTH - expect 3 results
	span.Range.Inclusion = datastore.BOTH
	items, err = doIndexScan(t, b, span)

	if err != nil {
		t.Fatalf("unexpected error in scan: %v", err)
	}

	if len(items) != 3 {
		t.Fatalf("unexpected number of items in scan: %d", len(items))
	}

	// Do a scan with incorrect range type - expect scan error
	span.Range.Low = []value.Value{value.NewValue(4.0)}
	items, err = doIndexScan(t, b, span)
}
开发者ID:pkdevboxy,项目名称:query,代码行数:50,代码来源:mock_test.go


示例15: Apply

/*
This method returns a string from a start position to the end. It is a substring.
If the input argument value type is missing, then return a missing value, and if null
return a null value. Loop through all the input values, and check the types. If it is
a number type, then check if it is an absolute non floating point number. If not
return null value. If any value other than a number or missing, return a null.
If the position is negative calculate the actual offset by adding it to the length
of the string. If the length of input arguments is 2 or more, it means that the
start and end positions are given, hence return a value which is the
slice starting from that position until the end if specified.
*/
func (this *Substr) Apply(context Context, args ...value.Value) (value.Value, error) {
	null := false

	if args[0].Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	} else if args[0].Type() != value.STRING {
		null = true
	}

	for i := 1; i < len(args); i++ {
		switch args[i].Type() {
		case value.MISSING:
			return value.MISSING_VALUE, nil
		case value.NUMBER:
			vf := args[i].Actual().(float64)
			if vf != math.Trunc(vf) {
				null = true
			}
		default:
			null = true
		}
	}

	if null {
		return value.NULL_VALUE, nil
	}

	str := args[0].Actual().(string)
	pos := int(args[1].Actual().(float64))

	if pos < 0 {
		pos = len(str) + pos
	}

	if pos < 0 || pos >= len(str) {
		return value.NULL_VALUE, nil
	}

	if len(args) == 2 {
		return value.NewValue(str[pos:]), nil
	}

	length := int(args[2].Actual().(float64))
	if length < 0 || pos+length > len(str) {
		return value.NULL_VALUE, nil
	}

	return value.NewValue(str[pos : pos+length]), nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:60,代码来源:func_str.go


示例16: Apply

/*
This method evaluates the input value and returns the length
based on its type. If the input argument is a missing then
return a missing value. Convert it to a valid Go type. If
it is a string slice of interfaces or object then return
its length cast as a number float64. By default return a
null value.
*/
func (this *PolyLength) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.MISSING {
		return value.MISSING_VALUE, nil
	}

	switch oa := arg.Actual().(type) {
	case string:
		return value.NewValue(float64(len(oa))), nil
	case []interface{}:
		return value.NewValue(float64(len(oa))), nil
	case map[string]interface{}:
		return value.NewValue(float64(len(oa))), nil
	default:
		return value.NULL_VALUE, nil
	}
}
开发者ID:pkdevboxy,项目名称:query,代码行数:24,代码来源:func_json.go


示例17: preparedSequence

func preparedSequence(t *testing.T, name string, stmt string) {
	// Verify a sequence of requests:

	// { "prepared": "name" }  fails with "no such name" error
	doNoSuchPrepared(t, name)

	// { "statement": "prepare name as <<N1QL statement>>" }  succeeds
	doPrepare(t, name, stmt)

	// { "prepared": "name" }  succeeds
	doJsonRequest(t, map[string]interface{}{
		"prepared": name,
	})

	prepared, _ := plan.GetPrepared(value.NewValue(name))
	if prepared == nil {
		t.Errorf("Expected to resolve prepared statement with name %v", name)
		return
	}

	// { "prepared": "name", "encoded_plan": "<<encoded plan>>" }  succeeds
	doJsonRequest(t, map[string]interface{}{
		"prepared":     name,
		"encoded_plan": prepared.EncodedPlan(),
	})

}
开发者ID:pkdevboxy,项目名称:query,代码行数:27,代码来源:service_request_test.go


示例18: Apply

/*
It returns true if type of the input value is an number value, else false.
*/
func (this *IsNumber) Apply(context Context, arg value.Value) (value.Value, error) {
	if arg.Type() == value.MISSING || arg.Type() == value.NULL {
		return arg, nil
	}

	return value.NewValue(arg.Type() == value.NUMBER), nil
}
开发者ID:pkdevboxy,项目名称:query,代码行数:10,代码来源:func_type_check.go


示例19: Evaluate

/*
Generate a Version 4 UUID as specified in RFC 4122, wrap it in a value
and return it. The UUID() function may return an error, if so return
a nil value UUID with the error.
*/
func (this *Uuid) Evaluate(item value.Value, context Context) (value.Value, error) {
	u, err := util.UUID()
	if err != nil {
		return nil, err
	}
	return value.NewValue(u), nil
}
开发者ID:jmptrader,项目名称:query,代码行数:12,代码来源:func_meta.go


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang value.AnnotatedValue类代码示例发布时间:2022-05-23
下一篇:
Golang value.NewScopeValue函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap