Skip to content

Commit

Permalink
Fixing timestamp conversions
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Feb 8, 2024
1 parent 70024bb commit 13c5f7b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,21 @@ private String getKey(Map<String, NumericDocValues> fieldColsMap, int doc) throw
for (Map.Entry<String, NumericDocValues> 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();
}

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;
}
}

0 comments on commit 13c5f7b

Please sign in to comment.