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


Golang dparval.Value类代码示例

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


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

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

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

示例3: processItem

func (this *InterpretedExecutor) processItem(q network.Query, item *dparval.Value) bool {
	projection := item.GetAttachment("projection")
	switch projection := projection.(type) {
	case *dparval.Value:
		result := projection.Value()
		q.Response().SendResult(result)
	}
	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:9,代码来源:interpreted.go

示例4: Evaluate

func (this *Property) Evaluate(item *dparval.Value) (*dparval.Value, error) {
	if item == nil {
		return nil, &dparval.Undefined{this.Path}
	}
	pv, err := item.Path(this.Path)
	if err != nil {
		return nil, err
	}
	return pv, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:10,代码来源:property.go

示例5: setAggregateValue

func setAggregateValue(item *dparval.Value, key string, val *dparval.Value) {
	aggregates := item.GetAttachment("aggregates")
	aggregatesMap, ok := aggregates.(map[string]interface{})
	if !ok {
		// create a new aggregates map
		aggregatesMap = map[string]interface{}{}
		item.SetAttachment("aggregates", aggregatesMap)
	}
	aggregatesMap[key] = val
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:10,代码来源:function_aggregate_utils.go

示例6: Evaluate

func (this *FunctionCallSplit) Evaluate(item *dparval.Value) (*dparval.Value, error) {
	// first evaluate the arguments
	av, err := this.Operands[0].Expr.Evaluate(item)

	if err != nil {
		switch err := err.(type) {
		case *dparval.Undefined:
			// undefined returns null
			return dparval.NewValue(nil), nil
		default:
			// any other error return to caller
			return nil, err
		}

		// FIXME warn if arguments were wrong type?
		if av.Type() != dparval.STRING {
			return dparval.NewValue(nil), nil
		}
	}

	var sep *dparval.Value = nil
	if len(this.Operands) > 1 {
		sep, err = this.Operands[1].Expr.Evaluate(item)
		if err != nil {
			switch err := err.(type) {
			case *dparval.Undefined:
				// undefined returns null
				return dparval.NewValue(nil), nil
			default:
				// any other error return to caller
				return nil, err
			}
		}

		// FIXME warn if arguments were wrong type?
		if sep.Type() != dparval.STRING {
			return dparval.NewValue(nil), nil
		}
	}

	var sa []string
	if sep != nil {
		sa = strings.Split(av.Value().(string),
			sep.Value().(string))
	} else {
		sa = strings.Fields(av.Value().(string))
	}

	rv := make([]interface{}, len(sa))
	for i, s := range sa {
		rv[i] = s
	}

	return dparval.NewValue(rv), nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:55,代码来源:function_strings.go

示例7: processItem

func (this *EliminateDuplicates) processItem(item *dparval.Value) bool {
	projection, _ := item.GetAttachment("projection").(*dparval.Value)
	if projection != nil {
		hashval := fmt.Sprintf("%s", projection.Value())
		found := this.uniqueBuffer[hashval]
		if found == nil {
			this.uniqueBuffer[hashval] = item
		}
	}
	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:11,代码来源:eliminate_duplicates.go

示例8: Evaluate

func (this *FunctionCallNowMillis) Evaluate(item *dparval.Value) (*dparval.Value, error) {
	// first retrieve the query object
	q := item.GetAttachment("query")

	query, ok := q.(network.Query)
	if !ok {
		return dparval.NewValue(nil), nil
	}

	return dparval.NewValue(timeToMillis(query.StartTime())), nil
}
开发者ID:phonkee,项目名称:tuqtng,代码行数:11,代码来源:function_date.go

示例9: eliminateNonObject

func eliminateNonObject(val *dparval.Value, err error) (*dparval.Value, error) {
	val, err = eliminateNullMissing(val, err)
	if err != nil {
		return nil, err
	}
	if val != nil {
		if val.Type() == dparval.OBJECT {
			return val, nil
		}
	}
	return nil, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:12,代码来源:function_aggregate_utils.go

示例10: eliminateNonNumber

func eliminateNonNumber(val *dparval.Value, err error) (*dparval.Value, error) {
	val, err = eliminateNullMissing(val, err)
	if err != nil {
		return nil, err
	}
	if val != nil {
		if val.Type() == dparval.NUMBER {
			return val, nil
		}
	}
	return nil, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:12,代码来源:function_aggregate_utils.go

示例11: aggregateValue

// lookup the current value of the aggregate stored
// at the specified key
func aggregateValue(item *dparval.Value, key string) (*dparval.Value, error) {
	aggregates := item.GetAttachment("aggregates")
	aggregatesMap, ok := aggregates.(map[string]interface{})
	if ok {
		value := aggregatesMap[key]
		valuedparval, ok := value.(*dparval.Value)
		if ok {
			return valuedparval, nil
		}
	}
	return nil, fmt.Errorf("Unable to find aggregate %s", key)
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:14,代码来源:function_aggregate_utils.go

示例12: eliminateNullMissing

func eliminateNullMissing(val *dparval.Value, err error) (*dparval.Value, error) {
	if err != nil {
		switch err := err.(type) {
		case *dparval.Undefined:
			// missing elimination
			return nil, nil
		default:
			return nil, err
		}
	}
	if val.Type() == dparval.NULL {
		// null elimination
		return nil, nil
	}
	return val, nil
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:16,代码来源:function_aggregate_utils.go

示例13: processItem

func (this *Project) processItem(item *dparval.Value) bool {
	resultMap := map[string]interface{}{}
	for _, resultItem := range this.Result {

		val, err := this.Base.projectedValueOfResultExpression(item, resultItem)
		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 expression"))
			}
		}

		if resultItem.Star {
			if val != nil {
				valval := val.Value()
				switch valval := valval.(type) {
				case map[string]interface{}:
					// then if the result was an object
					// add its contents ot the result map
					for k, v := range valval {
						resultMap[k] = v
					}
				}
			}
		} else {
			resultMap[resultItem.As] = val
		}
	}

	if !this.projectEmpty && len(resultMap) == 0 {
		return true
	}

	// build a Value from the projection
	projection := dparval.NewValue(resultMap)

	// store the projection as an attachment on the main item
	item.SetAttachment("projection", projection)

	clog.To(DEBUG_PROJECT_CHANNEL, "projecting: %v", item)

	// write to the output
	return this.Base.SendItem(item)
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:47,代码来源:project.go

示例14: processItem

func (this *Order) processItem(item *dparval.Value) bool {
	if this.explicitAliases != nil {
		projection := item.GetAttachment("projection")
		projectionValue, ok := projection.(*dparval.Value)
		if ok {
			for _, explicitAlias := range this.explicitAliases {
				// put the explicit alias values from the projection into the item
				aliasedProjectedValue, err := projectionValue.Path(explicitAlias)
				if err == nil {
					item.SetPath(explicitAlias, aliasedProjectedValue)
				}
			}
		}
	}
	this.buffer = append(this.buffer, item)
	return true
}
开发者ID:latinojoel,项目名称:tuqtng,代码行数:17,代码来源:order.go

示例15: flushBatch

func (this *KeyNest) 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]

		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 {
					this.Right = append(this.Right, projectedVal)
				}
			} else {
				this.Right = append(this.Right, item)
			}
			this.rowsFetched += 1
		}
	}
	if len(this.Right) > 0 {
		baseItem.SetPath(this.As, this.Right)
	}
	// if the lenght of the array is 0 and the type of join is not LEFT
	// then we return an empty result for this evaluation
	if len(this.Right) == 0 && this.Type != "LEFT" {
		return true
	}

	this.Base.SendItem(baseItem)

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


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