Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.gateway.ha.persistence.dao.QueryHistoryDao;
import org.jdbi.v3.core.Jdbi;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
Expand Down Expand Up @@ -144,7 +145,7 @@ public List<DistributionResponse.LineChart> findDistribution(Long ts)
List<DistributionResponse.LineChart> resList = new ArrayList<>();
for (Map<String, Object> model : results) {
DistributionResponse.LineChart lineChart = new DistributionResponse.LineChart();
long minute = (long) Float.parseFloat(model.get("minute").toString());
long minute = new BigDecimal(model.get("minute").toString()).longValue();
Instant instant = Instant.ofEpochSecond(minute * 60L);
LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.testcontainers.containers.JdbcDatabaseContainer;

import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -117,16 +118,17 @@ void testFindDistribution()
@Test
void testTimestampParsing()
{
long result = 30338640;

// postgres: minute -> {Double@9333} 3.033864E7
String postgresTimestamp = "3.033864E7";
long parsedLongTimestamp = (long) Float.parseFloat(postgresTimestamp);
assertThat(parsedLongTimestamp).isEqualTo(result);

// mysql: minute -> {BigDecimal@9775} "30338640"
String mysqlTimestamp = "30338640";
long parsedLongTimestamp2 = (long) Float.parseFloat(mysqlTimestamp);
assertThat(parsedLongTimestamp2).isEqualTo(result);
// This ensures odd-minute values remain precision when converted from different formats.
long expectedMinuteBucket = 30338641;

// postgres: minute -> {Double@9333} 3.0338641E7
String postgresTimestamp = "3.0338641E7";
long parsedPostgresMinute = new BigDecimal(postgresTimestamp).longValue();
assertThat(parsedPostgresMinute).isEqualTo(expectedMinuteBucket);

// mysql: minute -> {BigDecimal@9775} "30338641"
String mysqlTimestamp = "30338641";
long parsedMysqlMinute = new BigDecimal(mysqlTimestamp).longValue();
assertThat(parsedMysqlMinute).isEqualTo(expectedMinuteBucket);
}
}