{"record":{"id":"dd343edc3086fc67","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-fun-ceil","errorCode":null,"errorMessage":"Wrong type %v encountered for fun ceil","messagePattern":"Wrong type (.+?) encountered for fun ceil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":561,"sourceCode":"\treturn nil\n}\n\nfunc applyCeil(a, res *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\tres.Value = a.Value.(int64)\n\n\tcase FLOAT:\n\t\tres.Value = math.Ceil(a.Value.(float64))\n\n\tcase BIGFLOAT:\n\t\tvalue := a.Value.(big.Float)\n\t\tf, _ := value.Float64()\n\t\tres.Value = *big.NewFloat(math.Ceil(f)).SetPrec(types.BigFloatPrecision)\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for fun ceil\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applySince(a, res *types.Val) error {\n\tif a.Tid == types.DateTimeID {\n\t\ta.Value = float64(time.Since(a.Value.(time.Time))) / 1000000000.0\n\t\ta.Tid = types.FloatID\n\t\t*res = *a\n\t\treturn nil\n\t}\n\treturn errors.Errorf(\"Wrong type %v encountered for func since\", a.Tid)\n}\n\ntype unaryFunc func(a, res *types.Val) error\ntype binaryFunc func(a, b, res *types.Val) error\n\nvar unaryFunctions = map[string]unaryFunc{","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L543-L579","documentation":"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.","triggerScenarios":"math ceil(x) where x is a string, bool, dateTime, or DEFAULT-typed value rather than a numeric predicate/variable.","commonSituations":"Ceiling a string facet value; applying ceil to a datetime predicate; schema changed so the predicate no longer returns floats.","solutions":["Ensure the operand is an int/float typed predicate or numeric variable","Check and fix the predicate's schema type","Convert the value to a number first (e.g. since() for durations) then ceil","Sanity-test with a numeric literal to isolate the bad operand"],"exampleFix":"// before\n\"math ceil(priceAsString)\"\n// after\n\"math ceil(price)\"","handlingStrategy":"type-guard","validationCode":"if (!['int','float'].includes(schemaOf('price'))) throw new Error('ceil needs numeric predicate');","typeGuard":"function isCeilable(v) { return typeof v === 'number'; }","tryCatchPattern":"try {\n  r = await txn.query(q);\n} catch (e) {\n  if (String(e).includes('ceil')) throw new Error('ceil operand must be numeric: ' + e);\n  throw e;\n}","preventionTips":["Check schema types before using ceil","Avoid ceil on string/bool/date predicates","Keep migrations from silently changing predicate types","Add query smoke tests"],"tags":["dgraph","query","math-function","type-mismatch"],"backgroundTag":"math-function-invalid-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}