abhishekrb19 commented on code in PR #16046:
URL: https://github.com/apache/druid/pull/16046#discussion_r1516535624
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java:
##########
@@ -589,32 +593,40 @@ public void testLongs()
@Test
public void testMissingParameter()
{
- expectedException.expect(
- DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value
bound for parameter (position [1])")
+ DruidException exception = assertThrows(
+ DruidException.class,
+ () -> testQuery(
+ "SELECT COUNT(*)\n"
+ + "FROM druid.numfoo\n"
+ + "WHERE l1 > ?",
+ ImmutableList.of(),
+ ImmutableList.of(new Object[] {3L}),
+ ImmutableList.of()
+ )
);
- testQuery(
- "SELECT COUNT(*)\n"
- + "FROM druid.numfoo\n"
- + "WHERE l1 > ?",
- ImmutableList.of(),
- ImmutableList.of(new Object[]{3L}),
- ImmutableList.of()
+ assertThat(
Review Comment:
The codeQL notice seems legit. Can we replace the deprecated method with
`MatcherAssert.assertThat()`:
```suggestion
MatcherAssert.assertThat(
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java:
##########
@@ -589,32 +593,40 @@ public void testLongs()
@Test
public void testMissingParameter()
{
- expectedException.expect(
- DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value
bound for parameter (position [1])")
+ DruidException exception = assertThrows(
+ DruidException.class,
+ () -> testQuery(
+ "SELECT COUNT(*)\n"
+ + "FROM druid.numfoo\n"
+ + "WHERE l1 > ?",
+ ImmutableList.of(),
+ ImmutableList.of(new Object[] {3L}),
+ ImmutableList.of()
+ )
);
- testQuery(
- "SELECT COUNT(*)\n"
- + "FROM druid.numfoo\n"
- + "WHERE l1 > ?",
- ImmutableList.of(),
- ImmutableList.of(new Object[]{3L}),
- ImmutableList.of()
+ assertThat(
+ exception,
+ DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value
bound for parameter (position [1])")
);
}
@Test
public void testPartiallyMissingParameter()
{
- expectedException.expect(
- DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value
bound for parameter (position [2])")
+ DruidException exception = assertThrows(
+ DruidException.class,
+ () -> testQuery(
+ "SELECT COUNT(*)\n"
+ + "FROM druid.numfoo\n"
+ + "WHERE l1 > ? AND f1 = ?",
+ ImmutableList.of(),
+ ImmutableList.of(new Object[] {3L}),
+ ImmutableList.of(new SqlParameter(SqlType.BIGINT, 3L))
+ )
);
- testQuery(
- "SELECT COUNT(*)\n"
- + "FROM druid.numfoo\n"
- + "WHERE l1 > ? AND f1 = ?",
- ImmutableList.of(),
- ImmutableList.of(new Object[]{3L}),
- ImmutableList.of(new SqlParameter(SqlType.BIGINT, 3L))
+ assertThat(
Review Comment:
```suggestion
MatcherAssert.assertThat(
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java:
##########
@@ -624,14 +636,19 @@ public void testPartiallyMissingParameterInTheMiddle()
List<SqlParameter> params = new ArrayList<>();
params.add(null);
params.add(new SqlParameter(SqlType.INTEGER, 1));
- expectedException.expect(
- DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value
bound for parameter (position [1])")
+ DruidException exception = assertThrows(
+ DruidException.class,
+ () -> testQuery(
+ "SELECT 1 + ?, dim1 FROM foo LIMIT ?",
+ ImmutableList.of(),
+ ImmutableList.of(),
+ params
+ )
);
- testQuery(
- "SELECT 1 + ?, dim1 FROM foo LIMIT ?",
- ImmutableList.of(),
- ImmutableList.of(),
- params
+
+ assertThat(
Review Comment:
```suggestion
MatcherAssert.assertThat(
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java:
##########
@@ -6133,12 +6124,13 @@ public void
testCountStarWithTimeInIntervalFilterNonLiteral()
msqIncompatible();
testQueryThrows(
"SELECT COUNT(*) FROM druid.foo "
- + "WHERE TIME_IN_INTERVAL(__time, dim1)",
- expected -> {
- expected.expect(CoreMatchers.instanceOf(DruidException.class));
-
expected.expect(ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString(
- "Argument to function 'TIME_IN_INTERVAL' must be a literal (line
[1], column [63])")));
- }
+ + "WHERE TIME_IN_INTERVAL(__time, dim1)",
Review Comment:
Fixup some inconsistent space. The original formatting looks correct:
```suggestion
+ "WHERE TIME_IN_INTERVAL(__time, dim1)",
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java:
##########
@@ -1222,29 +1212,55 @@ public void assertResultsEquals(String sql,
List<Object[]> expectedResults, List
Assert.assertEquals(expectedResults.size(), results.size());
}
- public void testQueryThrows(final String sql, Consumer<ExpectedException>
expectedExceptionInitializer)
+ public <T extends Throwable> void testQueryThrows(
+ final String sql,
+ final DruidExceptionMatcher exceptionMatcher)
+
+ {
+ testQueryThrows(sql, null, null, DruidException.class, exceptionMatcher);
+ }
+
+ public <T extends Exception> void testQueryThrows(
+ final String sql,
+ final Class<T> exceptionType,
+ final String exceptionMessage)
+
{
- testBuilder()
- .sql(sql)
- .expectedException(expectedExceptionInitializer)
- .build()
- .run();
+ testQueryThrows(
+ sql,
+ null,
+ null,
+ exceptionType,
+
ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(exceptionMessage))
+ );
+ }
+
+ public <T extends Exception> void testQueryThrows(
+ final String sql,
+ final Class<T> exceptionType,
+ final Matcher<Throwable> exceptionMatcher)
+
Review Comment:
```suggestion
final Matcher<Throwable> exceptionMatcher
)
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java:
##########
@@ -12319,61 +12308,64 @@ public void
testRequireTimeConditionLogicalValuePositive()
@Test
public void testRequireTimeConditionSimpleQueryNegative()
{
- msqIncompatible();
- expectedException.expect(CannotBuildQueryException.class);
- expectedException.expectMessage("__time column");
+ Throwable exception = assertThrows(CannotBuildQueryException.class, () -> {
+ msqIncompatible();
- testQuery(
- PLANNER_CONFIG_REQUIRE_TIME_CONDITION,
- "SELECT SUM(cnt), gran FROM (\n"
- + " SELECT __time as t, floor(__time TO month) AS gran,\n"
- + " cnt FROM druid.foo\n"
- + ") AS x\n"
- + "GROUP BY gran\n"
- + "ORDER BY gran",
- CalciteTests.REGULAR_USER_AUTH_RESULT,
- ImmutableList.of(),
- ImmutableList.of()
- );
+ testQuery(
+ PLANNER_CONFIG_REQUIRE_TIME_CONDITION,
+ "SELECT SUM(cnt), gran FROM (\n"
+ + " SELECT __time as t, floor(__time TO month) AS gran,\n"
+ + " cnt FROM druid.foo\n"
+ + ") AS x\n"
+ + "GROUP BY gran\n"
+ + "ORDER BY gran",
+ CalciteTests.REGULAR_USER_AUTH_RESULT,
+ ImmutableList.of(),
+ ImmutableList.of()
+ );
+ });
+ assertTrue(exception.getMessage().contains("__time column"));
Review Comment:
ditto here and below
##########
sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java:
##########
@@ -1222,29 +1212,55 @@ public void assertResultsEquals(String sql,
List<Object[]> expectedResults, List
Assert.assertEquals(expectedResults.size(), results.size());
}
- public void testQueryThrows(final String sql, Consumer<ExpectedException>
expectedExceptionInitializer)
+ public <T extends Throwable> void testQueryThrows(
+ final String sql,
+ final DruidExceptionMatcher exceptionMatcher)
+
+ {
+ testQueryThrows(sql, null, null, DruidException.class, exceptionMatcher);
+ }
+
+ public <T extends Exception> void testQueryThrows(
+ final String sql,
+ final Class<T> exceptionType,
+ final String exceptionMessage)
+
Review Comment:
```suggestion
final String exceptionMessage
)
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java:
##########
@@ -7581,47 +7573,48 @@ public void testAvgDailyCountDistinct()
@Test
public void testHighestMaxNumericInFilter()
{
- expectedException.expect(UOE.class);
- expectedException.expectMessage("Expected parameter[maxNumericInFilters]
cannot exceed system set value of [100]");
+ Throwable exception = assertThrows(UOE.class, () -> {
- testQuery(
- PLANNER_CONFIG_MAX_NUMERIC_IN_FILTER,
- ImmutableMap.of(QueryContexts.MAX_NUMERIC_IN_FILTERS, 20000),
- "SELECT COUNT(*)\n"
- + "FROM druid.numfoo\n"
- + "WHERE dim6 IN (\n"
- + "1,2,3\n"
- + ")\n",
- CalciteTests.REGULAR_USER_AUTH_RESULT,
- ImmutableList.of(),
- ImmutableList.of()
- );
+ testQuery(
+ PLANNER_CONFIG_MAX_NUMERIC_IN_FILTER,
+ ImmutableMap.of(QueryContexts.MAX_NUMERIC_IN_FILTERS, 20000),
+ "SELECT COUNT(*)\n"
+ + "FROM druid.numfoo\n"
+ + "WHERE dim6 IN (\n"
+ + "1,2,3\n"
+ + ")\n",
+ CalciteTests.REGULAR_USER_AUTH_RESULT,
+ ImmutableList.of(),
+ ImmutableList.of()
+ );
+ });
+ assertTrue(exception.getMessage().contains("Expected
parameter[maxNumericInFilters] cannot exceed system set value of [100]"));
}
@Test
public void testQueryWithMoreThanMaxNumericInFilter()
{
- if (NullHandling.sqlCompatible()) {
- // skip in sql compatible mode, this plans to an OR filter with equality
filter children...
- return;
- }
+ assumeFalse(
+ "skip in sql compatible mode, this plans to an OR filter with equality
filter children",
+ NullHandling.sqlCompatible()
+ );
msqIncompatible();
- expectedException.expect(UOE.class);
- expectedException.expectMessage(
- "The number of values in the IN clause for [dim6] in query exceeds
configured maxNumericFilter limit of [2] for INs. Cast [3] values of IN clause
to String");
- testQuery(
- PLANNER_CONFIG_MAX_NUMERIC_IN_FILTER,
- ImmutableMap.of(QueryContexts.MAX_NUMERIC_IN_FILTERS, 2),
- "SELECT COUNT(*)\n"
- + "FROM druid.numfoo\n"
- + "WHERE dim6 IN (\n"
- + "1,2,3\n"
- + ")\n",
- CalciteTests.REGULAR_USER_AUTH_RESULT,
- ImmutableList.of(),
- ImmutableList.of()
- );
+ Throwable exception = assertThrows(UOE.class, () -> {
+ testQuery(
+ PLANNER_CONFIG_MAX_NUMERIC_IN_FILTER,
+ ImmutableMap.of(QueryContexts.MAX_NUMERIC_IN_FILTERS, 2),
+ "SELECT COUNT(*)\n"
+ + "FROM druid.numfoo\n"
+ + "WHERE dim6 IN (\n"
+ + "1,2,3\n"
+ + ")\n",
+ CalciteTests.REGULAR_USER_AUTH_RESULT,
+ ImmutableList.of(),
+ ImmutableList.of()
+ );
+ });
+ assertTrue(exception.getMessage().contains("The number of values in the IN
clause for [dim6] in query exceeds configured maxNumericFilter limit of [2] for
INs. Cast [3] values of IN clause to String"));
Review Comment:
nit: can you please break this up to accommodate smaller screen length?
Also, please use one consistently between MatcherAssert.assertThat and
assertTrue (given assertThat is deprecated).
##########
sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java:
##########
@@ -1222,29 +1212,55 @@ public void assertResultsEquals(String sql,
List<Object[]> expectedResults, List
Assert.assertEquals(expectedResults.size(), results.size());
}
- public void testQueryThrows(final String sql, Consumer<ExpectedException>
expectedExceptionInitializer)
+ public <T extends Throwable> void testQueryThrows(
+ final String sql,
+ final DruidExceptionMatcher exceptionMatcher)
+
+ {
+ testQueryThrows(sql, null, null, DruidException.class, exceptionMatcher);
+ }
+
+ public <T extends Exception> void testQueryThrows(
+ final String sql,
+ final Class<T> exceptionType,
+ final String exceptionMessage)
+
{
- testBuilder()
- .sql(sql)
- .expectedException(expectedExceptionInitializer)
- .build()
- .run();
+ testQueryThrows(
+ sql,
+ null,
+ null,
+ exceptionType,
+
ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(exceptionMessage))
+ );
+ }
+
+ public <T extends Exception> void testQueryThrows(
+ final String sql,
+ final Class<T> exceptionType,
+ final Matcher<Throwable> exceptionMatcher)
+
+ {
+ testQueryThrows(sql, null, null, exceptionType, exceptionMatcher);
}
- public void testQueryThrows(
+ public <T extends Exception> void testQueryThrows(
final String sql,
final Map<String, Object> queryContext,
final List<Query<?>> expectedQueries,
- final Consumer<ExpectedException> expectedExceptionInitializer
- )
- {
- testBuilder()
- .sql(sql)
- .queryContext(queryContext)
- .expectedQueries(expectedQueries)
- .expectedException(expectedExceptionInitializer)
- .build()
- .run();
+ final Class<T> exceptionType,
+ final Matcher<Throwable> exceptionMatcher)
Review Comment:
```suggestion
final Matcher<Throwable> exceptionMatcher
)
```
##########
sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java:
##########
@@ -1222,29 +1212,55 @@ public void assertResultsEquals(String sql,
List<Object[]> expectedResults, List
Assert.assertEquals(expectedResults.size(), results.size());
}
- public void testQueryThrows(final String sql, Consumer<ExpectedException>
expectedExceptionInitializer)
+ public <T extends Throwable> void testQueryThrows(
+ final String sql,
+ final DruidExceptionMatcher exceptionMatcher)
+
Review Comment:
```suggestion
final DruidExceptionMatcher exceptionMatcher
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]