{"record":{"id":"ab7f05bddea3f009","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-ab7f05","errorCode":null,"errorMessage":"Wrong type %v encountered for func -","messagePattern":"Wrong type (.+?) encountered for func -","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":188,"sourceCode":"\t\tif !ok {\n\t\t\treturn ErrorArgsDisagree\n\t\t}\n\t\tif len(aVal) != len(bVal) {\n\t\t\treturn ErrorVectorsNotMatch\n\t\t}\n\t\tcVal := make([]float32, len(aVal))\n\t\tfor i := range aVal {\n\t\t\tcVal[i] = aVal[i] - bVal[i]\n\t\t}\n\t\tc.Value = cVal\n\n\tcase BIGFLOAT:\n\t\taVal, bVal := a.Value.(big.Float), b.Value.(big.Float)\n\t\taVal.Sub(&aVal, &bVal)\n\t\tc.Value = aVal\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func -\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applyMul(a, b, c *types.Val) error {\n\t// Possible input combinations:\n\t//   INT * INT\n\t//   FLOAT * FLOAT\n\t//   FLOAT * VFLOAT\n\t//   VFLOAT * FLOAT\n\t// Other combinations should have been eliminated via matchType.\n\t// Some operations, such as INT * FLOAT might be allowed conceptually,\n\t// but we would have already cast the INT value to a FLOAT in the\n\t// matchType invocation.\n\tlValType := getValType(a)\n\trValType := getValType(b)\n\tswitch lValType {\n\tcase INT:","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L170-L206","documentation":"applySub returns this error when a subtraction (-) operand has DEFAULT type, meaning the value is untyped or unsupported for arithmetic. Subtraction requires int/float/bigfloat typed values; DEFAULT signals missing type metadata on the operand.","triggerScenarios":"math(\"-\", a, b) evaluates where an operand's Tid is DEFAULT — typically an untyped predicate value, an empty value, or a value that failed upstream type conversion.","commonSituations":"Subtracting values from predicates lacking a schema type; date/time arithmetic attempted with untyped values; queries over partially loaded or empty data.","solutions":["Add a concrete scalar type to the predicate's schema before doing math","Validate operands are numeric before the subtraction expression","Handle empty/missing values with filters or conditional logic in the query"],"exampleFix":"// before\nmath(a - b) // b: DEFAULT type\n// after\n// schema: b: float .\nmath(a - b) // now valid once b is stored as float","handlingStrategy":"validation","validationCode":"func isSubtractable(a, b types.Val) bool {\n    t := getValType(a)\n    return t == INT || t == FLOAT || t == BIGFLOAT\n}","typeGuard":"func hasNumericTid(v types.Val) bool {\n    t := getValType(&v)\n    return t != DEFAULT && (t == INT || t == FLOAT || t == BIGFLOAT)\n}","tryCatchPattern":"if err := applySub(a, b, c); err != nil {\n    if strings.Contains(err.Error(), \"func -\") {\n        return fmt.Errorf(\"operand type %v not supported for -; ensure values are typed numerics\", a.Tid)\n    }\n    return err\n}","preventionTips":["Declare int/float schema types for subtracted predicates","Avoid date arithmetic on untyped values; use typed datetime predicates","Filter empty/missing values before subtraction","Validate bulk-loaded numeric fields are stored with a type"],"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"}