Skip to content

Commit 601c051

Browse files
committed
Fix Trino Gateway UI query distribution displays zero queries error
1 parent 535802e commit 601c051

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/router/HaQueryHistoryManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.trino.gateway.ha.persistence.dao.QueryHistoryDao;
2222
import org.jdbi.v3.core.Jdbi;
2323

24+
import java.math.BigDecimal;
2425
import java.time.Instant;
2526
import java.time.LocalDateTime;
2627
import java.time.ZoneId;
@@ -144,7 +145,7 @@ public List<DistributionResponse.LineChart> findDistribution(Long ts)
144145
List<DistributionResponse.LineChart> resList = new ArrayList<>();
145146
for (Map<String, Object> model : results) {
146147
DistributionResponse.LineChart lineChart = new DistributionResponse.LineChart();
147-
long minute = (long) Float.parseFloat(model.get("minute").toString());
148+
long minute = new BigDecimal(model.get("minute").toString()).longValue();
148149
Instant instant = Instant.ofEpochSecond(minute * 60L);
149150
LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
150151
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");

gateway-ha/src/test/java/io/trino/gateway/ha/router/BaseTestQueryHistoryManager.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.api.TestInstance.Lifecycle;
2525
import org.testcontainers.containers.JdbcDatabaseContainer;
2626

27+
import java.math.BigDecimal;
2728
import java.util.List;
2829
import java.util.Optional;
2930

@@ -117,16 +118,17 @@ void testFindDistribution()
117118
@Test
118119
void testTimestampParsing()
119120
{
120-
long result = 30338640;
121-
122-
// postgres: minute -> {Double@9333} 3.033864E7
123-
String postgresTimestamp = "3.033864E7";
124-
long parsedLongTimestamp = (long) Float.parseFloat(postgresTimestamp);
125-
assertThat(parsedLongTimestamp).isEqualTo(result);
126-
127-
// mysql: minute -> {BigDecimal@9775} "30338640"
128-
String mysqlTimestamp = "30338640";
129-
long parsedLongTimestamp2 = (long) Float.parseFloat(mysqlTimestamp);
130-
assertThat(parsedLongTimestamp2).isEqualTo(result);
121+
// This ensures odd-minute values remain precision when converted from different formats.
122+
long expectedMinuteBucket = 30338641;
123+
124+
// postgres: minute -> {Double@9333} 3.0338641E7
125+
String postgresTimestamp = "3.0338641E7";
126+
long parsedPostgresMinute = new BigDecimal(postgresTimestamp).longValue();
127+
assertThat(parsedPostgresMinute).isEqualTo(expectedMinuteBucket);
128+
129+
// mysql: minute -> {BigDecimal@9775} "30338641"
130+
String mysqlTimestamp = "30338641";
131+
long parsedMysqlMinute = new BigDecimal(mysqlTimestamp).longValue();
132+
assertThat(parsedMysqlMinute).isEqualTo(expectedMinuteBucket);
131133
}
132134
}

0 commit comments

Comments
 (0)