{"record":{"id":"400815f09761df70","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-log","errorCode":null,"errorMessage":"Wrong type %v encountered for func log","messagePattern":"Wrong type (.+?) encountered for func log","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":378,"sourceCode":"\tcase INT:\n\t\tif a.Value.(int64) < 0 || b.Value.(int64) < 0 {\n\t\t\treturn ErrorNegativeLog\n\t\t} else if b.Value.(int64) == 1 {\n\t\t\treturn ErrorDivisionByZero\n\t\t}\n\t\tc.Value = math.Log(float64(a.Value.(int64))) / math.Log(float64(b.Value.(int64)))\n\t\tc.Tid = types.FloatID\n\n\tcase FLOAT:\n\t\tif a.Value.(float64) < 0 || b.Value.(float64) < 0 {\n\t\t\treturn ErrorNegativeLog\n\t\t} else if b.Value.(float64) == 1 {\n\t\t\treturn ErrorDivisionByZero\n\t\t}\n\t\tc.Value = math.Log(a.Value.(float64)) / math.Log(b.Value.(float64))\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func log\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applyMin(a, b, c *types.Val) error {\n\tr, err := types.Less(*a, *b)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif r {\n\t\t*c = *a\n\t\treturn nil\n\t}\n\t*c = *b\n\treturn nil\n}\n\nfunc applyMax(a, b, c *types.Val) error {","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L360-L396","documentation":"applyLog returns this error when a logarithm (log) operand has DEFAULT type. Log requires float-typed numeric values; DEFAULT means the operand is untyped or its bytes cannot be interpreted as a number. Log of base 0/1 or non-positive values raise separate domain errors.","triggerScenarios":"math(\"log\", a, b) evaluates where an operand's Tid is DEFAULT — e.g. taking log of an untyped predicate value or a value whose earlier conversion failed.","commonSituations":"Log-scaled scoring on predicates without a declared float type; computing log over string-stored numerics; empty optional values flowing into math().","solutions":["Declare the predicate as float in the schema","Ensure operands are positive numerics stored with a float type","Filter or default missing values before applying log"],"exampleFix":"// before\nmath(log(rating)) // rating: DEFAULT\n// after\n// schema: rating: float .\nmath(log(rating))","handlingStrategy":"validation","validationCode":"func isLogOperand(v types.Val) bool {\n    t := getValType(&v)\n    if t != INT && t != FLOAT { return false }\n    f, ok := v.Value.(float64)\n    return ok && f > 0\n}","typeGuard":"func canLog(a, b types.Val) bool {\n    return isLogOperand(a) && (isLogOperand(b) || b.Value == nil)\n}","tryCatchPattern":"if err := applyLog(a, b, c); err != nil {\n    if strings.Contains(err.Error(), \"func log\") {\n        return fmt.Errorf(\"operand type %v not supported for log; declare float schema type\", a.Tid)\n    }\n    return err // includes log(0) / base 1 domain errors\n}","preventionTips":["Declare float schema types for log-transformed predicates","Ensure operands are strictly positive before log","Default or filter missing/zero values before applying log","Avoid log over string-stored numbers; store as float"],"tags":["query","math","type-conversion"],"backgroundTag":"wrong-operand-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}