Skip to content

Commit 533fbdf

Browse files
ahkcsclaude
andcommitted
Address PR review: simplify leastRestrictive and shorten test assertions
Refactor leastRestrictive to use a single for-loop instead of two stream passes. Simplify multisearch integration tests by using 1-day intervals and count() aggregation to reduce verbose 36-row assertions to 5 rows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent bb026a5 commit 533fbdf

2 files changed

Lines changed: 30 additions & 139 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/utils/OpenSearchTypeFactory.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -398,19 +398,18 @@ public static boolean isNumericType(RelDataType fieldType) {
398398
if (types.size() > 1) {
399399
RelDataType first = types.get(0);
400400
if (first instanceof AbstractExprRelDataType<?> firstUdt) {
401-
boolean allSameUdt =
402-
types.stream()
403-
.allMatch(
404-
t ->
405-
t instanceof AbstractExprRelDataType<?> udt
406-
&& udt.getUdt() == firstUdt.getUdt());
407-
if (allSameUdt) {
408-
boolean anyNullable = types.stream().anyMatch(RelDataType::isNullable);
409-
if (anyNullable && !first.isNullable()) {
410-
return firstUdt.createWithNullability(this, true);
401+
boolean anyNullable = false;
402+
for (RelDataType t : types) {
403+
if (t instanceof AbstractExprRelDataType<?> udt && udt.getUdt() == firstUdt.getUdt()) {
404+
anyNullable |= t.isNullable();
405+
} else {
406+
return super.leastRestrictive(types);
411407
}
412-
return first;
413408
}
409+
if (anyNullable && !first.isNullable()) {
410+
return firstUdt.createWithNullability(this, true);
411+
}
412+
return first;
414413
}
415414
}
416415
return super.leastRestrictive(types);

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteMultisearchCommandIT.java

Lines changed: 20 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -375,55 +375,21 @@ public void testMultisearchWithSpanExpression() throws IOException {
375375
executeQuery(
376376
"| multisearch [search source=opensearch-sql_test_index_time_data | where category ="
377377
+ " \\\"A\\\"] [search source=opensearch-sql_test_index_time_data2 | where category"
378-
+ " = \\\"E\\\"] | stats avg(value) by span(@timestamp, 5m)");
378+
+ " = \\\"E\\\"] | stats count() by span(@timestamp, 1d)");
379379

380380
verifySchema(
381381
result,
382-
schema("avg(value)", null, "double"),
383-
schema("span(@timestamp,5m)", null, "timestamp"));
382+
schema("count()", null, "bigint"),
383+
schema("span(@timestamp,1d)", null, "timestamp"));
384384

385-
// Each data point falls in its own 5-min bucket (all >5min apart), so avg = single value
386-
// Category A: 26 rows from time_test_data, Category E: 10 rows from time_test_data2
385+
// Category A: 26 rows spanning Jul 28 – Aug 1; Category E: 10 rows spanning Jul 30 – Aug 1
387386
verifyDataRows(
388387
result,
389-
// Category A (26 rows)
390-
rows(8945.0, "2025-07-28 00:15:00"),
391-
rows(6834.0, "2025-07-28 03:55:00"),
392-
rows(6589.0, "2025-07-28 07:50:00"),
393-
rows(9367.0, "2025-07-28 11:05:00"),
394-
rows(9245.0, "2025-07-28 15:15:00"),
395-
rows(8917.0, "2025-07-28 19:20:00"),
396-
rows(8384.0, "2025-07-28 23:30:00"),
397-
rows(8798.0, "2025-07-29 03:35:00"),
398-
rows(9306.0, "2025-07-29 07:45:00"),
399-
rows(8873.0, "2025-07-29 11:50:00"),
400-
rows(8542.0, "2025-07-29 15:00:00"),
401-
rows(9321.0, "2025-07-29 19:05:00"),
402-
rows(8917.0, "2025-07-29 23:10:00"),
403-
rows(8756.0, "2025-07-30 03:20:00"),
404-
rows(9234.0, "2025-07-30 07:25:00"),
405-
rows(8679.0, "2025-07-30 11:35:00"),
406-
rows(8765.0, "2025-07-30 15:40:00"),
407-
rows(9187.0, "2025-07-30 19:50:00"),
408-
rows(8862.0, "2025-07-30 23:55:00"),
409-
rows(8537.0, "2025-07-31 03:00:00"),
410-
rows(9318.0, "2025-07-31 07:10:00"),
411-
rows(8914.0, "2025-07-31 11:15:00"),
412-
rows(8753.0, "2025-07-31 15:25:00"),
413-
rows(9231.0, "2025-07-31 19:30:00"),
414-
rows(8676.0, "2025-07-31 23:40:00"),
415-
rows(8762.0, "2025-08-01 03:45:00"),
416-
// Category E (10 rows)
417-
rows(2001.0, "2025-08-01 04:00:00"),
418-
rows(2003.0, "2025-08-01 01:00:00"),
419-
rows(2005.0, "2025-07-31 20:45:00"),
420-
rows(2007.0, "2025-07-31 16:00:00"),
421-
rows(2009.0, "2025-07-31 12:30:00"),
422-
rows(2011.0, "2025-07-31 08:00:00"),
423-
rows(2013.0, "2025-07-31 04:30:00"),
424-
rows(2015.0, "2025-07-31 01:00:00"),
425-
rows(2017.0, "2025-07-30 21:30:00"),
426-
rows(2019.0, "2025-07-30 18:00:00"));
388+
rows(7L, "2025-07-28 00:00:00"),
389+
rows(6L, "2025-07-29 00:00:00"),
390+
rows(8L, "2025-07-30 00:00:00"),
391+
rows(12L, "2025-07-31 00:00:00"),
392+
rows(3L, "2025-08-01 00:00:00"));
427393
}
428394

