MCPcopy Create free account
hub / github.com/brimdata/super / NewCompareRelative

Function NewCompareRelative

runtime/sam/expr/eval.go:286–301  ·  view source on GitHub ↗
(sctx *super.Context, lhs, rhs Evaluator, operator string)

Source from the content-addressed store, hash-verified

284}
285
286func NewCompareRelative(sctx *super.Context, lhs, rhs Evaluator, operator string) (*Compare, error) {
287 c := &Compare{sctx: sctx, numeric: newNumeric(sctx, lhs, rhs), operator: operator}
288 switch operator {
289 case "<":
290 c.convert = func(v int) bool { return v < 0 }
291 case "<=":
292 c.convert = func(v int) bool { return v <= 0 }
293 case ">":
294 c.convert = func(v int) bool { return v > 0 }
295 case ">=":
296 c.convert = func(v int) bool { return v >= 0 }
297 default:
298 return nil, fmt.Errorf("unknown comparison operator: %s", operator)
299 }
300 return c, nil
301}
302
303func (c *Compare) result(result int) super.Value {
304 return super.NewBool(c.convert(result))

Callers 1

compileBinaryMethod · 0.92

Calls 1

newNumericFunction · 0.85

Tested by

no test coverage detected