Skip to content

Commit

Permalink
Merge pull request #3341 from ingef/feature/speedup-date-statistics
Browse files Browse the repository at this point in the history
i deleted the wrong field: We need months not quarters
  • Loading branch information
awildturtok authored Mar 11, 2024
2 parents 21cc4c0 + cb2beb1 commit 378ff5c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Getter
public class DateColumnStatsCollector extends ColumnStatsCollector {

private final Object2IntMap<String> quarterCounts = new Object2IntOpenHashMap<>();
private final Object2IntMap<String> monthCounts = new Object2IntOpenHashMap<>();

private int totalCount = 0;
private int nulls = 0;
Expand Down Expand Up @@ -72,19 +72,21 @@ private void handleDay(int day) {
final LocalDate date = CDate.toLocalDate(day);
final int year = date.getYear();
final int quarter = date.get(IsoFields.QUARTER_OF_YEAR);
final int month = date.getMonthValue();

final String yearQuarter = year + "-" + quarter;
// This code is pretty hot, therefore I want to avoid String.format
final String yearMonth = year + "-" + (month < 10 ? "0" : "") + month;

quarterCounts.compute(yearQuarter, (ignored, current) -> current == null ? 1 : current + 1);
monthCounts.compute(yearMonth, (ignored, current) -> current == null ? 1 : current + 1);
}

@Override
public ResultColumnStatistics describe() {

return new ColumnDescription(getName(), getLabel(), getDescription(),
totalCount,
nulls,
// we only need to sort for output, so using a fastmap for computation is sensible.
new TreeMap<>(quarterCounts),
new TreeMap<>(monthCounts),
span == null ? CDateRange.all().toSimpleRange() : span.toSimpleRange()
);
}
Expand All @@ -96,15 +98,15 @@ public static class ColumnDescription extends ResultColumnStatistics {

private final int count;
private final int nullValues;
private final SortedMap<String, Integer> quarterCounts;
private final SortedMap<String, Integer> monthCounts;

private final Range<LocalDate> span;

public ColumnDescription(String name, String label, String description, int count, int nullValues, SortedMap<String, Integer> quarterCounts, Range<LocalDate> span) {
public ColumnDescription(String name, String label, String description, int count, int nullValues, SortedMap<String, Integer> monthCounts, Range<LocalDate> span) {
super(name, label, description);
this.count = count;
this.nullValues = nullValues;
this.quarterCounts = quarterCounts;
this.monthCounts = monthCounts;
this.span = span;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void execute(String name, TestConquery testConquery) throws Exception {
6,
0,
new TreeMap<>(Map.of(
"2021-1", 5,
"2021-4", 1
"2021-01", 5,
"2021-10", 1
)),
Range.of(
LocalDate.of(2021, 1, 1), LocalDate.of(2021, 10, 1)
Expand All @@ -90,8 +90,8 @@ public void execute(String name, TestConquery testConquery) throws Exception {
6,
0,
new TreeMap<>(Map.of(
"2021-1", 5,
"2021-4", 1
"2021-01", 5,
"2021-10", 1
)),
Range.of(
LocalDate.of(2021, 1, 1), LocalDate.of(2021, 10, 1)
Expand Down

0 comments on commit 378ff5c

Please sign in to comment.