Skip to content

Commit 92f027c

Browse files
TeddyCrclaude
andcommitted
fix(dq): seed NUMERIC on the numeric column test definitions
NUMERIC is a distinct member of the column dataType enum and is what BigQuery, Postgres, Snowflake and DB2 numeric columns are ingested as, but the numeric system test definitions only ever listed NUMBER and DECIMAL. The "Add test case" dropdown filters on the column's exact dataType (`TestCaseFormBody` -> `supportedDataType=<column.dataType>`), so on a NUMERIC column the mean/min/max/median/stddev/sum/between tests were not offered at all — only the three definitions that happened to list NUMERIC (missingCount, notNull, unique) showed up. - Seeds: add NUMERIC to the ten column definitions that list NUMBER but not NUMERIC. The three string-only definitions are deliberately untouched. - Migration (2.1.0, MySQL + Postgres): backfill the same ten definitions. `initializeEntity` returns early when the entity exists, so seeding alone only fixes fresh installs. Guarded on NUMERIC being absent, so re-runs are a no-op, and on the array existing, so a definition with no supportedDataTypes — which already means "every data type" — is not narrowed to exactly one. - IT: assert every seeded numeric aggregate definition is returned for NUMERIC, and that a string-only definition still is not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 60ffb14 commit 92f027c

13 files changed

Lines changed: 87 additions & 10 deletions

bootstrap/sql/migrations/native/2.1.0/mysql/postDataMigrationSQLScript.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ WHERE name IN (
236236
'"dimensionFailurePolicy"'
237237
);
238238

