diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManager.java b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManager.java index 0e98417748f..f805967cbae 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManager.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManager.java @@ -121,7 +121,7 @@ protected String getColumnExpression(ValueType valueType, String columnExpressio return getCastExpression(columnExpression, NUMERIC_REGEXP, sqlBuilder.dataTypeBigInt()); } else if (valueType.isBoolean()) { return sqlBuilder.ifThenElse( - columnExpression + " = 'true", "1", columnExpression + " = 'false'", "0", "null"); + columnExpression + " = 'true'", "1", columnExpression + " = 'false'", "0", "null"); } else if (valueType.isDate()) { return getCastExpression(columnExpression, DATE_REGEXP, sqlBuilder.dataTypeTimestamp()); } else if (valueType.isGeo() && isSpatialSupport()) { diff --git a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManagerTest.java b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManagerTest.java index a4ea5e5fa65..b26200ffb39 100644 --- a/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManagerTest.java +++ b/dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/AbstractEventJdbcTableManagerTest.java @@ -74,7 +74,7 @@ void testGetCastExpression() { """ case when eventdatavalues #>> '{GieVkTxp4HH, value}' ~* '^(-?[0-9]+)(\\.[0-9]+)?$' \ then cast(eventdatavalues #>> '{GieVkTxp4HH, value}' as double precision) \ - else null end"""; + end"""; String actual = manager.getCastExpression( @@ -91,7 +91,7 @@ void testGetSelectExpressionNumber() { """ case when eventdatavalues #>> '{GieVkTxp4HH, value}' ~* '^(-?[0-9]+)(\\.[0-9]+)?$' \ then cast(eventdatavalues #>> '{GieVkTxp4HH, value}' as double precision) \ - else null end"""; + end"""; String actual = manager.getColumnExpression(ValueType.NUMBER, "eventdatavalues #>> '{GieVkTxp4HH, value}'"); @@ -103,7 +103,9 @@ then cast(eventdatavalues #>> '{GieVkTxp4HH, value}' as double precision) \ void testGetSelectExpressionBoolean() { String expected = """ - case when eventdatavalues #>> '{Xl3voRRcmpo, value}' = 'true' then 1 when eventdatavalues #>> '{Xl3voRRcmpo, value}' = 'false' then 0 else null end"""; + case when eventdatavalues #>> '{Xl3voRRcmpo, value}' = 'true' then 1 \ + when eventdatavalues #>> '{Xl3voRRcmpo, value}' = 'false' then 0 \ + else null end"""; String actual = manager.getColumnExpression( @@ -118,7 +120,7 @@ void testGetSelectExpressionDate() { """ case when eventdatavalues #>> '{AL04Wbutskk, value}' ~* '^\\d{4}-\\d{2}-\\d{2}(\\s|T)?((\\d{2}:)(\\d{2}:)?(\\d{2}))?(|.(\\d{3})|.(\\d{3})Z)?$' \ then cast(eventdatavalues #>> '{AL04Wbutskk, value}' as timestamp) \ - else null end"""; + end"""; String actual = manager.getColumnExpression(ValueType.DATE, "eventdatavalues #>> '{AL04Wbutskk, value}'");