dgraph-io/dgraph · error

Wrong type %v encountered for func floor

Error message

Wrong type %v encountered for func floor

What it means

The `floor` unary function rounds a numeric value down; it supports INT, FLOAT, and BIGFLOAT (BIGFLOAT converted via Float64 then rebuilt with types.BigFloatPrecision). Any other operand type falls to the DEFAULT case which returns this error including the actual type ID encountered.

Source

Thrown at query/aggregator.go:541

	return nil
}

func applyFloor(a, res *types.Val) error {
	vBase := getValType(a)
	switch vBase {
	case INT:
		res.Value = a.Value.(int64)

	case FLOAT:
		res.Value = math.Floor(a.Value.(float64))

	case BIGFLOAT:
		value := a.Value.(big.Float)
		f, _ := value.Float64()
		res.Value = *big.NewFloat(math.Floor(f)).SetPrec(types.BigFloatPrecision)

	case DEFAULT:
		return errors.Errorf("Wrong type %v encountered for func floor", a.Tid)
	}
	return nil
}

func applyCeil(a, res *types.Val) error {
	vBase := getValType(a)
	switch vBase {
	case INT:
		res.Value = a.Value.(int64)

	case FLOAT:
		res.Value = math.Ceil(a.Value.(float64))

	case BIGFLOAT:
		value := a.Value.(big.Float)
		f, _ := value.Float64()
		res.Value = *big.NewFloat(math.Ceil(f)).SetPrec(types.BigFloatPrecision)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Confirm the argument predicate is numeric in the schema
  2. Use since(dt) or other numeric-producing functions before applying floor
  3. Filter out non-numeric values before aggregation
  4. Replace floor with the correct function if a non-numeric transform was intended

Example fix

// before
"math floor(createdAt)"
// after
"math floor(since(createdAt))"
Defensive patterns

Strategy: type-guard

Validate before calling

if (schemaOf('score') !== 'float' && schemaOf('score') !== 'int') throw new Error('floor needs numeric');

Type guard

function isFloorable(v) { return typeof v === 'number'; }

Try / catch

try {
  r = await txn.query(q);
} catch (e) {
  if (String(e).includes('func floor')) { /* switch to numeric source or since() */ }
  throw e;
}

Prevention

When it happens

Trigger: math floor(x) with x being a string, bool, dateTime, or otherwise non-numeric typed value from a predicate or variable.

Common situations: Flooring a string-typed score; using floor on a dateTime by accident (use since() to get a float duration instead); schema drift from float to string.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/76b5ea611a5cc4b4. Report an issue: GitHub.