Skip to content

Commit

Permalink
Add option to compare results with relative error tolerance (apache#1…
Browse files Browse the repository at this point in the history
…5429)

Adds a result comparision mode of EQUALS_RELATIVE_1000_ULPS ; which accepts floating point differences up-to 1000 units of least precision
  • Loading branch information
kgyrtkirk authored and ythorat2 committed Dec 1, 2023
1 parent e2b4cb3 commit 8f9f079
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,36 @@ void validate(int row, int column, ValueType type, Object expectedCell, Object r
EQUALS.validate(row, column, type, expectedCell, resultCell);
}
}
},
/**
* Comparision which accepts 1000 units of least precision.
*/
EQUALS_RELATIVE_1000_ULPS {
static final int ASSERTION_ERROR_ULPS = 1000;

@Override
void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell)
{
if (expectedCell instanceof Float) {
float eps = ASSERTION_ERROR_ULPS * Math.ulp((Float) expectedCell);
assertEquals(
mismatchMessage(row, column),
(Float) expectedCell,
(Float) resultCell,
eps
);
} else if (expectedCell instanceof Double) {
double eps = ASSERTION_ERROR_ULPS * Math.ulp((Double) expectedCell);
assertEquals(
mismatchMessage(row, column),
(Double) expectedCell,
(Double) resultCell,
eps
);
} else {
EQUALS.validate(row, column, type, expectedCell, resultCell);
}
}
};

abstract void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ public void verify(String sql, QueryResults queryResults)
results.sort(new ArrayRowCmp());
expectedResults.sort(new ArrayRowCmp());
}
assertResultsEquals(sql, expectedResults, results);
assertResultsValid(ResultMatchMode.EQUALS_RELATIVE_1000_ULPS, expectedResults, queryResults);
}
catch (AssertionError e) {
log.info("query: %s", sql);
log.info(resultsToString("Expected", expectedResults));
log.info(resultsToString("Actual", results));
throw e;
throw new AssertionError(StringUtils.format("%s while processing: %s", e.getMessage(), sql), e);
}
}

Expand Down Expand Up @@ -1484,7 +1484,6 @@ public void test_frameclause_defaultFrame_RBUPACR_dt_3()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/defaultFrame/RBUPACR_int11")
@Test
public void test_frameclause_defaultFrame_RBUPACR_int11()
Expand Down Expand Up @@ -1772,7 +1771,6 @@ public void test_frameclause_RBUPACR_RBUPACR_dt_3()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/RBUPACR/RBUPACR_int11")
@Test
public void test_frameclause_RBUPACR_RBUPACR_int11()
Expand Down Expand Up @@ -6667,7 +6665,6 @@ public void test_frameclause_defaultFrame_RBUPACR_bgint_3()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/defaultFrame/RBUPACR_bgint_4")
@Test
public void test_frameclause_defaultFrame_RBUPACR_bgint_4()
Expand Down Expand Up @@ -6829,7 +6826,6 @@ public void test_frameclause_defaultFrame_RBUPACR_vchr_5()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/multipl_wnwds/avg_mulwds")
@Test
public void test_frameclause_multipl_wnwds_avg_mulwds()
Expand Down Expand Up @@ -7048,7 +7044,6 @@ public void test_frameclause_RBUPACR_RBUPACR_bgint_3()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/RBUPACR/RBUPACR_bgint_4")
@Test
public void test_frameclause_RBUPACR_RBUPACR_bgint_4()
Expand Down Expand Up @@ -7163,7 +7158,6 @@ public void test_frameclause_RBUPACR_RBUPACR_vchr_5()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/RBUPAUF/RBUPAUF_bgint_4")
@Test
public void test_frameclause_RBUPAUF_RBUPAUF_bgint_4()
Expand Down Expand Up @@ -7262,15 +7256,13 @@ public void test_frameclause_subQueries_frmInSubQry_55()
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/subQueries/frmInSubQry_57")
@Test
public void test_frameclause_subQueries_frmInSubQry_57()
{
windowQueryTest();
}

@NotYetSupported(Modes.RESULT_MISMATCH)
@DrillTest("frameclause/subQueries/frmInSubQry_58")
@Test
public void test_frameclause_subQueries_frmInSubQry_58()
Expand Down Expand Up @@ -7855,15 +7847,13 @@ public void test_nestedAggs_frmclause03()
windowQueryTest();
}

@NotYetSupported(Modes.T_ALLTYPES_ISSUES)
@DrillTest("nestedAggs/frmclause12")
@Test
public void test_nestedAggs_frmclause12()
{
windowQueryTest();
}

@NotYetSupported(Modes.T_ALLTYPES_ISSUES)
@DrillTest("nestedAggs/frmclause16")
@Test
public void test_nestedAggs_frmclause16()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ enum Modes
INCORRECT_SYNTAX(DruidException.class, "Incorrect syntax near the keyword"),
// at least c7 is represented oddly in the parquet file
T_ALLTYPES_ISSUES(AssertionError.class, "(t_alltype|allTypsUniq|fewRowsAllData).parquet.*Verifier.verify"),
RESULT_MISMATCH(AssertionError.class, "assertResultsEquals"),
RESULT_MISMATCH(AssertionError.class, "(assertResultsEquals|AssertionError: column content mismatch)"),
UNSUPPORTED_NULL_ORDERING(DruidException.class, "(A|DE)SCENDING ordering with NULLS (LAST|FIRST)"),
CANNOT_TRANSLATE(DruidException.class, "Cannot translate reference");

Expand Down

0 comments on commit 8f9f079

Please sign in to comment.