{"record":{"id":"f6423f9355160d1d","repo":"prestodb/presto","slug":"row-comparison-not-supported-for-fields-with-null","errorCode":null,"errorMessage":"ROW comparison not supported for fields with null elements","messagePattern":"ROW comparison not supported for fields with null elements","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/RowType.java","lineNumber":345,"sourceCode":"        return 0;\n    }\n\n    @Override\n    public long hash(Block block, int position)\n    {\n        Block arrayBlock = block.getBlock(position);\n        long result = 1;\n        for (int i = 0; i < arrayBlock.getPositionCount(); i++) {\n            Type elementType = fields.get(i).getType();\n            result = 31 * result + TypeUtils.hashPosition(elementType, arrayBlock, i);\n        }\n        return result;\n    }\n\n    private static void checkElementNotNull(boolean isNull)\n    {\n        if (isNull) {\n            throw new NotSupportedException(\"ROW comparison not supported for fields with null elements\");\n        }\n    }\n}\n","sourceCodeStart":327,"sourceCodeEnd":349,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/RowType.java#L327-L349","documentation":"RowType comparison/equality refuses to compare ROW values whose fields contain null elements: checkElementNotNull throws NotSupportedException(\"ROW comparison not supported for fields with null elements\"). SQL semantics for comparing rows with nulls are undefined here, so the library fails explicitly rather than returning a possibly wrong result.","triggerScenarios":"Calling RowType.equalTo or RowType.compareTo on two rows where any corresponding element is NULL (isNull(i) true).","commonSituations":"GROUP BY / DISTINCT / equality checks on ROW columns with nullable members; ORDER BY on struct columns containing NULLs; joins on row-typed keys where fields can be null.","solutions":["Use COALESCE/null-safe semantics: IS NOT DISTINCT FROM or fill nulls with sentinel values before comparison.","Flatten the row and use IS DISTINCT FROM per field instead of comparing whole rows.","Rewrite the query so comparison keys exclude nullable components."],"exampleFix":"// before\nWHERE row_col = ROW(1, NULL)\n// after\nWHERE row_col IS NOT DISTINCT FROM CAST(ROW(1, NULL) AS ROW(int, int))","handlingStrategy":"validation","validationCode":"if (row.isNull(i)) { /* resolve nulls before comparison */ }","typeGuard":"boolean isComparableRow(Block a, Block b) { for (int i = 0; i < a.getPositionCount(); i++) { if (a.isNull(i) || b.isNull(i)) return false; } return true; }","tryCatchPattern":"try { rowType.equalTo(left, right); } catch (NotSupportedException e) { /* treat as not-equal or use IS NOT DISTINCT FROM semantics */ }","preventionTips":["Use IS NOT DISTINCT FROM / null-safe comparisons on ROW columns.","COALESCE null fields to sentinels before struct comparisons.","Avoid nullable fields in join/group-by keys of type ROW."],"tags":["comparison","null","row-type","unsupported"],"backgroundTag":"row-comparison-null-elements","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}