429395
/** Reproduce #5147: bin command after multisearch should produce non-null @timestamp. */
@@ -433,56 +399,16 @@ public void testMultisearchBinTimestamp() throws IOException {
433399
executeQuery(
434400
"| multisearch [search source=opensearch-sql_test_index_time_data | where category ="
435401
+ " \\\"A\\\"] [search source=opensearch-sql_test_index_time_data2 | where category"
436-
+ " = \\\"E\\\"] | fields @timestamp, category, value | bin @timestamp span=5m");
402+
+ " = \\\"E\\\"] | fields @timestamp, category, value | bin @timestamp span=1d");
437403

438404
verifySchema(
439405
result,
440406
schema("category", null, "string"),
441407
schema("value", null, "int"),
442408
schema("@timestamp", null, "timestamp"));
443409

444-
// bin floors @timestamp to 5-min boundaries; projectPlusOverriding moves @timestamp to end
445-
// Category A: 26 rows from time_test_data, Category E: 10 rows from time_test_data2
446-
verifyDataRows(
447-
result,
448-
// Category A (26 rows)
449-
rows("A", 8945, "2025-07-28 00:15:00"),
450-
rows("A", 6834, "2025-07-28 03:55:00"),
451-
rows("A", 6589, "2025-07-28 07:50:00"),
452-
rows("A", 9367, "2025-07-28 11:05:00"),
453-
rows("A", 9245, "2025-07-28 15:15:00"),
454-
rows("A", 8917, "2025-07-28 19:20:00"),
455-
rows("A", 8384, "2025-07-28 23:30:00"),
456-
rows("A", 8798, "2025-07-29 03:35:00"),
457-
rows("A", 9306, "2025-07-29 07:45:00"),
458-
rows("A", 8873, "2025-07-29 11:50:00"),
459-
rows("A", 8542, "2025-07-29 15:00:00"),
460-
rows("A", 9321, "2025-07-29 19:05:00"),
461-
rows("A", 8917, "2025-07-29 23:10:00"),
462-
rows("A", 8756, "2025-07-30 03:20:00"),
463-
rows("A", 9234, "2025-07-30 07:25:00"),
464-
rows("A", 8679, "2025-07-30 11:35:00"),
465-
rows("A", 8765, "2025-07-30 15:40:00"),
466-
rows("A", 9187, "2025-07-30 19:50:00"),
467-
rows("A", 8862, "2025-07-30 23:55:00"),
468-
rows("A", 8537, "2025-07-31 03:00:00"),
469-
rows("A", 9318, "2025-07-31 07:10:00"),
470-
rows("A", 8914, "2025-07-31 11:15:00"),
471-
rows("A", 8753, "2025-07-31 15:25:00"),
472-
rows("A", 9231, "2025-07-31 19:30:00"),
473-
rows("A", 8676, "2025-07-31 23:40:00"),
474-
rows("A", 8762, "2025-08-01 03:45:00"),
475-
// Category E (10 rows)
476-
rows("E", 2001, "2025-08-01 04:00:00"),
477-
rows("E", 2003, "2025-08-01 01:00:00"),
478-
rows("E", 2005, "2025-07-31 20:45:00"),
479-
rows("E", 2007, "2025-07-31 16:00:00"),
480-
rows("E", 2009, "2025-07-31 12:30:00"),
481-
rows("E", 2011, "2025-07-31 08:00:00"),
482-
rows("E", 2013, "2025-07-31 04:30:00"),
483-
rows("E", 2015, "2025-07-31 01:00:00"),
484-
rows("E", 2017, "2025-07-30 21:30:00"),
485-
rows("E", 2019, "2025-07-30 18:00:00"));
410+
// bin floors @timestamp to 1-day boundaries; 26 A-rows + 10 E-rows = 36 total
411+
assertEquals(36, result.getInt("total"));
486412
}
487413

