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


Golang Value.Duplicate方法代码示例

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


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

示例1: joinItems

func (this *KeyJoin) joinItems(item *dparval.Value, keyItem *dparval.Value) bool {

	if keyItem == nil {
		if this.Type == "LEFT" {
			return this.Base.SendItem(item)
		}
		return true
	}

	newItem := item.Duplicate()
	/* join the item and ship it */
	if this.Projection != nil {
		keyProj, Error := this.Base.Evaluate(this.Projection, keyItem)
		if Error != nil {
			switch err := Error.(type) {
			case *dparval.Undefined:
				return true
			default:
				return this.Base.SendError(query.NewError(err, "Internal error in KeyJoin"))
			}

		}
		newItem.SetPath(this.As, keyProj)
	} else {
		newItem.SetPath(this.As, keyItem)
	}
	this.rowsFetched += 1
	this.Base.SendItem(newItem)
	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:30,代码来源:key_join.go

示例2: Evaluate

func (this *CollectionFirstOperator) Evaluate(item *dparval.Value) (*dparval.Value, error) {
	// first evaluate the over
	ov, err := this.Over.Evaluate(item)
	if err != nil {
		return nil, err
	}

	// see if we're dealing with an array
	if ov.Type() == dparval.ARRAY {
		// by accessing the array contents this way
		// we avoid parsing it
		ok := true
		index := 0
		for ok {
			inner, err := ov.Index(index)
			index = index + 1
			if err != nil {
				switch err := err.(type) {
				case *dparval.Undefined:
					ok = false
				default:
					return nil, err
				}
			} else {
				// duplicate the existing context
				innerContext := item.Duplicate()
				// add this object named as the alias
				innerContext.SetPath(this.As, inner)
				if this.Condition != nil {
					// now evaluate the condition in this new context
					innerResult, err := this.Condition.Evaluate(innerContext)
					if err != nil {
						switch err := err.(type) {
						case *dparval.Undefined:
							// this is not true, keep trying
							continue
						default:
							// any other error should be returned to caller
							return nil, err
						}
					}
					innerResultVal := innerResult.Value()
					// check to see if this value is true
					innerBoolResult := ValueInBooleanContext(innerResultVal)
					if innerBoolResult == true {
						// now we have to evaluate the output expression
						outputResult, err := this.Output.Evaluate(innerContext)
						return outputResult, err
					}
				} else {
					// now we have to evaluate the output expression
					outputResult, err := this.Output.Evaluate(innerContext)
					return outputResult, err
				}
			}
		}
		return nil, &dparval.Undefined{}
	}
	return nil, &dparval.Undefined{}
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:60,代码来源:collection_first.go

示例3: flushBatch

func (this *KeyJoin) flushBatch(baseItem *dparval.Value, ids []string) bool {

	bulkResponse, err := this.bucket.BulkFetch(ids)
	if err != nil {
		return this.Base.SendError(query.NewError(err, "error getting bulk response"))
	}

	// now we need to emit the bulk fetched items in the correct order (from the id list)

	for _, v := range ids {
		item, ok := bulkResponse[v]
		newItem := baseItem.Duplicate()
		if item == nil {
			if this.Type == "LEFT" {
				this.Base.SendItem(newItem)
			}
			continue
		}
		if ok {
			if this.Projection != nil {
				projectedVal, err := this.Base.projectedValueOfResultExpression(item, ast.NewResultExpression(this.Projection))
				if err != nil {
					switch err := err.(type) {
					case *dparval.Undefined:
						// undefined contributes nothing to the result map
						continue
					default:
						return this.Base.SendError(query.NewError(err, "unexpected error projecting fetch expression"))
					}
				} else {
					newItem.SetPath(this.As, projectedVal)
				}
			} else {
				newItem.SetPath(this.As, item)
			}
			this.Base.SendItem(newItem)
			this.rowsFetched += 1
		}
	}

	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:42,代码来源:key_join.go

示例4: processItem

func (this *Unnest) processItem(item *dparval.Value) bool {

	val, err := this.Base.Evaluate(this.Over, item)
	if err != nil {
		switch err := err.(type) {
		case *dparval.Undefined:
			if val == nil && this.Type == "LEFT" {
				return this.Base.SendItem(item)
			}
			return true
		default:
			return this.Base.SendError(query.NewError(err, "Internal Error"))
		}
	}

	if val.Type() == dparval.ARRAY {
		ok := true
		index := 0
		for ok {
			inner, err := val.Index(index)
			index = index + 1
			if err != nil {
				switch err := err.(type) {
				case *dparval.Undefined:
					ok = false
				default:
					this.Base.SendError(query.NewError(err, "Internal Error"))
					return false
				}
			} else {
				newItem := item.Duplicate()
				newItem.SetPath(this.As, inner)
				this.Base.SendItem(newItem)
			}
		}
	} else if this.Type == "LEFT" {
		// send back the item since this is a left join
		this.Base.SendItem(item)
	}

	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:42,代码来源:unnest.go

示例5: processItem

func (this *KeyNest) processItem(item *dparval.Value) bool {

	if item == nil {
		return true
	}

	this.Right = make([]interface{}, 0)
	newItem := item.Duplicate()

	val, err := this.Base.Evaluate(this.Keys.Expr, item)
	if err != nil {
		switch err := err.(type) {
		case *dparval.Undefined:
			if this.Type == "LEFT" {
				this.Base.SendItem(newItem)
				return true
			}
			return true
		default:
			return this.Base.SendError(query.NewError(err, "Internal error in KeyNest"))
		}
	}

	if val.Type() == dparval.STRING {
		if this.Keys.Type == "KEYS" {
			this.Base.SendError(query.NewError(fmt.Errorf("KEYS expression should evaluate to an array"), ""))
			return false
		}
		if val.Value() == nil {
			if this.Type == "LEFT" {
				return this.Base.SendItem(item)
			}
			return true
		}

		fetch_id := val.Value().(string)
		keyitem, err := this.bucket.Fetch(fetch_id)
		if err != nil {
			this.Base.SendError(query.NewError(err, "Unable to fetch key"))
			return false
		}

		if keyitem != nil {
			if this.Projection != nil {
				keyproj, Error := this.Base.Evaluate(this.Projection, keyitem)
				if Error != nil {
					switch err := Error.(type) {
					case *dparval.Undefined:
						return true
					default:
						return this.Base.SendError(query.NewError(err, "Internal error in KeyNest"))
					}

				}
				this.Right = append(this.Right, keyproj)
			} else {
				this.Right = append(this.Right, keyitem)
			}

			newItem.SetPath(this.As, this.Right)
			this.Base.SendItem(newItem)
		} else if this.Type == "LEFT" {

			newItem.SetPath(this.As, this.Right)
			this.Base.SendItem(newItem)
		}

		this.rowsFetched += 1

	} else if val.Type() == dparval.ARRAY {
		ok := true
		index := 0

		ids := make([]string, 0, FETCH_BATCH_SIZE)

		if this.Keys.Type == "KEY" {
			this.Base.SendError(query.NewError(fmt.Errorf("KEY used with an array argument"), ""))
			return false
		}

		for ok {
			id, err := val.Index(index)
			index = index + 1

			array_len := len(val.Value().([]interface{}))
			if array_len == 0 {
				if this.Type == "LEFT" {
					item.SetPath(this.As, this.Right)
					this.Base.SendItem(item)
				}
				return true
			}

			if err != nil {
				if len(ids) != 0 {
					return this.flushBatch(item, ids)
				}
				return true
			}

//.........这里部分代码省略.........
开发者ID:latinojoel,项目名称:tuqtng,代码行数:101,代码来源:key_nest.go


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