2017-08-31 57 views
0

最重要的是的DbUnit:设置容差值 - 比较的SQL Server VS SAP HANA

DB单位在78行,返回一个双重价值的差异:

Exception in thread "main" junit.framework.ComparisonFailure: value (table=dataset, row=78, col=DirtyValue) expected:<49.27291950[7]> but was:<49.27291950[6]> 

所以我认为SQL Server返回49.272919507而HANA返回49.272919506
(基于答案JUnit assertEquals Changes String

然后我试图设置TOLER根据常见问题Is there an equivalent to JUnit's assertEquals(double expected, double actual, double delta) to define a tolerance level when comparing numeric values?

但我仍然得到同样的错误 - 任何想法?

信息

也许这就是原因:?

[main] WARN org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'Microsoft SQL Server' (e.g. some datatypes may not be supported properly). In rare cases you might see this message because the list of supported database products is incomplete (list=[derby]). If so please request a java-class update via the forums.If you are using your own IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override getValidDbProducts() to specify the supported database products. 
[main] WARN org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The configured data type factory 'class org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems with the current database 'HDB' (e.g. some datatypes may not be supported properly). In rare cases you might see this message because the list of supported database products is incomplete (list=[derby]). If so please request a java-class update via the forums.If you are using your own IDataTypeFactory extending DefaultDataTypeFactory, ensure that you override getValidDbProducts() to specify the supported database products. 
  • DbUnit的版本2.5.4
  • DirtyValue从3个瓦莱斯在这两个系统计算

SQL服务器

SELECT TypeOfGroup, Segment, Portfolio, UniqueID, JobId, DirtyValue, PosUnits, FX_RATE, THEO_Value 
FROM DATASET_PL 
order by JobId, TypeOfGroup, Segment, Portfolio, UniqueID COLLATE Latin1_General_bin 

HANA

SELECT "TypeOfGroup", "Segment", "Portfolio", "UniqueID", "JobId", "DirtyValue", Pos_Units as "PosUnits", FX_RATE, THEO_Value as "THEO_Value" 
FROM "_SYS_BIC"."meag.app.h4q.metadata.dataset.pnl/06_COMPARE_CUBES_AND_CALC_ATTR" 
order by "JobId", "TypeOfGroup", "Segment", "Portfolio", "UniqueID" 
+0

您能否提供测试定义以及您使用的DB单元版本?此外,所涉及的数据定义可能有助于理解差异来自何处。最终,您可能希望在两个平台上获得相同的结果,而不管双“实现”。 –

回答

0

变通

使用diffhandler和处理分歧存在:“任何想法”

DiffCollectingFailureHandler diffHandler = new DiffCollectingFailureHandler(); 
Assertion.assertEquals(expectedTable, actualTable); 

List<Difference> diffList = diffHandler.getDiffList(); 
for (Difference diff: diffList) { 
    if (diff.getColumnName().equals("DirtyValue")) { 
     double actual = (double) diff.getActualValue(); 
     double expected = (double) diff.getExpectedValue(); 
     if (Math.abs(Math.abs(actual) - Math.abs(expected)) > 0.00001) { 
      logDiff(diff); 
     } else { 
      logDebugDiff(diff); 
     } 
    } else { 
     logDiff(diff); 
    } 
} 

private void logDiff(Difference diff) { 
    logger.error(String.format("Diff found in row:%s, col:%s expected:%s, actual:%s", diff.getRowIndex(), diff.getColumnName(), diff.getExpectedValue(), diff.getActualValue())); 
} 

private void logDebugDiff(Difference diff) { 
    logger.debug(String.format("Diff found in row:%s, col:%s expected:%s, actual:%s", diff.getRowIndex(), diff.getColumnName(), diff.getExpectedValue(), diff.getActualValue())); 
} 
0

的问题是,也许它有助于理解为什么差异occurrs。

如果需要,HANA会截断,请参阅"HANA SQL and System Views Reference", numeric types。在HANA以下语句导致123.45:

select cast('123.456' as decimal(6,2)) from dummy; 

SQL-服务器轮如果需要的话,至少如果目标数据类型是数字的,参见例如here在“截断和舍入结果”。 SQL-Server中的上述SQL语句的结果为123.46。

而SQL标准似乎让它打开,无论是舍入还是截断,请参见answer on SO。 我不知道有任何更改HANA中的舍入行为的设置,但也许有。

+0

这是有用的信息的原因 - THX到目前为止。然而,问题是如何让DbUnit很好地忽略小于.00001 –

+0

的差异,绝对epsilon为0。00001比较增量时,你会遇到同样的问题时,使用较低的精度,但可能与你的用例无关。 –