488414
/** Reproduce #5147 full pattern: bin + stats after multisearch. */
@@ -492,53 +418,19 @@ public void testMultisearchBinAndStats() throws IOException {
492418
executeQuery(
493419
"| multisearch [search source=opensearch-sql_test_index_time_data | where category ="
494420
+ " \\\"A\\\"] [search source=opensearch-sql_test_index_time_data2 | where category"
495-
+ " = \\\"E\\\"] | bin @timestamp span=5m | stats avg(value) by @timestamp");
421+
+ " = \\\"E\\\"] | bin @timestamp span=1d | stats count() by @timestamp");
496422

497423
verifySchema(
498-
result, schema("avg(value)", null, "double"), schema("@timestamp", null, "timestamp"));
424+
result, schema("count()", null, "bigint"), schema("@timestamp", null, "timestamp"));
499425

500-
// Each data point falls in its own 5-min bucket (all >5min apart), so avg = single value
501-
// Category A: 26 rows from time_test_data, Category E: 10 rows from time_test_data2
426+
// Category A: 26 rows spanning Jul 28 – Aug 1; Category E: 10 rows spanning Jul 30 – Aug 1
502427
verifyDataRows(
503428
result,
504-
// Category A (26 rows)
505-
rows(8945.0, "2025-07-28 00:15:00"),
506-
rows(6834.0, "2025-07-28 03:55:00"),
507-
rows(6589.0, "2025-07-28 07:50:00"),
508-
rows(9367.0, "2025-07-28 11:05:00"),
509-
rows(9245.0, "2025-07-28 15:15:00"),
510-
rows(8917.0, "2025-07-28 19:20:00"),
511-
rows(8384.0, "2025-07-28 23:30:00"),
512-
rows(8798.0, "2025-07-29 03:35:00"),
513-
rows(9306.0, "2025-07-29 07:45:00"),
514-
rows(8873.0, "2025-07-29 11:50:00"),
515-
rows(8542.0, "2025-07-29 15:00:00"),
516-
rows(9321.0, "2025-07-29 19:05:00"),
517-
rows(8917.0, "2025-07-29 23:10:00"),
518-
rows(8756.0, "2025-07-30 03:20:00"),
519-
rows(9234.0, "2025-07-30 07:25:00"),
520-
rows(8679.0, "2025-07-30 11:35:00"),
521-
rows(8765.0, "2025-07-30 15:40:00"),
522-
rows(9187.0, "2025-07-30 19:50:00"),
523-
rows(8862.0, "2025-07-30 23:55:00"),
524-
rows(8537.0, "2025-07-31 03:00:00"),
525-
rows(9318.0, "2025-07-31 07:10:00"),
526-
rows(8914.0, "2025-07-31 11:15:00"),
527-
rows(8753.0, "2025-07-31 15:25:00"),
528-
rows(9231.0, "2025-07-31 19:30:00"),
529-
rows(8676.0, "2025-07-31 23:40:00"),
530-
rows(8762.0, "2025-08-01 03:45:00"),
531-
// Category E (10 rows)
532-
rows(2001.0, "2025-08-01 04:00:00"),
533-
rows(2003.0, "2025-08-01 01:00:00"),
534-
rows(2005.0, "2025-07-31 20:45:00"),
535-
rows(2007.0, "2025-07-31 16:00:00"),
536-
rows(2009.0, "2025-07-31 12:30:00"),
537-
rows(2011.0, "2025-07-31 08:00:00"),
538-
rows(2013.0, "2025-07-31 04:30:00"),
539-
rows(2015.0, "2025-07-31 01:00:00"),
540-
rows(2017.0, "2025-07-30 21:30:00"),
541-
rows(2019.0, "2025-07-30 18:00:00"));
429+
rows(7L, "2025-07-28 00:00:00"),
430+
rows(6L, "2025-07-29 00:00:00"),
431+
rows(8L, "2025-07-30 00:00:00"),
432+
rows(12L, "2025-07-31 00:00:00"),
433+
rows(3L, "2025-08-01 00:00:00"));
542434
}
543435

544436
@Test

0 commit comments

Comments
 (0)