jtuglu1 commented on code in PR #18949:
URL: https://github.com/apache/druid/pull/18949#discussion_r2728527544
##########
extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java:
##########
@@ -551,4 +553,33 @@ public void testSpectatorFunctionsOnNullHistogram()
ImmutableList.of(new Object[]{null, null, null})
);
}
+
+ @Test
+ public void testSpectatorPercentileWithStringLiteral()
+ {
+ // verify invalid queries return 400 (user error)
+ final String query = "SELECT SPECTATOR_PERCENTILE(histogram_metric,
'99.99') FROM foo";
+
+ try {
+ testQuery(query, ImmutableList.of(), ImmutableList.of());
+ throw new AssertionError("Expected DruidException but query succeeded");
+ }
+ catch (DruidException e) {
+ if (e.getTargetPersona() != DruidException.Persona.USER) {
Review Comment:
I think it's more idiomatic to use the `org.junit.Assert` class here.
Something like:
```java
Assert.assertEquals("Expected USER persona", e.getTargetPersona()),
DruidException.Persona.USER, e.getTargetPersona());
```
##########
extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java:
##########
@@ -551,4 +553,33 @@ public void testSpectatorFunctionsOnNullHistogram()
ImmutableList.of(new Object[]{null, null, null})
);
}
+
+ @Test
+ public void testSpectatorPercentileWithStringLiteral()
+ {
+ // verify invalid queries return 400 (user error)
+ final String query = "SELECT SPECTATOR_PERCENTILE(histogram_metric,
'99.99') FROM foo";
+
+ try {
+ testQuery(query, ImmutableList.of(), ImmutableList.of());
+ throw new AssertionError("Expected DruidException but query succeeded");
Review Comment:
Let's use:
```java
Assert.fail("Expected DruidException but query succeeded");
```
##########
extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchApproxQuantileSqlAggregator.java:
##########
@@ -98,7 +99,14 @@ public Aggregation toDruidAggregation(
return null;
}
- final float probability = ((Number)
RexLiteral.value(probabilityArg)).floatValue();
+ final Object probabilityValue = RexLiteral.value(probabilityArg);
+ if (!(probabilityValue instanceof Number)) {
+ throw InvalidSqlInput.exception(
+ "DS_QUANTILES_SKETCH probability parameter must be a numeric
literal, got %s",
Review Comment:
I wonder if we can template this error a bit better to make it uniform and
easier for callers to access (this should make it easier for new use-cases to
adopt it).
Maybe something like:
```java
public static DruidException invalidParameterTypeException(String
function, String expectedType, Object... args)
{
return DruidException.fromFailure(new InvalidSqlInput("{function}
parameter `{parameter}` must be a {expectedType} literal, got `%s`", msg,
args));
}
```
--
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]