dgraph-io/dgraph · error

Wrong type %v encountered for fun ceil

Error message

Wrong type %v encountered for fun ceil

What it means

The `ceil` unary function rounds a numeric value up; it supports INT, FLOAT, and BIGFLOAT inputs. Non-numeric operand types hit the DEFAULT branch, which returns this error (note the message typo "fun ceil" in this version) with the offending type ID.

Source

Thrown at query/aggregator.go:561

	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)

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

func applySince(a, res *types.Val) error {
	if a.Tid == types.DateTimeID {
		a.Value = float64(time.Since(a.Value.(time.Time))) / 1000000000.0
		a.Tid = types.FloatID
		*res = *a
		return nil
	}
	return errors.Errorf("Wrong type %v encountered for func since", a.Tid)
}

type unaryFunc func(a, res *types.Val) error
type binaryFunc func(a, b, res *types.Val) error

var unaryFunctions = map[string]unaryFunc{

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure the operand is an int/float typed predicate or numeric variable
  2. Check and fix the predicate's schema type
  3. Convert the value to a number first (e.g. since() for durations) then ceil
  4. Sanity-test with a numeric literal to isolate the bad operand

Example fix

// before
"math ceil(priceAsString)"
// after
"math ceil(price)"
Defensive patterns

Strategy: type-guard

Validate before calling

if (!['int','float'].includes(schemaOf('price'))) throw new Error('ceil needs numeric predicate');

Type guard

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

Try / catch

try {
  r = await txn.query(q);
} catch (e) {
  if (String(e).includes('ceil')) throw new Error('ceil operand must be numeric: ' + e);
  throw e;
}

Prevention

When it happens

Trigger: math ceil(x) where x is a string, bool, dateTime, or DEFAULT-typed value rather than a numeric predicate/variable.

Common situations: Ceiling a string facet value; applying ceil to a datetime predicate; schema changed so the predicate no longer returns floats.

Related errors


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