コード例 #1
0
func (this *EliminateDuplicates) afterItems() {
	// write the output
	for pos, item := range this.buffer {
		// we will nil out duplicates and then skip over those entries in the buffer
		if item != nil {
			if pos < len(this.buffer) {
				// look to see if the exact same item appears later in the buffer
				for nextpos, nextitem := range this.buffer[pos+1:] {
					itemProj, ok := item.GetAttachment("projection").(*dparval.Value)
					if ok {
						itemVal := itemProj.Value()
						if nextitem != nil {
							nextItemProj, ok := nextitem.GetAttachment("projection").(*dparval.Value)
							if ok {
								nextItemVal := nextItemProj.Value()
								comp := ast.CollateJSON(itemVal, nextItemVal)
								if comp == 0 {
									this.buffer[pos+nextpos+1] = nil
								}
							}
						}
					}
				}
			}
			clog.To(DEBUG_DUP_CHANNEL, "distinct: %v", item)
			this.Base.SendItem(item)
		}
	}
}
コード例 #2
0
ファイル: order.go プロジェクト: latinojoel/tuqtng
func (this *Order) Less(i, j int) bool {
	left := this.buffer[i]
	right := this.buffer[j]

	for _, oe := range this.OrderBy {
		leftVal, lerr := this.Base.Evaluate(oe.Expr, left)
		if lerr != nil {
			switch lerr := lerr.(type) {
			case *dparval.Undefined:
			default:
				clog.Error(lerr)
				return false
			}
		}
		rightVal, rerr := this.Base.Evaluate(oe.Expr, right)
		if rerr != nil {
			switch rerr := rerr.(type) {
			case *dparval.Undefined:
			default:
				clog.Error(rerr)
				return false
			}
		}

		// at this point, the only errors left should be MISSING/UNDEFINED
		if oe.Ascending && lerr != nil && rerr == nil {
			// ascending, left missing, right not, left is less
			return true
		} else if !oe.Ascending && rerr != nil && lerr == nil {
			// descending right missing, left not, left is more
			return true
		} else if !oe.Ascending && lerr != nil && rerr == nil {
			// descending, left missing, right not, left is less
			return false
		} else if oe.Ascending && rerr != nil && lerr == nil {
			//ascending, left not, left is more
			return false
		} else if lerr == nil && rerr == nil {
			lv := leftVal.Value()
			rv := rightVal.Value()

			// both not missing, compare values
			result := ast.CollateJSON(lv, rv)
			if result != 0 {
				if oe.Ascending && result < 0 {
					return true
				} else if !oe.Ascending && result > 0 {
					return true
				} else {
					return false
				}
			}
		}
		// at this level they are the same, keep going
	}

	// if we go to this point the order expressions could not differentiate between the elements
	return false
}
コード例 #3
0
ファイル: plan.go プロジェクト: latinojoel/tuqtng
func compareTheLookupValues(left, right catalog.LookupValue) int {
	for i, l := range left {
		if i >= len(right) {
			// left array has more elements, right sorts first
			return 1
		}
		r := right[i]
		comp := ast.CollateJSON(l.Value(), r.Value())
		if comp != 0 {
			return comp
		}
	}
	if len(right) > len(left) {
		return -1
	}
	return 0
}
コード例 #4
0
ファイル: plan.go プロジェクト: latinojoel/tuqtng
func compareLookupValues(left, right catalog.LookupValue, nilHighLow int) int {
	if left == nil && right == nil {
		return 0
	} else if left == nil {
		return nilHighLow
	} else if right == nil {
		return -nilHighLow
	}
	for i, l := range left {
		if i >= len(right) {
			// left array has more elements, right sorts first
			return 1
		}
		r := right[i]
		comp := ast.CollateJSON(l.Value(), r.Value())
		if comp != 0 {
			return comp
		}
	}
	if len(right) > len(left) {
		return -1
	}
	return 0
}