Skip to content

Commit

Permalink
Fix unit tests for rendering negative values sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrczarnas committed Jun 13, 2024
1 parent 1565793 commit 48099aa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ void renderSensor_whenErrorSamplingForProfilingNoTimeSeriesNoDataStream_thenRend
FROM
`%2$s`.`%3$s`.`%4$s` AS analyzed_table
WHERE (%5$s)
AND (NOT (%1$s >= 29 AND %1$s <= 30))
AND (%1$s IS NOT NULL AND NOT (%1$s >= 29 AND %1$s <= 30))
LIMIT 10""";

Assertions.assertEquals(String.format(target_query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ void renderSensor_whenProfilingNoTimeSeriesNoDataStream_thenRendersCorrectSql()
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value
FROM `%s`.`%s`.`%s` AS analyzed_table
WHERE (%s)""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -133,8 +132,8 @@ void renderSensor_whenProfilingOneTimeSeriesNoDataStream_thenRendersCorrectSql()
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`date` AS time_period,
Expand All @@ -145,7 +144,6 @@ void renderSensor_whenProfilingOneTimeSeriesNoDataStream_thenRendersCorrectSql()
ORDER BY time_period, time_period_utc""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -163,15 +161,14 @@ void renderSensor_whenMonitoringDefaultTimeSeriesNoDataStream_thenRendersCorrect
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value
FROM `%s`.`%s`.`%s` AS analyzed_table
WHERE (%s)""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -189,8 +186,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesNoDataStream_thenRendersCorrec
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`date` AS time_period,
Expand All @@ -203,7 +200,6 @@ void renderSensor_whenPartitionedDefaultTimeSeriesNoDataStream_thenRendersCorrec
ORDER BY time_period, time_period_utc""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -226,8 +222,8 @@ void renderSensor_whenProfilingNoTimeSeriesOneDataStream_thenRendersCorrectSql()
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`length_string` AS grouping_level_1
Expand All @@ -237,7 +233,6 @@ void renderSensor_whenProfilingNoTimeSeriesOneDataStream_thenRendersCorrectSql()
ORDER BY grouping_level_1""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -258,8 +253,8 @@ void renderSensor_whenMonitoringDefaultTimeSeriesOneDataStream_thenRendersCorrec
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`length_string` AS grouping_level_1
Expand All @@ -269,7 +264,6 @@ void renderSensor_whenMonitoringDefaultTimeSeriesOneDataStream_thenRendersCorrec
ORDER BY grouping_level_1""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -290,8 +284,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesOneDataStream_thenRendersCorre
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`length_string` AS grouping_level_1,
Expand All @@ -305,7 +299,6 @@ void renderSensor_whenPartitionedDefaultTimeSeriesOneDataStream_thenRendersCorre
ORDER BY grouping_level_1, time_period, time_period_utc""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand Down Expand Up @@ -334,8 +327,8 @@ void renderSensor_whenProfilingOneTimeSeriesThreeDataStream_thenRendersCorrectSq
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`strings_with_numbers` AS grouping_level_1,
Expand All @@ -349,7 +342,6 @@ void renderSensor_whenProfilingOneTimeSeriesThreeDataStream_thenRendersCorrectSq
ORDER BY grouping_level_1, grouping_level_2, grouping_level_3, time_period, time_period_utc""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -372,8 +364,8 @@ void renderSensor_whenMonitoringDefaultTimeSeriesThreeDataStream_thenRendersCorr
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`strings_with_numbers` AS grouping_level_1,
Expand All @@ -385,7 +377,6 @@ void renderSensor_whenMonitoringDefaultTimeSeriesThreeDataStream_thenRendersCorr
ORDER BY grouping_level_1, grouping_level_2, grouping_level_3""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand All @@ -408,8 +399,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesThreeDataStream_thenRendersCor
SELECT
SUM(
CASE
WHEN %s < 0 OR %s IS NULL THEN 0
ELSE 1
WHEN %s >= 0 THEN 1
ELSE 0
END
) AS actual_value,
analyzed_table.`strings_with_numbers` AS grouping_level_1,
Expand All @@ -425,7 +416,6 @@ void renderSensor_whenPartitionedDefaultTimeSeriesThreeDataStream_thenRendersCor
ORDER BY grouping_level_1, grouping_level_2, grouping_level_3, time_period, time_period_utc""";

Assertions.assertEquals(String.format(target_query,
this.getTableColumnName(runParameters),
this.getTableColumnName(runParameters),
runParameters.getConnection().getBigquery().getSourceProjectId(),
runParameters.getTable().getPhysicalTableName().getSchemaName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void renderSensor_whenProfilingNoTimeSeriesNoDataStream_thenRendersCorrectSql()
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value
Expand Down Expand Up @@ -137,8 +137,8 @@ void renderSensor_whenProfilingOneTimeSeriesNoDataStream_thenRendersCorrectSql()
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -169,8 +169,8 @@ void renderSensor_whenMonitoringDefaultTimeSeriesNoDataStream_thenRendersCorrect
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value
Expand All @@ -197,8 +197,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesNoDataStream_thenRendersCorrec
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -236,8 +236,8 @@ void renderSensor_whenProfilingNoTimeSeriesOneDataStream_thenRendersCorrectSql()
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -270,8 +270,8 @@ void renderSensor_whenMonitoringDefaultTimeSeriesOneDataStream_thenRendersCorrec
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -304,8 +304,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesOneDataStream_thenRendersCorre
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -350,8 +350,8 @@ void renderSensor_whenProfilingOneTimeSeriesThreeDataStream_thenRendersCorrectSq
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -390,8 +390,8 @@ void renderSensor_whenMonitoringDefaultTimeSeriesThreeDataStream_thenRendersCorr
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down Expand Up @@ -428,8 +428,8 @@ void renderSensor_whenPartitionedDefaultTimeSeriesThreeDataStream_thenRendersCor
WHEN COUNT(%1$s) = 0 THEN 0.0
ELSE 100.0 * SUM(
CASE
WHEN %1$s < 0 THEN 0
ELSE 1
WHEN %1$s >= 0 THEN 1
ELSE 0
END
) / COUNT(%1$s)
END AS actual_value,
Expand Down

0 comments on commit 48099aa

Please sign in to comment.