239+
-- NUMERIC is a distinct member of the column dataType enum and is what BigQuery, Postgres,
240+
-- Snowflake and DB2 numeric columns are ingested as, but the numeric system test definitions were
241+
-- only ever seeded with NUMBER/DECIMAL. The "Add test case" dropdown filters on the column's exact
242+
-- dataType, so mean/min/max/median/stddev/sum were unreachable on any NUMERIC column. Seeding only
243+
-- covers fresh installs (initializeEntity returns early when the entity exists), hence this
244+
-- backfill. The guard on NUMERIC being absent keeps re-runs a no-op, and it also skips a definition
245+
-- with no supportedDataTypes at all -- that already means "every data type" (issue #27718), so
246+
-- appending to it would narrow it to exactly one.
247+
UPDATE test_definition
248+
SET json = JSON_ARRAY_APPEND(json, '$.supportedDataTypes', 'NUMERIC')
249+
WHERE name IN (
250+
'columnValueMaxToBeBetween', 'columnValueMeanToBeBetween', 'columnValueMedianToBeBetween',
251+
'columnValueMinToBeBetween', 'columnValueStdDevToBeBetween',
252+
'columnValuesToBeAtExpectedLocation', 'columnValuesSumToBeBetween', 'columnValuesToBeBetween',
253+
'columnValuesToBeInSet', 'columnValuesToBeNotInSet'
254+
)
255+
AND NOT JSON_CONTAINS(json, JSON_QUOTE('NUMERIC'), '$.supportedDataTypes');
256+
239257
-- Normalize user emails to lowercase: email is the primary identity lookup key and the
240258
-- application always compares lowercased values. The case-insensitive unique key on email
241259
-- guarantees no collisions can result from lowercasing.

bootstrap/sql/migrations/native/2.1.0/postgres/postDataMigrationSQLScript.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,29 @@ WHERE name IN (
214214
)
215215
AND NOT ((json->'parameterDefinition')::jsonb @> '[{"name": "dimensionFailurePolicy"}]'::jsonb);
216216

217+
-- NUMERIC is a distinct member of the column dataType enum and is what BigQuery, Postgres,
218+
-- Snowflake and DB2 numeric columns are ingested as, but the numeric system test definitions were
219+
-- only ever seeded with NUMBER/DECIMAL. The "Add test case" dropdown filters on the column's exact
220+
-- dataType, so mean/min/max/median/stddev/sum were unreachable on any NUMERIC column. Seeding only
221+
-- covers fresh installs (initializeEntity returns early when the entity exists), hence this
222+
-- backfill. The guard on NUMERIC being absent keeps re-runs a no-op, and it also skips a definition
223+
-- with no supportedDataTypes at all -- that already means "every data type" (issue #27718), so
224+
-- appending to it would narrow it to exactly one.
225+
UPDATE test_definition
226+
SET json = jsonb_set(
227+
json::jsonb,
228+
'{supportedDataTypes}',
229+
(json->'supportedDataTypes')::jsonb || '["NUMERIC"]'::jsonb
230+
)
231+
WHERE name IN (
232+
'columnValueMaxToBeBetween', 'columnValueMeanToBeBetween', 'columnValueMedianToBeBetween',
233+
'columnValueMinToBeBetween', 'columnValueStdDevToBeBetween',
234+
'columnValuesToBeAtExpectedLocation', 'columnValuesSumToBeBetween', 'columnValuesToBeBetween',
235+
'columnValuesToBeInSet', 'columnValuesToBeNotInSet'
236+
)
237+
AND json->'supportedDataTypes' IS NOT NULL
238+
AND NOT ((json->'supportedDataTypes')::jsonb @> '["NUMERIC"]'::jsonb);
239+
217240
-- Normalize user emails to lowercase: email is the primary identity lookup key and the
218241
-- application always compares lowercased values. No collision guard is needed -- the 1.5.0
219242
-- migration already deleted rows duplicated by LOWER(email) and lowercased the survivors, and

openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/TestDefinitionResourceIT.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public class TestDefinitionResourceIT extends BaseEntityIT<TestDefinition, Creat
4343
List.of("COLUMN", "Column", "column", " Column ");
4444
private static final List<String> BLANK_ENTITY_TYPES = List.of("", " ");
4545
private static final int ENTITY_TYPE_FILTER_LIMIT = 1000000;
46+
private static final List<String> NUMERIC_AGGREGATE_DEFINITIONS =
47+
List.of(
48+
"columnValueMaxToBeBetween",
49+
"columnValueMeanToBeBetween",
50+
"columnValueMedianToBeBetween",
51+
"columnValueMinToBeBetween",
52+
"columnValueStdDevToBeBetween",
53+
"columnValuesSumToBeBetween");
54+
private static final String REGEX_DEFINITION = "columnValuesToMatchRegex";
4655

4756
// Disable tests that don't apply to TestDefinition
4857
{
@@ -363,6 +372,33 @@ void list_supportedDataTypeFilterKeepsDefinitionsWithoutDataTypes_200_OK(TestNam
363372
+ " separate listCount query");
364373
}
365374

375+
/**
376+
* NUMERIC is what BigQuery, Postgres, Snowflake and DB2 numeric columns are ingested as, but the
377+
* seeded aggregate definitions only ever listed NUMBER and DECIMAL. Since the listing filters on
378+
* the column's exact data type, none of mean/min/max/median/stddev/sum could be picked for a
379+
* NUMERIC column.
380+
*/
381+
@Test
382+
void list_supportedDataTypeNumericReturnsSeededAggregateDefinitions_200_OK() {
383+
Set<String> fullyQualifiedNames =
384+
fullyQualifiedNamesOf(
385+
listBySupportedDataType(SdkClients.adminClient(), ColumnDataType.NUMERIC.value())
386+
.getData());
387+
388+
assertTrue(
389+
fullyQualifiedNames.containsAll(NUMERIC_AGGREGATE_DEFINITIONS),
390+
() ->
391+
"Every seeded numeric aggregate definition must be offered for a NUMERIC column, missing: "
392+
+ NUMERIC_AGGREGATE_DEFINITIONS.stream()
393+
.filter(name -> !fullyQualifiedNames.contains(name))
394+
.collect(Collectors.joining(", ")));
395+
assertFalse(
396+
fullyQualifiedNames.contains(REGEX_DEFINITION),
397+
REGEX_DEFINITION
398+
+ " only supports string types, so returning it for NUMERIC would mean the filter"
399+
+ " stopped discriminating rather than that the data types were corrected");
400+
}
401+
366402
private static ListResponse<TestDefinition> listBySupportedDataType(
367403
OpenMetadataClient client, String supportedDataType) {
368404
ListParams params =

openmetadata-service/src/main/resources/json/data/tests/columnValueMaxToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValueMaxToBeBetween. Test the maximum value in a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata", "dbt"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForMaxInCol",

openmetadata-service/src/main/resources/json/data/tests/columnValueMeanToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValueMeanToBeBetween. Test the mean value in a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT", "ARRAY", "SET"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT", "ARRAY", "SET"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForMeanInCol",

openmetadata-service/src/main/resources/json/data/tests/columnValueMedianToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValueMedianToBeBetween. Test the median value in a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForMedianInCol",

openmetadata-service/src/main/resources/json/data/tests/columnValueMinToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValueMinToBeBetween. Test the minimum value in a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForMinInCol",

openmetadata-service/src/main/resources/json/data/tests/columnValueStdDevToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValueStdDevToBeBetween. Test the std. dev. value in a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForStdDevInCol",

openmetadata-service/src/main/resources/json/data/tests/columnValueToBeAtExpectedLocation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValuesToBeAtExpectedLocation. Test the lat/long values in a column to be at the specified location in the reference column.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["BYTES", "STRING", "MEDIUMTEXT", "TEXT", "CHAR", "VARCHAR","NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["BYTES", "STRING", "MEDIUMTEXT", "TEXT", "CHAR", "VARCHAR","NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "locationReferenceType",

openmetadata-service/src/main/resources/json/data/tests/columnValuesSumToBeBetween.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "This schema defines the test ColumnValuesSumToBeBetween. Test the sum of the values of a col is within a range.",
66
"entityType": "COLUMN",
77
"testPlatforms": ["OpenMetadata"],
8-
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
8+
"supportedDataTypes": ["NUMBER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC", "TINYINT", "SMALLINT", "BIGINT", "BYTEINT"],
99
"parameterDefinition": [
1010
{
1111
"name": "minValueForColSum",

0 commit comments

Comments
 (0)