From 13c5f7b31aade712fa6d31be54f289a88c8b7445 Mon Sep 17 00:00:00 2001 From: Bharathwaj G Date: Fri, 9 Feb 2024 00:20:39 +0530 Subject: [PATCH] Fixing timestamp conversions Signed-off-by: Bharathwaj G --- .../builder/BaseSingleTreeBuilder.java | 48 +++++++++++++++---- .../bucket/startree/StarTreeAggregator.java | 16 +++---- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/BaseSingleTreeBuilder.java b/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/BaseSingleTreeBuilder.java index 34537d7b63828..e77b30336104c 100644 --- a/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/BaseSingleTreeBuilder.java +++ b/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/BaseSingleTreeBuilder.java @@ -16,6 +16,7 @@ */ package org.opensearch.index.codec.freshstartree.builder; +import java.time.temporal.ChronoField; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.codecs.CodecUtil; @@ -59,7 +60,7 @@ /** Base class for star tree builder */ public abstract class BaseSingleTreeBuilder { public static final int STAR_IN_DOC_VALUES_INDEX = -1; - public final static long SECOND = 1;// HTTP codec + public final static long SECOND = 1000;// HTTP codec public final static long MINUTE = 60 * SECOND; public final static long HOUR = 60 * 60 * SECOND; public final static long DAY = 24 * HOUR; @@ -98,8 +99,8 @@ public abstract class BaseSingleTreeBuilder { dimensionsSplitOrder = new ArrayList<>(); dimensionsSplitOrder.add("minute"); dimensionsSplitOrder.add("hour"); - //dimensionsSplitOrder.add("day"); - //dimensionsSplitOrder.add("month"); + dimensionsSplitOrder.add("day"); + dimensionsSplitOrder.add("month"); // dimensionsSplitOrder.add("year"); dimensionsSplitOrder.add("status"); _numDimensions = dimensionsSplitOrder.size(); @@ -565,19 +566,48 @@ Record getNextSegmentRecord() throws IOException { return new Record(dimensions, metrics); } + private long getTimeStampVal1(final String fieldName, final long val) { + switch (fieldName) { + case "minute": + return val / MINUTE; + case "hour": + System.out.println(val + " " + val % HOUR); + return val / HOUR; + case "day": + return val / DAY; + case "month": + return val / MONTH; + case "year": + return val / YEAR; + default: + return val; + } + } + private long getTimeStampVal(final String fieldName, final long val) { + long roundedDate = 0; + long ratio = 0; + switch (fieldName) { + case "minute": - return val / MINUTE;// * MINUTE; + ratio = ChronoField.MINUTE_OF_HOUR.getBaseUnit().getDuration().toMillis(); + roundedDate = DateUtils.roundFloor(val, ratio); + return roundedDate; case "hour": - logger.info( "val: " + val + " hour: " + (val/HOUR)); - return val / HOUR;// * HOUR; + ratio = ChronoField.HOUR_OF_DAY.getBaseUnit().getDuration().toMillis(); + roundedDate = DateUtils.roundFloor(val, ratio); + return roundedDate; case "day": - return val / DAY;// * DAY; + ratio = ChronoField.DAY_OF_MONTH.getBaseUnit().getDuration().toMillis(); + roundedDate = DateUtils.roundFloor(val, ratio); + return roundedDate; case "month": - return val / MONTH;// * MONTH; // TODO + roundedDate = DateUtils.roundMonthOfYear(val); + return roundedDate; case "year": - return val / YEAR;// * YEAR; + roundedDate = DateUtils.roundYear(val); + return roundedDate; default: return val; } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/startree/StarTreeAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/startree/StarTreeAggregator.java index 5f3dee2a29d6c..015ab02495bf0 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/startree/StarTreeAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/startree/StarTreeAggregator.java @@ -203,7 +203,7 @@ private String getKey(Map fieldColsMap, int doc) throw for (Map.Entry fieldEntry : fieldColsMap.entrySet()) { fieldEntry.getValue().advanceExact(doc); long val = fieldEntry.getValue().longValue(); - System.out.println("Key field : " + fieldEntry.getKey() + " Value : " + val); + //System.out.println("Key field : " + fieldEntry.getKey() + " Value : " + val); sj.add("" + val); } return sj.toString(); @@ -211,13 +211,13 @@ private String getKey(Map fieldColsMap, int doc) throw private long subBucketOrdinal(long owningBucketOrdinal, int keyOrd) { long subord = owningBucketOrdinal * indexMap.size() + keyOrd; - logger.info( - "Owning bucket ordinal : {} , rangeord : {} , len : {} == SubOrd : {}", - owningBucketOrdinal, - keyOrd, - indexMap.size(), - subord - ); +// logger.info( +// "Owning bucket ordinal : {} , rangeord : {} , len : {} == SubOrd : {}", +// owningBucketOrdinal, +// keyOrd, +// indexMap.size(), +// subord +// ); return owningBucketOrdinal * indexMap.size() + keyOrd; } }