{"record":{"id":"76b5ea611a5cc4b4","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-floor","errorCode":null,"errorMessage":"Wrong type %v encountered for func floor","messagePattern":"Wrong type (.+?) encountered for func floor","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":541,"sourceCode":"\treturn nil\n}\n\nfunc applyFloor(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.Floor(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.Floor(f)).SetPrec(types.BigFloatPrecision)\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func floor\", a.Tid)\n\t}\n\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","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L523-L559","documentation":"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.","triggerScenarios":"math floor(x) with x being a string, bool, dateTime, or otherwise non-numeric typed value from a predicate or variable.","commonSituations":"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.","solutions":["Confirm the argument predicate is numeric in the schema","Use since(dt) or other numeric-producing functions before applying floor","Filter out non-numeric values before aggregation","Replace floor with the correct function if a non-numeric transform was intended"],"exampleFix":"// before\n\"math floor(createdAt)\"\n// after\n\"math floor(since(createdAt))\"","handlingStrategy":"type-guard","validationCode":"if (schemaOf('score') !== 'float' && schemaOf('score') !== 'int') throw new Error('floor needs numeric');","typeGuard":"function isFloorable(v) { return typeof v === 'number'; }","tryCatchPattern":"try {\n  r = await txn.query(q);\n} catch (e) {\n  if (String(e).includes('func floor')) { /* switch to numeric source or since() */ }\n  throw e;\n}","preventionTips":["Never apply floor to dateTime; use since() first","Validate predicate types against the schema","Test math expressions with real data samples","Document which predicates are numeric"],"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"}