Data Diff
The API documentation for creating comparing datasets programmatically using Data Diff.
Creating a new Diff
This method creates a new data diff job asynchronously and returns the id
that can later be used to retrieve the diff results.
Endpoint
/api/v1/datadiffs
Method
POST
Request Content-Type
application/json
Response Content-Type
application/json
Example request body:
Parameter
Required
Type
Description
data_source1_id
required
integer
Id of data source. You can look it up in Datafold UI: Settings -> Data Sources -> Connection, it'll be the last number in the URL.
data_source2_id
required
integer
Id of the second datasource. It should be the same as data_source1_id
, unless you are doing cross-database diffs
table1
[string]
Use the table as the first datasource. Table is specified as a list of segments. Names are case-sensitive.
query1
string
Use provided query as the first datasource. Either table1
, or query1
must be specified.
table2
[string]
Use this table as the second data source.
query2
string
Use the query as the second data source. Either table2
or query2
must be specified.
materialize_dataset1
optional
bool
Force materialization of dataset 1. It's useful if table1
is a view and it needs to be materialized prior to diffing. If a query is used as a dataset, then this flag is ignored.
materialize_dataset2
optional
bool
Force materialization of dataset 2.
pk_columns
required
[string]
List of primary key columns. It's case-sensitive.
include_columns
optional
[string]
Include only specified columns, besides PK columns.
exclude_columns
optional
[string]
Exclude those columns from diff. Useful for excluding data transfer timestamps and such.
time_column
optional
string
Time column to use for DataDiff time view.
filter1
optional
string
SQL filter for dataset 1. It'll be injected as-is to WHERE clauses during diffing.
filter2
optional
string
SQL filter for dataset 2.
time_travel_point1
optional
string
Relative using a negative integer (ex. -220) for an offset in seconds.
At a certain point in time using a timestamp (ex. 2021-08-13T00:00:00)
At a certain statement using the query id.
At a certain point in time using a timestamp (ex. 2021-08-13T00:00:00)
time_travel_point2
optional
string
Same as the abovementioned, for the second data source.
sampling_tolerance
optional
float
Ratio of acceptable number of rows that can be different to the total number of rows. Used only in sampling.
sampling_confidence
optional
float
Confidence that number of differing rows is less than allowed by sampling_tolerance, in percents. E.g. 99.9
.
diff_tolerances_per_column
optional
[object]
List of objects to configure tolerance value per column.
diff_tolerances_per_column.
column_name
required
string
The name of the column to which the tolerance applies. Must be of type integer or float, ignored otherwise.
diff_tolerances_per_column.
tolerance_value
required
float
The value applied to the tolerance.
diff_tolerances_per_column.
tolerance_mode
required
string
The tolerance mode to apply.
absolute
: abs(b-a) < X
relative
: abs((b-a) / a) < X
Getting Diff Results
This method retrieves results of previously created data diff.
Endpoint
/api/v1/datadiffs/<id>/summary_results
Method
GET
Response Content-Type
application/json
Immediately after the diff is submitted, the status will be either waiting
for processing
:
When the diff task is done, the status will be set to done
and additional fields will contain high-level statistics:
Field Path
Description
schema.columns_mismatched
The number of columns across both datasets compared that didn't match. Datafold matches columns by name and type.
schema.column_type_mismatches
The number of columns across both datasets compared that had a matching name but different types.
schema.column_reorders
The approximate number of columns that were reordered (changed the ordinal position between datasets)
schema.column_counts
Column counts in each dataset that were considered for diffing (after include/exclude filters)
pks.total_rows
The total number of rows in each dataset.
pks.nulls
The number of NULL
primary keys in each dataset. In the case of a composite primary key, if any part of it is NULL
, then the whole key is counted as NULL
.
pks.dupes
The number of rows that have duplicate primary keys for each dataset.
pks.exclusives
The number of primary keys that are exclusive to the first and the second dataset.
pks.distincts
The number of distinct primary keys in each dataset.
values.total_rows
The total number of rows for which value comparison was done. Rows with exclusive, duplicate, and null primary keys are excluded from the comparison.
values.compared_columns
The number of columns that were compared between datasets (not counting primary keys). Mismatched columns (different names or types) are not compared.
values.total_values
The number of values (individual dataset cells) that were compared, excluding primary keys.
values.rows_with_differences
The number of rows with at least one value different between the datasets.
values.columns_with_differences
The number of columns with at least one value different between the datasets.
values.values_with_differences
The number of individual cells across both rows and columns that are different between datasets.
In case of error status
will be set to failed
and the message
field will contain error description:
Example: using DataDiff with curl
Example: using DataDiff with Python and requests lib
Last updated
Was this helpful?