From e4b31f9d6580ed1db46f37baf13b94c5aae5ec4b Mon Sep 17 00:00:00 2001 From: Teddy Date: Thu, 18 Jul 2024 16:47:05 +0200 Subject: [PATCH] fix: supportedDataType PSQL query (#17069) --- .../openmetadata/service/jdbi3/CollectionDAO.java | 15 +++++++++------ .../dqtests/TestDefinitionResourceTest.java | 11 +++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index 0a424b15394..d12d43203c5 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -3688,8 +3688,9 @@ public interface CollectionDAO { if (supportedDataType != null) { filter.queryParams.put("supportedDataTypeLike", String.format("%%%s%%", supportedDataType)); - mysqlCondition.append("AND supported_data_types LIKE :supportedDataTypeLike"); - psqlCondition.append("AND supported_data_types @> :supportedDataTypeLike "); + mysqlCondition.append( + "AND json_extract(json, '$.supportedDataTypes') LIKE :supportedDataTypeLike "); + psqlCondition.append("AND json->>'supportedDataTypes' LIKE :supportedDataTypeLike "); } return listBefore( @@ -3731,8 +3732,9 @@ public interface CollectionDAO { if (supportedDataType != null) { filter.queryParams.put("supportedDataTypeLike", String.format("%%%s%%", supportedDataType)); - mysqlCondition.append("AND supported_data_types LIKE :supportedDataTypeLike"); - psqlCondition.append("AND supported_data_types @> :supportedDataTypeLike "); + mysqlCondition.append( + "AND json_extract(json, '$.supportedDataTypes') LIKE :supportedDataTypeLike "); + psqlCondition.append("AND json->>'supportedDataTypes' LIKE :supportedDataTypeLike "); } return listAfter( @@ -3774,8 +3776,9 @@ public interface CollectionDAO { if (supportedDataType != null) { filter.queryParams.put("supportedDataTypeLike", String.format("%%%s%%", supportedDataType)); - mysqlCondition.append("AND supported_data_types LIKE :supportedDataTypeLike"); - psqlCondition.append("AND supported_data_types @> :supportedDataTypeLike "); + mysqlCondition.append( + "AND json_extract(json, '$.supportedDataTypes') LIKE :supportedDataTypeLike "); + psqlCondition.append("AND json->>'supportedDataTypes' LIKE :supportedDataTypeLike "); } return listCount( getTableName(), diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java index 11e85e7aaa1..4e62a052d85 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestDefinitionResourceTest.java @@ -21,6 +21,7 @@ import org.openmetadata.schema.api.tests.CreateTestDefinition; import org.openmetadata.schema.tests.TestCaseParameter; import org.openmetadata.schema.tests.TestDefinition; import org.openmetadata.schema.tests.TestPlatform; +import org.openmetadata.schema.type.ColumnDataType; import org.openmetadata.schema.type.TestDefinitionEntityType; import org.openmetadata.service.Entity; import org.openmetadata.service.resources.EntityResourceTest; @@ -51,6 +52,16 @@ public class TestDefinitionResourceTest "columnValuesMissingCount", "owner", ADMIN_AUTH_HEADERS); } + @Test + void list_testDefinitionsForBoolType(TestInfo test) throws HttpResponseException { + Map params = Map.of("supportedDataType", "BOOLEAN"); + ResultList testDefinitions = listEntities(params, ADMIN_AUTH_HEADERS); + boolean b = + testDefinitions.getData().stream() + .allMatch(t -> t.getSupportedDataTypes().contains(ColumnDataType.BOOLEAN)); + Assertions.assertTrue(b); + } + @Test void post_testDefinitionWithoutRequiredFields_4xx(TestInfo test) { // Test Platform is required field