@@ -174,8 +174,8 @@ void decimalMinimumBoundsDoNotDependOnRows() throws Exception {
174174 }
175175
176176 /**
177- * A set operation over a DECIMAL MIN merges the same bounds whether or not the
178- * MIN branch returns rows.
177+ * A set operation over a DECIMAL MIN merges the declared decimal bounds whether
178+ * or not the MIN branch returns rows.
179179 *
180180 * @throws Exception
181181 * if query execution fails
@@ -185,11 +185,12 @@ void setOperationBoundsDoNotDependOnRows() throws Exception {
185185 String suffix = " UNION ALL SELECT CAST(1 AS DECIMAL(3,0))" ;
186186 String emptyBranch = "SELECT MIN(CAST(mpg AS DECIMAL(10,2))) FROM mtcars WHERE cyl = 99" + suffix ;
187187 String filledBranch = "SELECT MIN(CAST(mpg AS DECIMAL(10,2))) FROM mtcars" + suffix ;
188+ int [] declaredBounds = {
189+ Types .DECIMAL , 10 , 2
190+ };
188191 try (var connection = DriverManager .getConnection (url ())) {
189- int [] emptyBounds = setBounds (connection , emptyBranch );
190- int [] filledBounds = setBounds (connection , filledBranch );
191- assertArrayEquals (filledBounds , emptyBounds , "merged bounds must not depend on rows" );
192- assertEquals (Types .DECIMAL , emptyBounds [0 ]);
192+ assertArrayEquals (declaredBounds , setBounds (connection , emptyBranch ), "merged bounds must not depend on rows" );
193+ assertArrayEquals (declaredBounds , setBounds (connection , filledBranch ), "merged bounds must not depend on rows" );
193194 }
194195 }
195196
@@ -224,6 +225,37 @@ void emptyUnboundedDecimalMinimumReportsDecimal() throws Exception {
224225 }
225226 }
226227
228+ /**
229+ * An empty MAX over an unbounded decimal argument reports DECIMAL instead of
230+ * OTHER, matching the argument's plain empty projection.
231+ *
232+ * @throws Exception
233+ * if query execution fails
234+ */
235+ @ Test
236+ void emptyUnboundedDecimalMaximumReportsDecimal () throws Exception {
237+ try (var connection = DriverManager .getConnection (url ()); var statement = connection .createStatement ()) {
238+ try (var result = statement .executeQuery ("SELECT MAX(cyl / 3) FROM mtcars WHERE cyl = 99" )) {
239+ var meta = result .getMetaData ();
240+ assertEquals (Types .DECIMAL , meta .getColumnType (1 ));
241+ assertEquals (0 , meta .getPrecision (1 ));
242+ assertEquals (0 , meta .getScale (1 ));
243+ assertTrue (result .next ());
244+ assertNull (result .getObject (1 ));
245+ }
246+ try (var result = statement .executeQuery ("SELECT MAX(ROUND(mpg, 1)) FROM mtcars WHERE cyl = 99" )) {
247+ assertEquals (Types .DECIMAL , result .getMetaData ().getColumnType (1 ));
248+ assertTrue (result .next ());
249+ assertNull (result .getObject (1 ));
250+ }
251+ try (var result = statement .executeQuery ("SELECT MAX(cyl / 3) FROM mtcars" )) {
252+ assertEquals (Types .DECIMAL , result .getMetaData ().getColumnType (1 ));
253+ assertTrue (result .next ());
254+ assertNotNull (result .getBigDecimal (1 ));
255+ }
256+ }
257+ }
258+
227259 /**
228260 * Reads a set operation's first-column JDBC type, precision, and scale.
229261 *
0 commit comments