diff
The diff
method returns the differences between two provided tables as a string. If the two tables are the same, an empty string is returned.
This method starts by comparing the table sizes and then the schema of the two tables, such as the number of columns, column names, column types, and column orders. If the schemas differ, the comparison stops, and the differences are returned. If the schemas are the same, the method compares the table data. The method compares the table data column by column (not row by row) and only records the first difference found in each column.
Note that inexact comparison of floating numbers may sometimes be desirable due to their inherent imprecision.
Syntax
diff(actualResult, expectedResult, maxDiffLines)
diff(actualResult, expectedResult, maxDiffLines, itemsToSkip)
Parameters
Parameter | Type | Description |
---|---|---|
actualResult | Table | The table to compare. |
expectedResult | Table | The table to compare |
maxDiffLines | long | The maximum number of differences to return. |
itemsToSkip | EnumSet<TableDiff.DiffItems> | EnumSet of checks not to perform.
|
Returns
The differences between actualResult
and expectedResult
as a string.
Examples
In the following example, we use the diff
method to compare two tables.
t1 = emptyTable(10).update("A = i", "B = i", "C = i")
t2 = emptyTable(10).update("A = i", "C = i % 2 == 0? i: i + 1", "C = i % 2 == 0? i + 1: i")
d = diff(t1, t2, 10).split("\n")
println d
- Log
Here, we have two identical tables, except that table t2
swaps columns B
and C
. We'll use the itemsToSkip
parameter to ignore the column order.
import io.deephaven.engine.util.TableDiff.DiffItems
t1 = emptyTable(10).update("A = i", "B = i", "C = i")
t2 = emptyTable(10).update("A = i", "C = i", "B = i")
d = diff(t1, t2, 10, EnumSet.of(DiffItems.valueOf("ColumnsOrder")))
d2 = diff(t1, t2, 10)
println "d:" + d
println "d2: \n" + d2
- Log