提交 5e73ccf7 编写于 作者: V Vlad Ilyushchenko

chore: renamed timestamp related classes to Timestamp*. Otherwise there is...

chore: renamed timestamp related classes to Timestamp*. Otherwise there is constant confusion over which class is being used.
上级 8e5770ed
......@@ -27,8 +27,8 @@ import io.questdb.cairo.sql.RecordMetadata;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.std.*;
import io.questdb.std.microtime.DateLocaleFactory;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.Path;
import java.io.Closeable;
......@@ -101,23 +101,23 @@ public class TableReader implements Closeable {
case PartitionBy.DAY:
partitionPathGenerator = DAY_GEN;
reloadMethod = FIRST_TIME_PARTITIONED_RELOAD_METHOD;
timestampFloorMethod = Dates::floorDD;
intervalLengthMethod = Dates::getDaysBetween;
partitionTimestampCalculatorMethod = Dates::addDays;
timestampFloorMethod = Timestamps::floorDD;
intervalLengthMethod = Timestamps::getDaysBetween;
partitionTimestampCalculatorMethod = Timestamps::addDays;
break;
case PartitionBy.MONTH:
partitionPathGenerator = MONTH_GEN;
reloadMethod = FIRST_TIME_PARTITIONED_RELOAD_METHOD;
timestampFloorMethod = Dates::floorMM;
intervalLengthMethod = Dates::getMonthsBetween;
partitionTimestampCalculatorMethod = Dates::addMonths;
timestampFloorMethod = Timestamps::floorMM;
intervalLengthMethod = Timestamps::getMonthsBetween;
partitionTimestampCalculatorMethod = Timestamps::addMonths;
break;
case PartitionBy.YEAR:
partitionPathGenerator = YEAR_GEN;
reloadMethod = FIRST_TIME_PARTITIONED_RELOAD_METHOD;
timestampFloorMethod = Dates::floorYYYY;
intervalLengthMethod = Dates::getYearsBetween;
partitionTimestampCalculatorMethod = Dates::addYear;
timestampFloorMethod = Timestamps::floorYYYY;
intervalLengthMethod = Timestamps::getYearsBetween;
partitionTimestampCalculatorMethod = Timestamps::addYear;
break;
default:
partitionPathGenerator = DEFAULT_GEN;
......@@ -748,8 +748,8 @@ public class TableReader implements Closeable {
private Path pathGenDay(int partitionIndex) {
TableUtils.fmtDay.format(
Dates.addDays(minTimestamp, partitionIndex),
DateLocaleFactory.INSTANCE.getDefaultDateLocale(),
Timestamps.addDays(minTimestamp, partitionIndex),
TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale(),
null,
path.put(Files.SEPARATOR)
);
......@@ -762,8 +762,8 @@ public class TableReader implements Closeable {
private Path pathGenMonth(int partitionIndex) {
TableUtils.fmtMonth.format(
Dates.addMonths(minTimestamp, partitionIndex),
DateLocaleFactory.INSTANCE.getDefaultDateLocale(),
Timestamps.addMonths(minTimestamp, partitionIndex),
TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale(),
null,
path.put(Files.SEPARATOR)
);
......@@ -772,8 +772,8 @@ public class TableReader implements Closeable {
private Path pathGenYear(int partitionIndex) {
TableUtils.fmtYear.format(
Dates.addYear(minTimestamp, partitionIndex),
DateLocaleFactory.INSTANCE.getDefaultDateLocale(),
Timestamps.addYear(minTimestamp, partitionIndex),
TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale(),
null,
path.put(Files.SEPARATOR)
);
......
......@@ -28,9 +28,9 @@ import io.questdb.griffin.SqlException;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.std.*;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateFormatCompiler;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.LPSZ;
import io.questdb.std.str.Path;
......@@ -47,9 +47,9 @@ public final class TableUtils {
static final int MIN_INDEX_VALUE_BLOCK_SIZE = Numbers.ceilPow2(4);
static final byte TODO_RESTORE_META = 2;
static final byte TODO_TRUNCATE = 1;
static final DateFormat fmtDay;
static final DateFormat fmtMonth;
static final DateFormat fmtYear;
static final TimestampFormat fmtDay;
static final TimestampFormat fmtMonth;
static final TimestampFormat fmtYear;
static final String ARCHIVE_FILE_NAME = "_archive";
static final String DEFAULT_PARTITION_NAME = "default";
// transaction file structure
......@@ -433,11 +433,11 @@ public final class TableUtils {
case PartitionBy.NONE:
return true;
case PartitionBy.DAY:
return Dates.floorDD(timestampA) == Dates.floorDD(timestampB);
return Timestamps.floorDD(timestampA) == Timestamps.floorDD(timestampB);
case PartitionBy.MONTH:
return Dates.floorMM(timestampA) == Dates.floorMM(timestampB);
return Timestamps.floorMM(timestampA) == Timestamps.floorMM(timestampB);
case PartitionBy.YEAR:
return Dates.floorYYYY(timestampA) == Dates.floorYYYY(timestampB);
return Timestamps.floorYYYY(timestampA) == Timestamps.floorYYYY(timestampB);
default:
throw CairoException.instance(0).put("Cannot compare timestamps for unsupported partition type: [").put(partitionBy).put(']');
}
......
......@@ -31,10 +31,10 @@ import io.questdb.mp.RingQueue;
import io.questdb.mp.SOCountDownLatch;
import io.questdb.mp.Sequence;
import io.questdb.std.*;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.DateLocaleFactory;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.LPSZ;
import io.questdb.std.str.NativeLPSZ;
import io.questdb.std.str.Path;
......@@ -82,7 +82,7 @@ public class TableWriter implements Closeable {
private final NativeLPSZ nativeLPSZ = new NativeLPSZ();
private final LongList columnTops;
private final FilesFacade ff;
private final DateFormat partitionDirFmt;
private final TimestampFormat partitionDirFmt;
private final AppendMemory ddlMem;
private final int mkDirMode;
private final int fileOperationRetryCount;
......@@ -193,19 +193,19 @@ public class TableWriter implements Closeable {
this.columnTops = new LongList(columnCount);
switch (partitionBy) {
case PartitionBy.DAY:
timestampFloorMethod = Dates::floorDD;
nextTimestampMethod = Dates::addDays;
timestampFloorMethod = Timestamps::floorDD;
nextTimestampMethod = Timestamps::addDays;
partitionDirFmt = fmtDay;
break;
case PartitionBy.MONTH:
timestampFloorMethod = Dates::floorMM;
nextTimestampMethod = Dates::addMonths;
timestampFloorMethod = Timestamps::floorMM;
nextTimestampMethod = Timestamps::addMonths;
partitionDirFmt = fmtMonth;
break;
case PartitionBy.YEAR:
// year
timestampFloorMethod = Dates::floorYYYY;
nextTimestampMethod = Dates::addYear;
timestampFloorMethod = Timestamps::floorYYYY;
nextTimestampMethod = Timestamps::addYear;
partitionDirFmt = fmtYear;
break;
default:
......@@ -227,7 +227,7 @@ public class TableWriter implements Closeable {
}
}
public static DateFormat selectPartitionDirFmt(int partitionBy) {
public static TimestampFormat selectPartitionDirFmt(int partitionBy) {
switch (partitionBy) {
case PartitionBy.DAY:
return fmtDay;
......@@ -1660,7 +1660,7 @@ public class TableWriter implements Closeable {
nativeLPSZ.of(pName);
if (IGNORED_FILES.excludes(nativeLPSZ) && type == Files.DT_DIR) {
try {
long dirTimestamp = partitionDirFmt.parse(nativeLPSZ, DateLocaleFactory.INSTANCE.getDefaultDateLocale());
long dirTimestamp = partitionDirFmt.parse(nativeLPSZ, TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale());
if (dirTimestamp <= timestamp) {
return;
}
......@@ -1873,10 +1873,10 @@ public class TableWriter implements Closeable {
path.put(Files.SEPARATOR);
switch (partitionBy) {
case PartitionBy.DAY:
y = Dates.getYear(timestamp);
leap = Dates.isLeapYear(y);
m = Dates.getMonthOfYear(timestamp, y, leap);
d = Dates.getDayOfMonth(timestamp, y, m, leap);
y = Timestamps.getYear(timestamp);
leap = Timestamps.isLeapYear(y);
m = Timestamps.getMonthOfYear(timestamp, y, leap);
d = Timestamps.getDayOfMonth(timestamp, y, m, leap);
DateFormatUtils.append000(path, y);
path.put('-');
DateFormatUtils.append0(path, m);
......@@ -1885,32 +1885,32 @@ public class TableWriter implements Closeable {
if (updatePartitionInterval) {
partitionHi =
Dates.yearMicros(y, leap)
+ Dates.monthOfYearMicros(m, leap)
+ (d - 1) * Dates.DAY_MICROS + 24 * Dates.HOUR_MICROS;
Timestamps.yearMicros(y, leap)
+ Timestamps.monthOfYearMicros(m, leap)
+ (d - 1) * Timestamps.DAY_MICROS + 24 * Timestamps.HOUR_MICROS;
}
break;
case PartitionBy.MONTH:
y = Dates.getYear(timestamp);
leap = Dates.isLeapYear(y);
m = Dates.getMonthOfYear(timestamp, y, leap);
y = Timestamps.getYear(timestamp);
leap = Timestamps.isLeapYear(y);
m = Timestamps.getMonthOfYear(timestamp, y, leap);
DateFormatUtils.append000(path, y);
path.put('-');
DateFormatUtils.append0(path, m);
if (updatePartitionInterval) {
partitionHi =
Dates.yearMicros(y, leap)
+ Dates.monthOfYearMicros(m, leap)
+ Dates.getDaysPerMonth(m, leap) * 24L * Dates.HOUR_MICROS;
Timestamps.yearMicros(y, leap)
+ Timestamps.monthOfYearMicros(m, leap)
+ Timestamps.getDaysPerMonth(m, leap) * 24L * Timestamps.HOUR_MICROS;
}
break;
case PartitionBy.YEAR:
y = Dates.getYear(timestamp);
leap = Dates.isLeapYear(y);
y = Timestamps.getYear(timestamp);
leap = Timestamps.isLeapYear(y);
DateFormatUtils.append000(path, y);
if (updatePartitionInterval) {
partitionHi = Dates.addYear(Dates.yearMicros(y, leap), 1);
partitionHi = Timestamps.addYear(Timestamps.yearMicros(y, leap), 1);
}
break;
default:
......
......@@ -30,6 +30,7 @@ import io.questdb.cutlass.json.JsonLexer;
import io.questdb.cutlass.text.types.InputFormatConfiguration;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.mp.EagerThreadSetup;
import io.questdb.mp.Job;
import io.questdb.mp.WorkerPool;
import io.questdb.mp.WorkerPoolConfiguration;
......@@ -39,6 +40,8 @@ import io.questdb.network.IODispatchers;
import io.questdb.network.IORequestProcessor;
import io.questdb.std.ThreadLocal;
import io.questdb.std.*;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocaleFactory;
import org.jetbrains.annotations.Nullable;
......@@ -104,12 +107,12 @@ public class HttpServer implements Closeable {
) throws JsonException {
if (configuration.isEnabled()) {
final DateFormatFactory dateFormatFactory = new DateFormatFactory();
final io.questdb.std.microtime.DateFormatFactory timestampFormatFactory = new io.questdb.std.microtime.DateFormatFactory();
final TimestampFormatFactory timestampFormatFactory = new TimestampFormatFactory();
final InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
dateFormatFactory,
DateLocaleFactory.INSTANCE,
timestampFormatFactory,
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
TimestampLocaleFactory.INSTANCE
);
try (JsonLexer jsonLexer = new JsonLexer(configuration.getTextImportProcessorConfiguration().getTextConfiguration().getJsonCacheSize(), configuration.getTextImportProcessorConfiguration().getTextConfiguration().getJsonCacheLimit())) {
......@@ -266,7 +269,7 @@ public class HttpServer implements Closeable {
}
}
private static class HttpContextFactory implements IOContextFactory<HttpConnectionContext>, Closeable {
private static class HttpContextFactory implements IOContextFactory<HttpConnectionContext>, Closeable, EagerThreadSetup {
private final ThreadLocal<WeakObjectPool<HttpConnectionContext>> contextPool;
private boolean closed = false;
......@@ -296,6 +299,11 @@ public class HttpServer implements Closeable {
}
}
@Override
public void setup() {
contextPool.get();
}
private void closeContextPool() {
Misc.free(this.contextPool.get());
LOG.info().$("closed").$();
......
......@@ -255,7 +255,7 @@ public class JsonQueryProcessor implements HttpRequestProcessor, Closeable {
// todo: configure the following
// - when happens when data row errors out, max errors may be?
// - we should be able to skip X rows from top, dodgy headers etc.
textLoader.configureDestination(model.getTableName().token, true, false, Atomicity.SKIP_ROW);
textLoader.configureDestination(model.getTableName().token, false, false, Atomicity.SKIP_ROW);
int len = configuration.getCopyBufferSize();
long buf = Unsafe.malloc(len);
try {
......
......@@ -26,6 +26,7 @@ package io.questdb.cutlass.pgwire;
import io.questdb.cairo.CairoEngine;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.mp.EagerThreadSetup;
import io.questdb.mp.Job;
import io.questdb.mp.WorkerPool;
import io.questdb.mp.WorkerPoolConfiguration;
......@@ -129,7 +130,7 @@ public class PGWireServer implements Closeable {
Misc.free(dispatcher);
}
private static class PGConnectionContextFactory implements IOContextFactory<PGConnectionContext>, Closeable {
private static class PGConnectionContextFactory implements IOContextFactory<PGConnectionContext>, Closeable, EagerThreadSetup {
private final ThreadLocal<WeakObjectPool<PGConnectionContext>> contextPool;
private boolean closed = false;
......@@ -159,6 +160,11 @@ public class PGWireServer implements Closeable {
}
}
@Override
public void setup() {
contextPool.get();
}
private void closeContextPool() {
Misc.free(this.contextPool.get());
LOG.info().$("closed").$();
......
......@@ -32,6 +32,9 @@ import io.questdb.cutlass.text.types.TypeManager;
import io.questdb.log.Log;
import io.questdb.log.LogFactory;
import io.questdb.std.*;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.AbstractCharSequence;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocale;
......@@ -51,10 +54,10 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
private static final int P_LOCALE = 4;
private static final CharSequenceIntHashMap propertyNameMap = new CharSequenceIntHashMap();
private final DateLocaleFactory dateLocaleFactory;
private final io.questdb.std.microtime.DateLocaleFactory timestampLocaleFactory;
private final TimestampLocaleFactory timestampLocaleFactory;
private final ObjectPool<FloatingCharSequence> csPool;
private final DateFormatFactory dateFormatFactory;
private final io.questdb.std.microtime.DateFormatFactory timestampFormatFactory;
private final TimestampFormatFactory timestampFormatFactory;
private final ObjList<CharSequence> columnNames;
private final ObjList<TypeAdapter> columnTypes;
private final TypeManager typeManager;
......@@ -217,9 +220,9 @@ public class TextMetadataParser implements JsonParser, Mutable, Closeable {
columnTypes.add(typeManager.nextDateAdapter().of(dateFormatFactory.get(pattern), dateLocale));
break;
case ColumnType.TIMESTAMP:
io.questdb.std.microtime.DateLocale timestampLocale =
TimestampLocale timestampLocale =
locale == null ?
timestampLocaleFactory.getDefaultDateLocale()
timestampLocaleFactory.getDefaultTimestampLocale()
: timestampLocaleFactory.getDateLocale(locale);
if (timestampLocale == null) {
throw JsonException.$(localePosition, "Invalid timestamp locale");
......
......@@ -30,6 +30,10 @@ import io.questdb.log.LogFactory;
import io.questdb.std.Chars;
import io.questdb.std.ObjList;
import io.questdb.std.Unsafe;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.time.DateFormat;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocale;
......@@ -52,23 +56,23 @@ public class InputFormatConfiguration {
private static final int STATE_EXPECT_TIMESTAMP_FORMAT_ENTRY = 9;
private final ObjList<DateFormat> dateFormats = new ObjList<>();
private final ObjList<DateLocale> dateLocales = new ObjList<>();
private final ObjList<io.questdb.std.microtime.DateFormat> timestampFormats = new ObjList<>();
private final ObjList<io.questdb.std.microtime.DateLocale> timestampLocales = new ObjList<>();
private final ObjList<TimestampFormat> timestampFormats = new ObjList<>();
private final ObjList<TimestampLocale> timestampLocales = new ObjList<>();
private final DateFormatFactory dateFormatFactory;
private final DateLocaleFactory dateLocaleFactory;
private final io.questdb.std.microtime.DateFormatFactory timestampFormatFactory;
private final io.questdb.std.microtime.DateLocaleFactory timestampLocaleFactory;
private final TimestampFormatFactory timestampFormatFactory;
private final TimestampLocaleFactory timestampLocaleFactory;
private int jsonState = STATE_EXPECT_TOP; // expect start of object
private DateFormat jsonDateFormat;
private DateLocale jsonDateLocale;
private io.questdb.std.microtime.DateFormat jsonTimestampFormat;
private io.questdb.std.microtime.DateLocale jsonTimestampLocale;
private TimestampFormat jsonTimestampFormat;
private TimestampLocale jsonTimestampLocale;
public InputFormatConfiguration(
DateFormatFactory dateFormatFactory,
DateLocaleFactory dateLocaleFactory,
io.questdb.std.microtime.DateFormatFactory timestampFormatFactory,
io.questdb.std.microtime.DateLocaleFactory timestampLocaleFactory
TimestampFormatFactory timestampFormatFactory,
TimestampLocaleFactory timestampLocaleFactory
) {
this.dateFormatFactory = dateFormatFactory;
this.dateLocaleFactory = dateLocaleFactory;
......@@ -104,19 +108,19 @@ public class InputFormatConfiguration {
return dateLocales;
}
public io.questdb.std.microtime.DateFormatFactory getTimestampFormatFactory() {
public TimestampFormatFactory getTimestampFormatFactory() {
return timestampFormatFactory;
}
public ObjList<io.questdb.std.microtime.DateFormat> getTimestampFormats() {
public ObjList<TimestampFormat> getTimestampFormats() {
return timestampFormats;
}
public io.questdb.std.microtime.DateLocaleFactory getTimestampLocaleFactory() {
public TimestampLocaleFactory getTimestampLocaleFactory() {
return timestampLocaleFactory;
}
public ObjList<io.questdb.std.microtime.DateLocale> getTimestampLocales() {
public ObjList<TimestampLocale> getTimestampLocales() {
return timestampLocales;
}
......@@ -195,7 +199,7 @@ public class InputFormatConfiguration {
}
timestampFormats.add(jsonTimestampFormat);
timestampLocales.add(jsonTimestampLocale == null ? io.questdb.std.microtime.DateLocaleFactory.INSTANCE.getDefaultDateLocale() : jsonTimestampLocale);
timestampLocales.add(jsonTimestampLocale == null ? TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale() : jsonTimestampLocale);
break;
default:
// the only time we get here would be when
......
......@@ -28,15 +28,15 @@ import io.questdb.cairo.TableWriter;
import io.questdb.cutlass.text.TextUtil;
import io.questdb.std.Mutable;
import io.questdb.std.NumericException;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateLocale;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.str.DirectByteCharSequence;
import io.questdb.std.str.DirectCharSink;
public class TimestampAdapter extends AbstractTypeAdapter implements Mutable {
private final DirectCharSink utf8Sink;
private DateLocale locale;
private DateFormat format;
private TimestampLocale locale;
private TimestampFormat format;
public TimestampAdapter(DirectCharSink utf8Sink) {
this.utf8Sink = utf8Sink;
......@@ -70,7 +70,7 @@ public class TimestampAdapter extends AbstractTypeAdapter implements Mutable {
row.putDate(column, format.parse(utf8Sink, locale));
}
public TimestampAdapter of(DateFormat format, DateLocale locale) {
public TimestampAdapter of(TimestampFormat format, TimestampLocale locale) {
this.format = format;
this.locale = locale;
return this;
......
......@@ -29,6 +29,8 @@ import io.questdb.cutlass.text.TextConfiguration;
import io.questdb.std.Mutable;
import io.questdb.std.ObjList;
import io.questdb.std.ObjectPool;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.str.DirectCharSink;
import io.questdb.std.time.DateFormat;
import io.questdb.std.time.DateLocale;
......@@ -59,8 +61,8 @@ public class TypeManager implements Mutable {
for (int i = 0, n = dateFormats.size(); i < n; i++) {
probes.add(new DateAdapter(utf8Sink).of(dateFormats.getQuick(i), dateLocales.getQuick(i)));
}
final ObjList<io.questdb.std.microtime.DateFormat> timestampFormats = inputFormatConfiguration.getTimestampFormats();
final ObjList<io.questdb.std.microtime.DateLocale> timestampLocales = inputFormatConfiguration.getTimestampLocales();
final ObjList<TimestampFormat> timestampFormats = inputFormatConfiguration.getTimestampFormats();
final ObjList<TimestampLocale> timestampLocales = inputFormatConfiguration.getTimestampLocales();
for (int i = 0, n = timestampFormats.size(); i < n; i++) {
probes.add(new TimestampAdapter(utf8Sink).of(timestampFormats.getQuick(i), timestampLocales.getQuick(i)));
}
......
......@@ -33,10 +33,10 @@ import io.questdb.griffin.engine.functions.UnaryFunction;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.ObjList;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateFormatCompiler;
import io.questdb.std.microtime.DateLocale;
import io.questdb.std.microtime.DateLocaleFactory;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.microtime.TimestampLocaleFactory;
public class ToTimestampVCFunctionFactory implements FunctionFactory {
private static final ThreadLocal<DateFormatCompiler> tlCompiler = ThreadLocal.withInitial(DateFormatCompiler::new);
......@@ -53,19 +53,19 @@ public class ToTimestampVCFunctionFactory implements FunctionFactory {
if (pattern == null) {
throw SqlException.$(args.getQuick(1).getPosition(), "pattern is required");
}
return new Func(position, arg, tlCompiler.get().compile(pattern), DateLocaleFactory.INSTANCE.getDefaultDateLocale());
return new Func(position, arg, tlCompiler.get().compile(pattern), TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale());
}
private static final class Func extends TimestampFunction implements UnaryFunction {
private final Function arg;
private final DateFormat dateFormat;
private final DateLocale locale;
private final TimestampFormat timestampFormat;
private final TimestampLocale locale;
public Func(int position, Function arg, DateFormat dateFormat, DateLocale locale) {
public Func(int position, Function arg, TimestampFormat timestampFormat, TimestampLocale locale) {
super(position);
this.arg = arg;
this.dateFormat = dateFormat;
this.timestampFormat = timestampFormat;
this.locale = locale;
}
......@@ -79,7 +79,7 @@ public class ToTimestampVCFunctionFactory implements FunctionFactory {
CharSequence value = arg.getStr(rec);
try {
if (value != null) {
return dateFormat.parse(value, locale);
return timestampFormat.parse(value, locale);
}
} catch (NumericException ignore) {
}
......
......@@ -34,10 +34,10 @@ import io.questdb.griffin.engine.functions.constants.NullConstant;
import io.questdb.griffin.engine.functions.constants.StrConstant;
import io.questdb.std.Numbers;
import io.questdb.std.ObjList;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateFormatCompiler;
import io.questdb.std.microtime.DateLocale;
import io.questdb.std.microtime.DateLocaleFactory;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocale;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.CharSink;
import io.questdb.std.str.StringSink;
import org.jetbrains.annotations.Nullable;
......@@ -60,7 +60,7 @@ public class ToCharTimestampFunctionFactory implements FunctionFactory {
throw SqlException.$(fmt.getPosition(), "format must not be null");
}
DateFormat dateFormat = tlCompiler.get().compile(fmt.getStr(null));
TimestampFormat timestampFormat = tlCompiler.get().compile(fmt.getStr(null));
Function var = args.getQuick(0);
if (var.isConstant()) {
long value = var.getTimestamp(null);
......@@ -70,25 +70,25 @@ public class ToCharTimestampFunctionFactory implements FunctionFactory {
StringSink sink = tlSink.get();
sink.clear();
dateFormat.format(value, DateLocaleFactory.INSTANCE.getDefaultDateLocale(), "Z", sink);
timestampFormat.format(value, TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale(), "Z", sink);
return new StrConstant(position, sink);
}
return new ToCharDateFFunc(position, args.getQuick(0), dateFormat);
return new ToCharDateFFunc(position, args.getQuick(0), timestampFormat);
}
private static class ToCharDateFFunc extends StrFunction implements UnaryFunction {
final Function arg;
final DateFormat format;
final DateLocale locale;
final TimestampFormat format;
final TimestampLocale locale;
final StringSink sink1;
final StringSink sink2;
public ToCharDateFFunc(int position, Function arg, DateFormat format) {
public ToCharDateFFunc(int position, Function arg, TimestampFormat format) {
super(position);
this.arg = arg;
this.format = format;
locale = DateLocaleFactory.INSTANCE.getDefaultDateLocale();
locale = TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale();
sink1 = new StringSink();
sink2 = new StringSink();
}
......
......@@ -23,7 +23,7 @@
package io.questdb.griffin.engine.groupby;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
class MonthTimestampSampler implements TimestampSampler {
private final int bucket;
......@@ -34,22 +34,22 @@ class MonthTimestampSampler implements TimestampSampler {
@Override
public long nextTimestamp(long timestamp) {
return Dates.addMonths(timestamp, bucket);
return Timestamps.addMonths(timestamp, bucket);
}
@Override
public long previousTimestamp(long timestamp) {
return Dates.addMonths(timestamp, -bucket);
return Timestamps.addMonths(timestamp, -bucket);
}
@Override
public long round(long value) {
int y = Dates.getYear(value);
boolean l = Dates.isLeapYear(y);
int m = Dates.getMonthOfYear(value, y, l);
int y = Timestamps.getYear(value);
boolean l = Timestamps.isLeapYear(y);
int m = Timestamps.getMonthOfYear(value, y, l);
// target month
int n = ((m - 1) / bucket) * bucket + 1;
return Dates.yearMicros(y, l) +
Dates.monthOfYearMicros(n, l);
return Timestamps.yearMicros(y, l) +
Timestamps.monthOfYearMicros(n, l);
}
}
......@@ -26,7 +26,7 @@ package io.questdb.griffin.engine.groupby;
import io.questdb.griffin.SqlException;
import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
public final class TimestampSamplerFactory {
......@@ -79,16 +79,16 @@ public final class TimestampSamplerFactory {
switch (cs.charAt(k)) {
case 's':
// seconds
return new MicroTimestampSampler(Dates.SECOND_MICROS * n);
return new MicroTimestampSampler(Timestamps.SECOND_MICROS * n);
case 'm':
// minutes
return new MicroTimestampSampler(Dates.MINUTE_MICROS * n);
return new MicroTimestampSampler(Timestamps.MINUTE_MICROS * n);
case 'h':
// hours
return new MicroTimestampSampler(Dates.HOUR_MICROS * n);
return new MicroTimestampSampler(Timestamps.HOUR_MICROS * n);
case 'd':
// days
return new MicroTimestampSampler(Dates.DAY_MICROS * n);
return new MicroTimestampSampler(Timestamps.DAY_MICROS * n);
case 'M':
// months
return new MonthTimestampSampler(n);
......
......@@ -23,7 +23,7 @@
package io.questdb.griffin.engine.groupby;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
class YearTimestampSampler implements TimestampSampler {
......@@ -35,18 +35,18 @@ class YearTimestampSampler implements TimestampSampler {
@Override
public long nextTimestamp(long timestamp) {
return Dates.addYear(timestamp, bucket);
return Timestamps.addYear(timestamp, bucket);
}
@Override
public long previousTimestamp(long timestamp) {
return Dates.addYear(timestamp, -bucket);
return Timestamps.addYear(timestamp, -bucket);
}
@Override
public long round(long value) {
int y = Dates.getYear(value);
int y = Timestamps.getYear(value);
y = y - y % bucket;
return Dates.yearMicros(y, Dates.isLeapYear(y));
return Timestamps.yearMicros(y, Timestamps.isLeapYear(y));
}
}
......@@ -26,7 +26,7 @@ package io.questdb.griffin.model;
import io.questdb.griffin.SqlException;
import io.questdb.std.*;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
public class IntrinsicModel implements Mutable {
public static final ObjectFactory<IntrinsicModel> FACTORY = IntrinsicModel::new;
......@@ -184,16 +184,16 @@ public class IntrinsicModel implements Mutable {
addMonthInterval(period, count, out);
break;
case 'h':
addMillisInterval(period * Dates.HOUR_MICROS, count, out);
addMillisInterval(period * Timestamps.HOUR_MICROS, count, out);
break;
case 'm':
addMillisInterval(period * Dates.MINUTE_MICROS, count, out);
addMillisInterval(period * Timestamps.MINUTE_MICROS, count, out);
break;
case 's':
addMillisInterval(period * Dates.SECOND_MICROS, count, out);
addMillisInterval(period * Timestamps.SECOND_MICROS, count, out);
break;
case 'd':
addMillisInterval(period * Dates.DAY_MICROS, count, out);
addMillisInterval(period * Timestamps.DAY_MICROS, count, out);
break;
default:
throw SqlException.$(position, "Unknown period: " + type + " at " + (p - 1));
......@@ -210,7 +210,7 @@ public class IntrinsicModel implements Mutable {
}
int p = pos;
int year = Numbers.parseInt(seq, p, p += 4);
boolean l = Dates.isLeapYear(year);
boolean l = Timestamps.isLeapYear(year);
if (checkLen(p, lim)) {
checkChar(seq, p++, lim, '-');
int month = Numbers.parseInt(seq, p, p += 2);
......@@ -218,7 +218,7 @@ public class IntrinsicModel implements Mutable {
if (checkLen(p, lim)) {
checkChar(seq, p++, lim, '-');
int day = Numbers.parseInt(seq, p, p += 2);
checkRange(day, 1, Dates.getDaysPerMonth(month, l));
checkRange(day, 1, Timestamps.getDaysPerMonth(month, l));
if (checkLen(p, lim)) {
checkChar(seq, p++, lim, 'T');
int hour = Numbers.parseInt(seq, p, p += 2);
......@@ -235,82 +235,82 @@ public class IntrinsicModel implements Mutable {
throw NumericException.INSTANCE;
} else {
// seconds
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ min * Dates.MINUTE_MICROS
+ sec * Dates.SECOND_MICROS);
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ min * Dates.MINUTE_MICROS
+ sec * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ min * Timestamps.MINUTE_MICROS
+ sec * Timestamps.SECOND_MICROS);
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ min * Timestamps.MINUTE_MICROS
+ sec * Timestamps.SECOND_MICROS
+ 999999);
}
} else {
// minute
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ min * Dates.MINUTE_MICROS);
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ min * Dates.MINUTE_MICROS
+ 59 * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ min * Timestamps.MINUTE_MICROS);
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ min * Timestamps.MINUTE_MICROS
+ 59 * Timestamps.SECOND_MICROS
+ 999999);
}
} else {
// year + month + day + hour
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS);
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ 59 * Dates.MINUTE_MICROS
+ 59 * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS);
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ 59 * Timestamps.MINUTE_MICROS
+ 59 * Timestamps.SECOND_MICROS
+ 999999);
}
} else {
// year + month + day
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (day - 1) * Dates.DAY_MICROS);
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ +(day - 1) * Dates.DAY_MICROS
+ 23 * Dates.HOUR_MICROS
+ 59 * Dates.MINUTE_MICROS
+ 59 * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (day - 1) * Timestamps.DAY_MICROS);
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ +(day - 1) * Timestamps.DAY_MICROS
+ 23 * Timestamps.HOUR_MICROS
+ 59 * Timestamps.MINUTE_MICROS
+ 59 * Timestamps.SECOND_MICROS
+ 999999);
}
} else {
// year + month
out.add(Dates.yearMicros(year, l) + Dates.monthOfYearMicros(month, l));
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(month, l)
+ (Dates.getDaysPerMonth(month, l) - 1) * Dates.DAY_MICROS
+ 23 * Dates.HOUR_MICROS
+ 59 * Dates.MINUTE_MICROS
+ 59 * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l) + Timestamps.monthOfYearMicros(month, l));
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(month, l)
+ (Timestamps.getDaysPerMonth(month, l) - 1) * Timestamps.DAY_MICROS
+ 23 * Timestamps.HOUR_MICROS
+ 59 * Timestamps.MINUTE_MICROS
+ 59 * Timestamps.SECOND_MICROS
+ 999999);
}
} else {
// year
out.add(Dates.yearMicros(year, l) + Dates.monthOfYearMicros(1, l));
out.add(Dates.yearMicros(year, l)
+ Dates.monthOfYearMicros(12, l)
+ (Dates.getDaysPerMonth(12, l) - 1) * Dates.DAY_MICROS
+ 23 * Dates.HOUR_MICROS
+ 59 * Dates.MINUTE_MICROS
+ 59 * Dates.SECOND_MICROS
out.add(Timestamps.yearMicros(year, l) + Timestamps.monthOfYearMicros(1, l));
out.add(Timestamps.yearMicros(year, l)
+ Timestamps.monthOfYearMicros(12, l)
+ (Timestamps.getDaysPerMonth(12, l) - 1) * Timestamps.DAY_MICROS
+ 23 * Timestamps.HOUR_MICROS
+ 59 * Timestamps.MINUTE_MICROS
+ 59 * Timestamps.SECOND_MICROS
+ 999999);
}
}
......@@ -340,14 +340,14 @@ public class IntrinsicModel implements Mutable {
try {
parseInterval(seq, lo, p, out);
int n = out.size();
out.setQuick(n - 1, Dates.addPeriod(out.getQuick(n - 1), type, period));
out.setQuick(n - 1, Timestamps.addPeriod(out.getQuick(n - 1), type, period));
return;
} catch (NumericException ignore) {
// try date instead
}
try {
long loMillis = DateFormatUtils.tryParse(seq, lo, p);
append(out, loMillis, Dates.addPeriod(loMillis, type, period));
append(out, loMillis, Timestamps.addPeriod(loMillis, type, period));
} catch (NumericException e) {
throw SqlException.invalidDate(position);
}
......@@ -371,8 +371,8 @@ public class IntrinsicModel implements Mutable {
long hi = out.getQuick(k - 1);
for (int i = 0, n = count - 1; i < n; i++) {
lo = Dates.addMonths(lo, period);
hi = Dates.addMonths(hi, period);
lo = Timestamps.addMonths(lo, period);
hi = Timestamps.addMonths(hi, period);
append(out, lo, hi);
}
}
......@@ -383,8 +383,8 @@ public class IntrinsicModel implements Mutable {
long hi = out.getQuick(k - 1);
for (int i = 0, n = count - 1; i < n; i++) {
lo = Dates.addYear(lo, period);
hi = Dates.addYear(hi, period);
lo = Timestamps.addYear(lo, period);
hi = Timestamps.addYear(hi, period);
append(out, lo, hi);
}
}
......
......@@ -253,23 +253,23 @@ public class LogRollingFileWriter extends SynchronizedJob implements Closeable,
}
private long getNextDayDealine() {
return Dates.addDays(Dates.floorDD(clock.getTicks()), 1);
return Timestamps.addDays(Timestamps.floorDD(clock.getTicks()), 1);
}
private long getNextHourDeadline() {
return Dates.addHours(Dates.floorHH(clock.getTicks()), 1);
return Timestamps.addHours(Timestamps.floorHH(clock.getTicks()), 1);
}
private long getNextMinuteDeadline() {
return Dates.floorMI(clock.getTicks()) + Dates.MINUTE_MICROS;
return Timestamps.floorMI(clock.getTicks()) + Timestamps.MINUTE_MICROS;
}
private long getNextMonthDeadline() {
return Dates.addMonths(Dates.floorMM(clock.getTicks()), 1);
return Timestamps.addMonths(Timestamps.floorMM(clock.getTicks()), 1);
}
private long getNextYearDeadline() {
return Dates.addYear(Dates.floorYYYY(clock.getTicks()), 1);
return Timestamps.addYear(Timestamps.floorYYYY(clock.getTicks()), 1);
}
private void openFile() {
......@@ -406,9 +406,9 @@ public class LogRollingFileWriter extends SynchronizedJob implements Closeable,
}
private class DateSinkable implements Sinkable {
private final DateFormat format;
private final TimestampFormat format;
public DateSinkable(DateFormat format) {
public DateSinkable(TimestampFormat format) {
this.format = format;
}
......@@ -416,7 +416,7 @@ public class LogRollingFileWriter extends SynchronizedJob implements Closeable,
public void toSink(CharSink sink) {
format.format(
fileTimestamp,
DateLocaleFactory.INSTANCE.getDefaultDateLocale(),
TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale(),
null,
sink
);
......
/*******************************************************************************
* ___ _ ____ ____
* / _ \ _ _ ___ ___| |_| _ \| __ )
* | | | | | | |/ _ \/ __| __| | | | _ \
* | |_| | |_| | __/\__ \ |_| |_| | |_) |
* \__\_\\__,_|\___||___/\__|____/|____/
*
* Copyright (C) 2014-2019 Appsicle
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
package io.questdb.mp;
@FunctionalInterface
public interface EagerThreadSetup {
void setup();
}
......@@ -25,7 +25,4 @@ package io.questdb.mp;
public interface Job {
boolean run();
default void setupThread() {
}
}
......@@ -79,7 +79,6 @@ public class Worker extends Thread {
Throwable ex = null;
try {
if (Unsafe.getUnsafe().compareAndSwapInt(this, RUNNING_OFFSET, 0, 1)) {
setupJobs();
if (affinity > -1) {
if (Os.setCurrentThreadAffinity(this.affinity) == 0) {
if (log != null) {
......@@ -95,6 +94,7 @@ public class Worker extends Thread {
log.info().$("os scheduled [name=").$(getName()).$(']').$();
}
}
setupJobs();
int n = jobs.size();
long uselessCounter = 0;
while (running == 1) {
......@@ -163,7 +163,10 @@ public class Worker extends Thread {
for (int i = 0; i < jobs.size(); i++) {
loadFence();
try {
jobs.get(i).setupThread();
Job job = jobs.get(i);
if (job instanceof EagerThreadSetup) {
((EagerThreadSetup) job).setup();
}
} finally {
storeFence();
}
......
......@@ -31,7 +31,7 @@ import io.questdb.std.time.MillisecondClock;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class AbstractIODispatcher<C extends IOContext> extends SynchronizedJob implements IODispatcher<C> {
public abstract class AbstractIODispatcher<C extends IOContext> extends SynchronizedJob implements IODispatcher<C>, EagerThreadSetup {
protected static final int M_TIMESTAMP = 0;
protected static final int M_FD = 1;
protected final Log LOG;
......@@ -96,6 +96,13 @@ public abstract class AbstractIODispatcher<C extends IOContext> extends Synchron
}
}
@Override
public void setup() {
if (ioContextFactory instanceof EagerThreadSetup) {
((EagerThreadSetup) ioContextFactory).setup();
}
}
@Override
public void close() {
processDisconnects();
......@@ -205,7 +212,6 @@ public abstract class AbstractIODispatcher<C extends IOContext> extends Synchron
pending.set(r, M_FD, fd);
pending.set(r, ioContextFactory.newInstance(fd));
pendingAdded(r);
}
private void disconnectContext(IOEvent<C> event) {
......
......@@ -25,10 +25,10 @@ package io.questdb.std.microtime;
import io.questdb.std.NumericException;
public abstract class AbstractDateFormat implements DateFormat {
public abstract class AbstractTimestampFormat implements TimestampFormat {
@Override
public long parse(CharSequence in, DateLocale locale) throws NumericException {
public long parse(CharSequence in, TimestampLocale locale) throws NumericException {
return parse(in, 0, in.length(), locale);
}
}
......@@ -174,15 +174,15 @@ public class DateFormatCompiler {
opList.add(op);
}
public DateFormat compile(CharSequence pattern) {
public TimestampFormat compile(CharSequence pattern) {
return compile(pattern, false);
}
public DateFormat compile(CharSequence pattern, boolean generic) {
public TimestampFormat compile(CharSequence pattern, boolean generic) {
return compile(pattern, 0, pattern.length(), generic);
}
public DateFormat compile(CharSequence pattern, int lo, int hi, boolean generic) {
public TimestampFormat compile(CharSequence pattern, int lo, int hi, boolean generic) {
this.lexer.of(pattern, lo, hi);
IntList ops;
......@@ -215,7 +215,7 @@ public class DateFormatCompiler {
// make last operation "greedy"
makeLastOpGreedy(ops);
return generic ? new GenericDateFormat(ops, delimiters) : compile(ops, delimiters);
return generic ? new GenericTimestampFormat(ops, delimiters) : compile(ops, delimiters);
}
private void addTempToPos(int decodeLenIndex) {
......@@ -1333,27 +1333,27 @@ public class DateFormatCompiler {
* from removing redundant local variable initialization code. For example year has to be defaulted to 1970 when
* it isn't present in the pattern and does not have to be defaulted at all when it is.
*/
private DateFormat compile(IntList ops, ObjList<String> delimiters) {
asm.init(DateFormat.class);
private TimestampFormat compile(IntList ops, ObjList<String> delimiters) {
asm.init(TimestampFormat.class);
asm.setupPool();
int thisClassIndex = asm.poolClass(asm.poolUtf8("io/questdb/std/microtime/DateFormatAsm"));
int thisClassIndex = asm.poolClass(asm.poolUtf8("io/questdb/std/microtime/TimestampFormatAsm"));
int stackMapTableIndex = asm.poolUtf8("StackMapTable");
int superclassIndex = asm.poolClass(AbstractDateFormat.class);
int dateLocaleClassIndex = asm.poolClass(DateLocale.class);
int superclassIndex = asm.poolClass(AbstractTimestampFormat.class);
int dateLocaleClassIndex = asm.poolClass(TimestampLocale.class);
int charSequenceClassIndex = asm.poolClass(CharSequence.class);
int minLongIndex = asm.poolLongConst(Long.MIN_VALUE);
int minMillisIndex = asm.poolLongConst(Dates.MINUTE_MICROS);
int minMillisIndex = asm.poolLongConst(Timestamps.MINUTE_MICROS);
int superIndex = asm.poolMethod(superclassIndex, "<init>", "()V");
int matchWeekdayIndex = asm.poolMethod(DateLocale.class, "matchWeekday", "(Ljava/lang/CharSequence;II)J");
int matchMonthIndex = asm.poolMethod(DateLocale.class, "matchMonth", "(Ljava/lang/CharSequence;II)J");
int matchZoneIndex = asm.poolMethod(DateLocale.class, "matchZone", "(Ljava/lang/CharSequence;II)J");
int matchAMPMIndex = asm.poolMethod(DateLocale.class, "matchAMPM", "(Ljava/lang/CharSequence;II)J");
int matchEraIndex = asm.poolMethod(DateLocale.class, "matchEra", "(Ljava/lang/CharSequence;II)J");
int getWeekdayIndex = asm.poolMethod(DateLocale.class, "getWeekday", "(I)Ljava/lang/String;");
int getShortWeekdayIndex = asm.poolMethod(DateLocale.class, "getShortWeekday", "(I)Ljava/lang/String;");
int getMonthIndex = asm.poolMethod(DateLocale.class, "getMonth", "(I)Ljava/lang/String;");
int getShortMonthIndex = asm.poolMethod(DateLocale.class, "getShortMonth", "(I)Ljava/lang/String;");
int matchWeekdayIndex = asm.poolMethod(TimestampLocale.class, "matchWeekday", "(Ljava/lang/CharSequence;II)J");
int matchMonthIndex = asm.poolMethod(TimestampLocale.class, "matchMonth", "(Ljava/lang/CharSequence;II)J");
int matchZoneIndex = asm.poolMethod(TimestampLocale.class, "matchZone", "(Ljava/lang/CharSequence;II)J");
int matchAMPMIndex = asm.poolMethod(TimestampLocale.class, "matchAMPM", "(Ljava/lang/CharSequence;II)J");
int matchEraIndex = asm.poolMethod(TimestampLocale.class, "matchEra", "(Ljava/lang/CharSequence;II)J");
int getWeekdayIndex = asm.poolMethod(TimestampLocale.class, "getWeekday", "(I)Ljava/lang/String;");
int getShortWeekdayIndex = asm.poolMethod(TimestampLocale.class, "getShortWeekday", "(I)Ljava/lang/String;");
int getMonthIndex = asm.poolMethod(TimestampLocale.class, "getMonth", "(I)Ljava/lang/String;");
int getShortMonthIndex = asm.poolMethod(TimestampLocale.class, "getShortMonth", "(I)Ljava/lang/String;");
int parseIntSafelyIndex = asm.poolMethod(Numbers.class, "parseIntSafely", "(Ljava/lang/CharSequence;II)J");
int decodeLenIndex = asm.poolMethod(Numbers.class, "decodeHighInt", "(J)I");
......@@ -1364,11 +1364,11 @@ public class DateFormatCompiler {
int assertNoTailIndex = asm.poolMethod(DateFormatUtils.class, "assertNoTail", "(II)V");
int assertStringIndex = asm.poolMethod(DateFormatUtils.class, "assertString", "(Ljava/lang/CharSequence;ILjava/lang/CharSequence;II)I");
int assertCharIndex = asm.poolMethod(DateFormatUtils.class, "assertChar", "(CLjava/lang/CharSequence;II)V");
int computeMillisIndex = asm.poolMethod(DateFormatUtils.class, "compute", "(Lio/questdb/std/microtime/DateLocale;IIIIIIIIIIJI)J");
int computeMillisIndex = asm.poolMethod(DateFormatUtils.class, "compute", "(Lio/questdb/std/microtime/TimestampLocale;IIIIIIIIIIJI)J");
int adjustYearIndex = asm.poolMethod(DateFormatUtils.class, "adjustYear", "(I)I");
int parseYearGreedyIndex = asm.poolMethod(DateFormatUtils.class, "parseYearGreedy", "(Ljava/lang/CharSequence;II)J");
int appendEraIndex = asm.poolMethod(DateFormatUtils.class, "appendEra", "(Lio/questdb/std/str/CharSink;ILio/questdb/std/microtime/DateLocale;)V");
int appendAmPmIndex = asm.poolMethod(DateFormatUtils.class, "appendAmPm", "(Lio/questdb/std/str/CharSink;ILio/questdb/std/microtime/DateLocale;)V");
int appendEraIndex = asm.poolMethod(DateFormatUtils.class, "appendEra", "(Lio/questdb/std/str/CharSink;ILio/questdb/std/microtime/TimestampLocale;)V");
int appendAmPmIndex = asm.poolMethod(DateFormatUtils.class, "appendAmPm", "(Lio/questdb/std/str/CharSink;ILio/questdb/std/microtime/TimestampLocale;)V");
int appendHour12Index = asm.poolMethod(DateFormatUtils.class, "appendHour12", "(Lio/questdb/std/str/CharSink;I)V");
int appendHour12PaddedIndex = asm.poolMethod(DateFormatUtils.class, "appendHour12Padded", "(Lio/questdb/std/str/CharSink;I)V");
int appendHour121Index = asm.poolMethod(DateFormatUtils.class, "appendHour121", "(Lio/questdb/std/str/CharSink;I)V");
......@@ -1377,17 +1377,17 @@ public class DateFormatCompiler {
int append00Index = asm.poolMethod(DateFormatUtils.class, "append00", "(Lio/questdb/std/str/CharSink;I)V");
int append0Index = asm.poolMethod(DateFormatUtils.class, "append0", "(Lio/questdb/std/str/CharSink;I)V");
int parseOffsetIndex = asm.poolMethod(Dates.class, "parseOffset", "(Ljava/lang/CharSequence;II)J");
int getYearIndex = asm.poolMethod(Dates.class, "getYear", "(J)I");
int isLeapYearIndex = asm.poolMethod(Dates.class, "isLeapYear", "(I)Z");
int getMonthOfYearIndex = asm.poolMethod(Dates.class, "getMonthOfYear", "(JIZ)I");
int getDayOfMonthIndex = asm.poolMethod(Dates.class, "getDayOfMonth", "(JIIZ)I");
int getHourOfDayIndex = asm.poolMethod(Dates.class, "getHourOfDay", "(J)I");
int getMinuteOfHourIndex = asm.poolMethod(Dates.class, "getMinuteOfHour", "(J)I");
int getSecondOfMinuteIndex = asm.poolMethod(Dates.class, "getSecondOfMinute", "(J)I");
int getMillisOfSecondIndex = asm.poolMethod(Dates.class, "getMillisOfSecond", "(J)I");
int getMicrosOfSecondIndex = asm.poolMethod(Dates.class, "getMicrosOfSecond", "(J)I");
int getDayOfWeekIndex = asm.poolMethod(Dates.class, "getDayOfWeekSundayFirst", "(J)I");
int parseOffsetIndex = asm.poolMethod(Timestamps.class, "parseOffset", "(Ljava/lang/CharSequence;II)J");
int getYearIndex = asm.poolMethod(Timestamps.class, "getYear", "(J)I");
int isLeapYearIndex = asm.poolMethod(Timestamps.class, "isLeapYear", "(I)Z");
int getMonthOfYearIndex = asm.poolMethod(Timestamps.class, "getMonthOfYear", "(JIZ)I");
int getDayOfMonthIndex = asm.poolMethod(Timestamps.class, "getDayOfMonth", "(JIIZ)I");
int getHourOfDayIndex = asm.poolMethod(Timestamps.class, "getHourOfDay", "(J)I");
int getMinuteOfHourIndex = asm.poolMethod(Timestamps.class, "getMinuteOfHour", "(J)I");
int getSecondOfMinuteIndex = asm.poolMethod(Timestamps.class, "getSecondOfMinute", "(J)I");
int getMillisOfSecondIndex = asm.poolMethod(Timestamps.class, "getMillisOfSecond", "(J)I");
int getMicrosOfSecondIndex = asm.poolMethod(Timestamps.class, "getMicrosOfSecond", "(J)I");
int getDayOfWeekIndex = asm.poolMethod(Timestamps.class, "getDayOfWeekSundayFirst", "(J)I");
int sinkPutIntIndex = asm.poolInterfaceMethod(CharSink.class, "put", "(I)Lio/questdb/std/str/CharSink;");
int sinkPutStrIndex = asm.poolInterfaceMethod(CharSink.class, "put", "(Ljava/lang/CharSequence;)Lio/questdb/std/str/CharSink;");
......@@ -1396,9 +1396,9 @@ public class DateFormatCompiler {
int charAtIndex = asm.poolInterfaceMethod(charSequenceClassIndex, "charAt", "(I)C");
int parseNameIndex = asm.poolUtf8("parse");
int parseSigIndex = asm.poolUtf8("(Ljava/lang/CharSequence;IILio/questdb/std/microtime/DateLocale;)J");
int parseSigIndex = asm.poolUtf8("(Ljava/lang/CharSequence;IILio/questdb/std/microtime/TimestampLocale;)J");
int formatNameIndex = asm.poolUtf8("format");
int formatSigIndex = asm.poolUtf8("(JLio/questdb/std/microtime/DateLocale;Ljava/lang/CharSequence;Lio/questdb/std/str/CharSink;)V");
int formatSigIndex = asm.poolUtf8("(JLio/questdb/std/microtime/TimestampLocale;Ljava/lang/CharSequence;Lio/questdb/std/str/CharSink;)V");
// pool only delimiters over 1 char in length
// when delimiter is 1 char we would use shorter code path
......
......@@ -33,12 +33,12 @@ public class DateFormatUtils {
public static final int HOUR_24 = 2;
public static final int HOUR_PM = 1;
public static final int HOUR_AM = 0;
public static final DateFormat UTC_FORMAT;
public static final DateFormat USEC_UTC_FORMAT;
public static final DateFormat PG_TIMESTAMP_FORMAT;
public static final TimestampFormat UTC_FORMAT;
public static final TimestampFormat USEC_UTC_FORMAT;
public static final TimestampFormat PG_TIMESTAMP_FORMAT;
public static final String UTC_PATTERN = "yyyy-MM-ddTHH:mm:ss.SSSz";
public static final DateLocale defaultLocale = DateLocaleFactory.INSTANCE.getDefaultDateLocale();
private static final DateFormat HTTP_FORMAT;
public static final TimestampLocale defaultLocale = TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale();
private static final TimestampFormat HTTP_FORMAT;
static long referenceYear;
static int thisCenturyLimit;
static int thisCenturyLow;
......@@ -101,12 +101,12 @@ public class DateFormatUtils {
// YYYY-MM-DD
public static void formatDashYYYYMMDD(CharSink sink, long millis) {
int y = Dates.getYear(millis);
boolean l = Dates.isLeapYear(y);
int m = Dates.getMonthOfYear(millis, y, l);
int y = Timestamps.getYear(millis);
boolean l = Timestamps.isLeapYear(y);
int m = Timestamps.getMonthOfYear(millis, y, l);
Numbers.append(sink, y);
append0(sink.put('-'), m);
append0(sink.put('-'), Dates.getDayOfMonth(millis, y, m, l));
append0(sink.put('-'), Timestamps.getDayOfMonth(millis, y, m, l));
}
public static void formatHTTP(CharSink sink, long millis) {
......@@ -115,20 +115,20 @@ public class DateFormatUtils {
// YYYY-MM
public static void formatYYYYMM(CharSink sink, long millis) {
int y = Dates.getYear(millis);
int m = Dates.getMonthOfYear(millis, y, Dates.isLeapYear(y));
int y = Timestamps.getYear(millis);
int m = Timestamps.getMonthOfYear(millis, y, Timestamps.isLeapYear(y));
Numbers.append(sink, y);
append0(sink.put('-'), m);
}
// YYYYMMDD
public static void formatYYYYMMDD(CharSink sink, long millis) {
int y = Dates.getYear(millis);
boolean l = Dates.isLeapYear(y);
int m = Dates.getMonthOfYear(millis, y, l);
int y = Timestamps.getYear(millis);
boolean l = Timestamps.isLeapYear(y);
int m = Timestamps.getMonthOfYear(millis, y, l);
Numbers.append(sink, y);
append0(sink, m);
append0(sink, Dates.getDayOfMonth(millis, y, m, l));
append0(sink, Timestamps.getDayOfMonth(millis, y, m, l));
}
public static long getReferenceYear() {
......@@ -165,7 +165,7 @@ public class DateFormatUtils {
public static void updateReferenceYear(long micros) {
referenceYear = micros;
int referenceYear = Dates.getYear(micros);
int referenceYear = Timestamps.getYear(micros);
int centuryOffset = referenceYear % 100;
thisCenturyLimit = centuryOffset + 20;
if (thisCenturyLimit > 100) {
......@@ -175,10 +175,10 @@ public class DateFormatUtils {
thisCenturyLow = referenceYear - centuryOffset;
}
prevCenturyLow = thisCenturyLow - 100;
newYear = Dates.endOfYear(referenceYear);
newYear = Timestamps.endOfYear(referenceYear);
}
static void appendAmPm(CharSink sink, int hour, DateLocale locale) {
static void appendAmPm(CharSink sink, int hour, TimestampLocale locale) {
if (hour < 12) {
sink.put(locale.getAMPM(0));
} else {
......@@ -223,7 +223,7 @@ public class DateFormatUtils {
}
static long compute(
DateLocale locale,
TimestampLocale locale,
int era,
int year,
int month,
......@@ -241,7 +241,7 @@ public class DateFormatUtils {
year = -(year - 1);
}
boolean leap = Dates.isLeapYear(year);
boolean leap = Timestamps.isLeapYear(year);
// wrong month
if (month < 1 || month > 12) {
......@@ -265,7 +265,7 @@ public class DateFormatUtils {
}
// wrong day of month
if (day < 1 || day > Dates.getDaysPerMonth(month, leap)) {
if (day < 1 || day > Timestamps.getDaysPerMonth(month, leap)) {
throw NumericException.INSTANCE;
}
......@@ -277,13 +277,13 @@ public class DateFormatUtils {
throw NumericException.INSTANCE;
}
long datetime = Dates.yearMicros(year, leap)
+ Dates.monthOfYearMicros(month, leap)
+ (day - 1) * Dates.DAY_MICROS
+ hour * Dates.HOUR_MICROS
+ minute * Dates.MINUTE_MICROS
+ second * Dates.SECOND_MICROS
+ millis * Dates.MILLI_MICROS
long datetime = Timestamps.yearMicros(year, leap)
+ Timestamps.monthOfYearMicros(month, leap)
+ (day - 1) * Timestamps.DAY_MICROS
+ hour * Timestamps.HOUR_MICROS
+ minute * Timestamps.MINUTE_MICROS
+ second * Timestamps.SECOND_MICROS
+ millis * Timestamps.MILLI_MICROS
+ micros;
if (timezone > -1) {
......@@ -344,7 +344,7 @@ public class DateFormatUtils {
}
}
static void appendEra(CharSink sink, int year, DateLocale locale) {
static void appendEra(CharSink sink, int year, TimestampLocale locale) {
if (year < 0) {
sink.put(locale.getEra(0));
} else {
......
......@@ -29,17 +29,17 @@ import io.questdb.std.NumericException;
import io.questdb.std.ObjList;
import io.questdb.std.str.CharSink;
public class GenericDateFormat extends AbstractDateFormat {
public class GenericTimestampFormat extends AbstractTimestampFormat {
private final IntList compiledOps;
private final ObjList<String> delimiters;
public GenericDateFormat(IntList compiledOps, ObjList<String> delimiters) {
public GenericTimestampFormat(IntList compiledOps, ObjList<String> delimiters) {
this.compiledOps = compiledOps;
this.delimiters = delimiters;
}
@Override
public void format(long micros, DateLocale locale, CharSequence timeZoneName, CharSink sink) {
public void format(long micros, TimestampLocale locale, CharSequence timeZoneName, CharSink sink) {
int day = -1;
int month = -1;
int year = Integer.MIN_VALUE;
......@@ -58,7 +58,7 @@ public class GenericDateFormat extends AbstractDateFormat {
// AM/PM
case DateFormatCompiler.OP_AM_PM:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.appendAmPm(sink, hour, locale);
break;
......@@ -67,14 +67,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_MICROS_ONE_DIGIT:
case DateFormatCompiler.OP_MICROS_GREEDY:
if (micros0 == -1) {
micros0 = Dates.getMicrosOfSecond(micros);
micros0 = Timestamps.getMicrosOfSecond(micros);
}
sink.put(micros0);
break;
case DateFormatCompiler.OP_MICROS_THREE_DIGITS:
if (micros0 == -1) {
micros0 = Dates.getMicrosOfSecond(micros);
micros0 = Timestamps.getMicrosOfSecond(micros);
}
DateFormatUtils.append00(sink, micros0);
break;
......@@ -83,14 +83,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_MILLIS_ONE_DIGIT:
case DateFormatCompiler.OP_MILLIS_GREEDY:
if (millis == -1) {
millis = Dates.getMillisOfSecond(micros);
millis = Timestamps.getMillisOfSecond(micros);
}
sink.put(millis);
break;
case DateFormatCompiler.OP_MILLIS_THREE_DIGITS:
if (millis == -1) {
millis = Dates.getMillisOfSecond(micros);
millis = Timestamps.getMillisOfSecond(micros);
}
DateFormatUtils.append00(sink, millis);
break;
......@@ -99,14 +99,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_SECOND_ONE_DIGIT:
case DateFormatCompiler.OP_SECOND_GREEDY:
if (second == -1) {
second = Dates.getSecondOfMinute(micros);
second = Timestamps.getSecondOfMinute(micros);
}
sink.put(second);
break;
case DateFormatCompiler.OP_SECOND_TWO_DIGITS:
if (second == -1) {
second = Dates.getSecondOfMinute(micros);
second = Timestamps.getSecondOfMinute(micros);
}
DateFormatUtils.append0(sink, second);
break;
......@@ -116,14 +116,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_MINUTE_ONE_DIGIT:
case DateFormatCompiler.OP_MINUTE_GREEDY:
if (minute == -1) {
minute = Dates.getMinuteOfHour(micros);
minute = Timestamps.getMinuteOfHour(micros);
}
sink.put(minute);
break;
case DateFormatCompiler.OP_MINUTE_TWO_DIGITS:
if (minute == -1) {
minute = Dates.getMinuteOfHour(micros);
minute = Timestamps.getMinuteOfHour(micros);
}
DateFormatUtils.append0(sink, minute);
break;
......@@ -133,14 +133,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_HOUR_12_ONE_DIGIT:
case DateFormatCompiler.OP_HOUR_12_GREEDY:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.appendHour12(sink, hour);
break;
case DateFormatCompiler.OP_HOUR_12_TWO_DIGITS:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.appendHour12Padded(sink, hour);
break;
......@@ -149,14 +149,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_HOUR_12_ONE_DIGIT_ONE_BASED:
case DateFormatCompiler.OP_HOUR_12_GREEDY_ONE_BASED:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.appendHour121(sink, hour);
break;
case DateFormatCompiler.OP_HOUR_12_TWO_DIGITS_ONE_BASED:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.appendHour121Padded(sink, hour);
break;
......@@ -165,14 +165,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_HOUR_24_ONE_DIGIT:
case DateFormatCompiler.OP_HOUR_24_GREEDY:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
sink.put(hour);
break;
case DateFormatCompiler.OP_HOUR_24_TWO_DIGITS:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.append0(sink, hour);
break;
......@@ -181,14 +181,14 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_HOUR_24_ONE_DIGIT_ONE_BASED:
case DateFormatCompiler.OP_HOUR_24_GREEDY_ONE_BASED:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
sink.put(hour + 1);
break;
case DateFormatCompiler.OP_HOUR_24_TWO_DIGITS_ONE_BASED:
if (hour == -1) {
hour = Dates.getHourOfDay(micros);
hour = Timestamps.getHourOfDay(micros);
}
DateFormatUtils.append0(sink, hour + 1);
break;
......@@ -198,51 +198,51 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_DAY_GREEDY:
if (day == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
if (month == -1) {
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
day = Dates.getDayOfMonth(micros, year, month, leap);
day = Timestamps.getDayOfMonth(micros, year, month, leap);
}
sink.put(day);
break;
case DateFormatCompiler.OP_DAY_TWO_DIGITS:
if (day == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
if (month == -1) {
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
day = Dates.getDayOfMonth(micros, year, month, leap);
day = Timestamps.getDayOfMonth(micros, year, month, leap);
}
DateFormatUtils.append0(sink, day);
break;
case DateFormatCompiler.OP_DAY_NAME_LONG:
if (dayOfWeek == -1) {
dayOfWeek = Dates.getDayOfWeekSundayFirst(micros);
dayOfWeek = Timestamps.getDayOfWeekSundayFirst(micros);
}
sink.put(locale.getWeekday(dayOfWeek));
break;
case DateFormatCompiler.OP_DAY_NAME_SHORT:
if (dayOfWeek == -1) {
dayOfWeek = Dates.getDayOfWeekSundayFirst(micros);
dayOfWeek = Timestamps.getDayOfWeekSundayFirst(micros);
}
sink.put(locale.getShortWeekday(dayOfWeek));
break;
case DateFormatCompiler.OP_DAY_OF_WEEK:
if (dayOfWeek == -1) {
dayOfWeek = Dates.getDayOfWeekSundayFirst(micros);
dayOfWeek = Timestamps.getDayOfWeekSundayFirst(micros);
}
sink.put(dayOfWeek);
break;
......@@ -253,22 +253,22 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_MONTH_GREEDY:
if (month == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
sink.put(month);
break;
case DateFormatCompiler.OP_MONTH_TWO_DIGITS:
if (month == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
DateFormatUtils.append0(sink, month);
break;
......@@ -276,22 +276,22 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_MONTH_SHORT_NAME:
if (month == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
sink.put(locale.getShortMonth(month - 1));
break;
case DateFormatCompiler.OP_MONTH_LONG_NAME:
if (month == -1) {
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
month = Dates.getMonthOfYear(micros, year, leap);
month = Timestamps.getMonthOfYear(micros, year, leap);
}
sink.put(locale.getMonth(month - 1));
break;
......@@ -301,22 +301,22 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_YEAR_ONE_DIGIT:
case DateFormatCompiler.OP_YEAR_GREEDY:
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
sink.put(year);
break;
case DateFormatCompiler.OP_YEAR_TWO_DIGITS:
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
DateFormatUtils.append0(sink, year % 100);
break;
case DateFormatCompiler.OP_YEAR_FOUR_DIGITS:
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
DateFormatUtils.append000(sink, year);
break;
......@@ -324,8 +324,8 @@ public class GenericDateFormat extends AbstractDateFormat {
// ERA
case DateFormatCompiler.OP_ERA:
if (year == Integer.MIN_VALUE) {
year = Dates.getYear(micros);
leap = Dates.isLeapYear(year);
year = Timestamps.getYear(micros);
leap = Timestamps.isLeapYear(year);
}
DateFormatUtils.appendEra(sink, year, locale);
break;
......@@ -350,7 +350,7 @@ public class GenericDateFormat extends AbstractDateFormat {
}
@Override
public long parse(CharSequence in, int lo, int hi, DateLocale locale) throws NumericException {
public long parse(CharSequence in, int lo, int hi, TimestampLocale locale) throws NumericException {
int day = 1;
int month = 1;
int year = 1970;
......@@ -624,12 +624,12 @@ public class GenericDateFormat extends AbstractDateFormat {
case DateFormatCompiler.OP_TIME_ZONE_LONG:
case DateFormatCompiler.OP_TIME_ZONE_RFC_822:
l = Dates.parseOffset(in, pos, hi);
l = Timestamps.parseOffset(in, pos, hi);
if (l == Long.MIN_VALUE) {
l = locale.matchZone(in, pos, hi);
timezone = Numbers.decodeLowInt(l);
} else {
offset = Numbers.decodeLowInt(l) * Dates.MINUTE_MICROS;
offset = Numbers.decodeLowInt(l) * Timestamps.MINUTE_MICROS;
}
pos += Numbers.decodeHighInt(l);
break;
......
......@@ -55,9 +55,9 @@ public class TimeZoneRuleFactory {
i = ruleMap.get(alias);
if (i == -1) {
// this could be fixed offset, try parsing value as one
long offset = Dates.parseOffset(alias, 0, alias.length());
long offset = Timestamps.parseOffset(alias, 0, alias.length());
if (offset != Long.MIN_VALUE) {
ruleList.add(new FixedTimeZoneRule(alias, Numbers.decodeLowInt(offset) * Dates.MILLI_MICROS));
ruleList.add(new FixedTimeZoneRule(alias, Numbers.decodeLowInt(offset) * Timestamps.MILLI_MICROS));
ruleMap.put(key, index++);
}
} else {
......
......@@ -55,7 +55,7 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
if (savingsInstantTransition.length == 0) {
ZoneOffset[] standardOffsets = (ZoneOffset[]) Unsafe.getUnsafe().getObject(rules, STANDARD_OFFSETS);
standardOffset = standardOffsets[0].getTotalSeconds() * Dates.SECOND_MICROS;
standardOffset = standardOffsets[0].getTotalSeconds() * Timestamps.SECOND_MICROS;
} else {
standardOffset = Long.MIN_VALUE;
}
......@@ -64,8 +64,8 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
for (int i = 0, n = savingsLocalTransitions.length; i < n; i++) {
LocalDateTime dt = savingsLocalTransitions[i];
historicTransitions.add(Dates.toMicros(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute()) +
dt.getSecond() * Dates.SECOND_MICROS + dt.getNano() / 1000);
historicTransitions.add(Timestamps.toMicros(dt.getYear(), dt.getMonthValue(), dt.getDayOfMonth(), dt.getHour(), dt.getMinute()) +
dt.getSecond() * Timestamps.SECOND_MICROS + dt.getNano() / 1000);
}
cutoffTransition = historicTransitions.getLast();
historyOverlapCheckCutoff = historicTransitions.size() - 1;
......@@ -107,8 +107,8 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
for (int i = 0, n = wallOffsets.length; i < n; i++) {
this.wallOffsets[i] = wallOffsets[i].getTotalSeconds();
}
this.firstWall = this.wallOffsets[0] * Dates.SECOND_MICROS;
this.lastWall = this.wallOffsets[wallOffsets.length - 1] * Dates.SECOND_MICROS;
this.firstWall = this.wallOffsets[0] * Timestamps.SECOND_MICROS;
this.lastWall = this.wallOffsets[wallOffsets.length - 1] * Timestamps.SECOND_MICROS;
}
@Override
......@@ -135,8 +135,8 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
@Override
public long getOffset(long micros) {
int y = Dates.getYear(micros);
return getOffset(micros, y, Dates.isLeapYear(y));
int y = Timestamps.getYear(micros);
return getOffset(micros, y, Timestamps.isLeapYear(y));
}
private long fromHistory(long micros) {
......@@ -158,12 +158,12 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
int delta = offsetAfter - offsetBefore;
if (delta > 0) {
// engage 0 transition logic
return (delta + offsetAfter) * Dates.SECOND_MICROS;
return (delta + offsetAfter) * Timestamps.SECOND_MICROS;
} else {
return offsetBefore * Dates.SECOND_MICROS;
return offsetBefore * Timestamps.SECOND_MICROS;
}
} else {
return Unsafe.arrayGet(wallOffsets, index / 2 + 1) * Dates.SECOND_MICROS;
return Unsafe.arrayGet(wallOffsets, index / 2 + 1) * Timestamps.SECOND_MICROS;
}
}
......@@ -182,27 +182,27 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
int dow = zr.dow;
long date;
if (dom < 0) {
date = Dates.toMicros(year, leap, month, Dates.getDaysPerMonth(month, leap) + 1 + dom, zr.hour, zr.minute) + zr.second * Dates.SECOND_MICROS;
date = Timestamps.toMicros(year, leap, month, Timestamps.getDaysPerMonth(month, leap) + 1 + dom, zr.hour, zr.minute) + zr.second * Timestamps.SECOND_MICROS;
if (dow > -1) {
date = Dates.previousOrSameDayOfWeek(date, dow);
date = Timestamps.previousOrSameDayOfWeek(date, dow);
}
} else {
date = Dates.toMicros(year, leap, month, dom, zr.hour, zr.minute) + zr.second * Dates.SECOND_MICROS;
date = Timestamps.toMicros(year, leap, month, dom, zr.hour, zr.minute) + zr.second * Timestamps.SECOND_MICROS;
if (dow > -1) {
date = Dates.nextOrSameDayOfWeek(date, dow);
date = Timestamps.nextOrSameDayOfWeek(date, dow);
}
}
if (zr.midnightEOD) {
date = Dates.addDays(date, 1);
date = Timestamps.addDays(date, 1);
}
switch (zr.timeDef) {
case TransitionRule.UTC:
date += (offset - ZoneOffset.UTC.getTotalSeconds()) * Dates.SECOND_MICROS;
date += (offset - ZoneOffset.UTC.getTotalSeconds()) * Timestamps.SECOND_MICROS;
break;
case TransitionRule.STANDARD:
date += (offset - zr.standardOffset) * Dates.SECOND_MICROS;
date += (offset - zr.standardOffset) * Timestamps.SECOND_MICROS;
break;
default: // WALL
break;
......@@ -212,24 +212,24 @@ public class TimeZoneRulesImpl implements TimeZoneRules {
if (delta > 0) {
if (micros < date) {
return offset * Dates.SECOND_MICROS;
return offset * Timestamps.SECOND_MICROS;
}
if (micros < date + delta) {
return (offsetAfter + delta) * Dates.SECOND_MICROS;
return (offsetAfter + delta) * Timestamps.SECOND_MICROS;
} else {
offset = offsetAfter;
}
} else {
if (micros < date) {
return offset * Dates.SECOND_MICROS;
return offset * Timestamps.SECOND_MICROS;
} else {
offset = offsetAfter;
}
}
}
return offset * Dates.SECOND_MICROS;
return offset * Timestamps.SECOND_MICROS;
}
private static class TransitionRule {
......
......@@ -26,11 +26,11 @@ package io.questdb.std.microtime;
import io.questdb.std.NumericException;
import io.questdb.std.str.CharSink;
public interface DateFormat {
public interface TimestampFormat {
void format(long micros, DateLocale locale, CharSequence timeZoneName, CharSink sink);
void format(long micros, TimestampLocale locale, CharSequence timeZoneName, CharSink sink);
long parse(CharSequence in, DateLocale locale) throws NumericException;
long parse(CharSequence in, TimestampLocale locale) throws NumericException;
long parse(CharSequence in, int lo, int hi, DateLocale locale) throws NumericException;
long parse(CharSequence in, int lo, int hi, TimestampLocale locale) throws NumericException;
}
......@@ -26,9 +26,9 @@ package io.questdb.std.microtime;
import io.questdb.std.ConcurrentHashMap;
public class DateFormatFactory {
public class TimestampFormatFactory {
private final static ThreadLocal<DateFormatCompiler> tlCompiler = ThreadLocal.withInitial(DateFormatCompiler::new);
private final ConcurrentHashMap<DateFormat> cache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<TimestampFormat> cache = new ConcurrentHashMap<>();
/**
* Retrieves cached data format, if already exists of creates and caches new one. Concurrent behaviour is
......@@ -40,7 +40,7 @@ public class DateFormatFactory {
* @param pattern can be mutable and is not stored if same pattern already in cache.
* @return compiled implementation of DateFormat
*/
public DateFormat get(CharSequence pattern) {
public TimestampFormat get(CharSequence pattern) {
return cache.computeIfAbsent(pattern, p -> tlCompiler.get().compile(p));
}
}
......@@ -27,7 +27,7 @@ import io.questdb.std.*;
import java.text.DateFormatSymbols;
public class DateLocale {
public class TimestampLocale {
private final IntObjHashMap<ObjList<CharSequence>> months = new IntObjHashMap<>();
private final IntObjHashMap<ObjList<CharSequence>> weekdays = new IntObjHashMap<>();
private final IntObjHashMap<ObjList<CharSequence>> amspms = new IntObjHashMap<>();
......@@ -42,7 +42,7 @@ public class DateLocale {
private final TimeZoneRuleFactory factory;
private final String id;
DateLocale(String id, DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
TimestampLocale(String id, DateFormatSymbols symbols, TimeZoneRuleFactory timeZoneRuleFactory, @Transient CharSequenceHashSet cache) {
this.id = id;
this.factory = timeZoneRuleFactory;
index(monthArray = symbols.getMonths(), months);
......
......@@ -29,34 +29,34 @@ import io.questdb.std.CharSequenceObjHashMap;
import java.text.DateFormatSymbols;
import java.util.Locale;
public class DateLocaleFactory {
public static final DateLocaleFactory INSTANCE = new DateLocaleFactory(TimeZoneRuleFactory.INSTANCE);
public class TimestampLocaleFactory {
public static final TimestampLocaleFactory INSTANCE = new TimestampLocaleFactory(TimeZoneRuleFactory.INSTANCE);
private final CharSequenceObjHashMap<DateLocale> dateLocales = new CharSequenceObjHashMap<>();
private final DateLocale defaultDateLocale;
private final CharSequenceObjHashMap<TimestampLocale> dateLocales = new CharSequenceObjHashMap<>();
private final TimestampLocale defaultTimestampLocale;
public DateLocaleFactory(TimeZoneRuleFactory timeZoneRuleFactory) {
public TimestampLocaleFactory(TimeZoneRuleFactory timeZoneRuleFactory) {
CharSequenceHashSet cache = new CharSequenceHashSet();
for (Locale l : Locale.getAvailableLocales()) {
String tag = l.toLanguageTag();
if ("und".equals(tag)) {
tag = "";
}
dateLocales.put(tag, new DateLocale(tag, new DateFormatSymbols(l), timeZoneRuleFactory, cache));
dateLocales.put(tag, new TimestampLocale(tag, new DateFormatSymbols(l), timeZoneRuleFactory, cache));
cache.clear();
}
defaultDateLocale = dateLocales.get(Locale.getDefault().toLanguageTag());
defaultTimestampLocale = dateLocales.get(Locale.getDefault().toLanguageTag());
}
public CharSequenceObjHashMap<DateLocale> getAll() {
public CharSequenceObjHashMap<TimestampLocale> getAll() {
return dateLocales;
}
public DateLocale getDateLocale(CharSequence id) {
public TimestampLocale getDateLocale(CharSequence id) {
return dateLocales.get(id);
}
public DateLocale getDefaultDateLocale() {
return defaultDateLocale;
public TimestampLocale getDefaultTimestampLocale() {
return defaultTimestampLocale;
}
}
......@@ -28,7 +28,7 @@ import io.questdb.std.Numbers;
import io.questdb.std.NumericException;
import io.questdb.std.str.StringSink;
final public class Dates {
final public class Timestamps {
public static final long DAY_MICROS = 86400000000L;
public static final long HOUR_MICROS = 3600000000L;
......@@ -73,7 +73,7 @@ final public class Dates {
}
}
private Dates() {
private Timestamps() {
}
public static long addDays(long micros, int days) {
......@@ -88,8 +88,8 @@ final public class Dates {
if (months == 0) {
return micros;
}
int y = Dates.getYear(micros);
boolean l = Dates.isLeapYear(y);
int y = Timestamps.getYear(micros);
boolean l = Timestamps.isLeapYear(y);
int m = getMonthOfYear(micros, y, l);
int _y;
int _m = m - 1 + months;
......@@ -118,17 +118,17 @@ final public class Dates {
public static long addPeriod(long lo, char type, int period) throws NumericException {
switch (type) {
case 's':
return lo + period * Dates.SECOND_MICROS;
return lo + period * Timestamps.SECOND_MICROS;
case 'm':
return lo + period * Dates.MINUTE_MICROS;
return lo + period * Timestamps.MINUTE_MICROS;
case 'h':
return Dates.addHours(lo, period);
return Timestamps.addHours(lo, period);
case 'd':
return Dates.addDays(lo, period);
return Timestamps.addDays(lo, period);
case 'M':
return Dates.addMonths(lo, period);
return Timestamps.addMonths(lo, period);
case 'y':
return Dates.addYear(lo, period);
return Timestamps.addYear(lo, period);
default:
throw NumericException.INSTANCE;
}
......
......@@ -31,7 +31,7 @@ import io.questdb.cairo.sql.SymbolTable;
import io.questdb.std.LongList;
import io.questdb.std.Rnd;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
import io.questdb.test.tools.TestUtils;
import org.junit.Assert;
import org.junit.Test;
......@@ -418,7 +418,7 @@ public class IntervalBwdDataFrameCursorTest extends AbstractCairoTest {
Assert.assertTrue(cursor.reload());
assertEquals(expected1, record, cursor);
timestamp = Dates.addYear(timestamp, 3);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
......@@ -585,7 +585,7 @@ public class IntervalBwdDataFrameCursorTest extends AbstractCairoTest {
}
writer.commit();
timestamp = Dates.addYear(timestamp, 3);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
......
......@@ -31,7 +31,7 @@ import io.questdb.cairo.sql.SymbolTable;
import io.questdb.std.LongList;
import io.questdb.std.Rnd;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
import io.questdb.test.tools.TestUtils;
import org.junit.Assert;
import org.junit.Test;
......@@ -419,7 +419,7 @@ public class IntervalFwdDataFrameCursorTest extends AbstractCairoTest {
Assert.assertTrue(cursor.reload());
assertEquals(expected1, record, cursor);
timestamp = Dates.addYear(timestamp, 3);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
......@@ -586,7 +586,7 @@ public class IntervalFwdDataFrameCursorTest extends AbstractCairoTest {
}
writer.commit();
timestamp = Dates.addYear(timestamp, 3);
timestamp = Timestamps.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
......
......@@ -26,10 +26,10 @@ package io.questdb.cairo;
import io.questdb.cairo.sql.Record;
import io.questdb.cairo.sql.RecordCursor;
import io.questdb.std.*;
import io.questdb.std.microtime.DateFormat;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.DateLocaleFactory;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.TimestampFormat;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.LPSZ;
import io.questdb.std.str.Path;
import io.questdb.std.str.StringSink;
......@@ -2155,17 +2155,17 @@ public class TableReaderTest extends AbstractCairoTest {
@Test
public void testRemoveActivePartitionByDay() throws Exception {
testRemoveActivePartition(PartitionBy.DAY, current -> Dates.addDays(Dates.floorDD(current), 1), "2017-12-15");
testRemoveActivePartition(PartitionBy.DAY, current -> Timestamps.addDays(Timestamps.floorDD(current), 1), "2017-12-15");
}
@Test
public void testRemoveActivePartitionByMonth() throws Exception {
testRemoveActivePartition(PartitionBy.MONTH, current -> Dates.addMonths(Dates.floorMM(current), 1), "2018-04");
testRemoveActivePartition(PartitionBy.MONTH, current -> Timestamps.addMonths(Timestamps.floorMM(current), 1), "2018-04");
}
@Test
public void testRemoveActivePartitionByYear() throws Exception {
testRemoveActivePartition(PartitionBy.YEAR, current -> Dates.addYear(Dates.floorYYYY(current), 1), "2021");
testRemoveActivePartition(PartitionBy.YEAR, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 1), "2021");
}
@Test
......@@ -2194,7 +2194,7 @@ public class TableReaderTest extends AbstractCairoTest {
writer.commit();
timestampUs += stride;
}
timestampUs = Dates.addDays(Dates.floorDD(timestampUs), 1);
timestampUs = Timestamps.addDays(Timestamps.floorDD(timestampUs), 1);
}
Assert.assertEquals(N * N_PARTITIONS, writer.size());
......@@ -2223,22 +2223,22 @@ public class TableReaderTest extends AbstractCairoTest {
@Test
public void testRemoveFirstPartitionByDay() throws Exception {
testRemovePartition(PartitionBy.DAY, "2017-12-11", 0, current -> Dates.addDays(Dates.floorDD(current), 1));
testRemovePartition(PartitionBy.DAY, "2017-12-11", 0, current -> Timestamps.addDays(Timestamps.floorDD(current), 1));
}
@Test
public void testRemoveFirstPartitionByDayReload() throws Exception {
testRemovePartitionReload(PartitionBy.DAY, "2017-12-11", 0, current -> Dates.addDays(Dates.floorDD(current), 1));
testRemovePartitionReload(PartitionBy.DAY, "2017-12-11", 0, current -> Timestamps.addDays(Timestamps.floorDD(current), 1));
}
@Test
public void testRemoveFirstPartitionByDayReloadTwo() throws Exception {
testRemovePartitionReload(PartitionBy.DAY, "2017-12-11", 0, current -> Dates.addDays(Dates.floorDD(current), 2));
testRemovePartitionReload(PartitionBy.DAY, "2017-12-11", 0, current -> Timestamps.addDays(Timestamps.floorDD(current), 2));
}
@Test
public void testRemoveFirstPartitionByDayTwo() throws Exception {
testRemovePartition(PartitionBy.DAY, "2017-12-11", 0, current -> Dates.addDays(Dates.floorDD(current), 2));
testRemovePartition(PartitionBy.DAY, "2017-12-11", 0, current -> Timestamps.addDays(Timestamps.floorDD(current), 2));
}
@Test
......@@ -2379,47 +2379,47 @@ public class TableReaderTest extends AbstractCairoTest {
@Test
public void testRemoveFirstPartitionByMonth() throws Exception {
testRemovePartition(PartitionBy.MONTH, "2017-12", 0, current -> Dates.addMonths(Dates.floorMM(current), 1));
testRemovePartition(PartitionBy.MONTH, "2017-12", 0, current -> Timestamps.addMonths(Timestamps.floorMM(current), 1));
}
@Test
public void testRemoveFirstPartitionByMonthReload() throws Exception {
testRemovePartitionReload(PartitionBy.MONTH, "2017-12", 0, current -> Dates.addMonths(Dates.floorMM(current), 1));
testRemovePartitionReload(PartitionBy.MONTH, "2017-12", 0, current -> Timestamps.addMonths(Timestamps.floorMM(current), 1));
}
@Test
public void testRemoveFirstPartitionByMonthReloadTwo() throws Exception {
testRemovePartitionReload(PartitionBy.MONTH, "2017-12", 0, current -> Dates.addMonths(Dates.floorMM(current), 2));
testRemovePartitionReload(PartitionBy.MONTH, "2017-12", 0, current -> Timestamps.addMonths(Timestamps.floorMM(current), 2));
}
@Test
public void testRemoveFirstPartitionByMonthTwo() throws Exception {
testRemovePartition(PartitionBy.MONTH, "2017-12", 0, current -> Dates.addMonths(Dates.floorMM(current), 2));
testRemovePartition(PartitionBy.MONTH, "2017-12", 0, current -> Timestamps.addMonths(Timestamps.floorMM(current), 2));
}
@Test
public void testRemoveFirstPartitionByYear() throws Exception {
testRemovePartition(PartitionBy.YEAR, "2017", 0, current -> Dates.addYear(Dates.floorYYYY(current), 1));
testRemovePartition(PartitionBy.YEAR, "2017", 0, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 1));
}
@Test
public void testRemoveFirstPartitionByYearReload() throws Exception {
testRemovePartitionReload(PartitionBy.YEAR, "2017", 0, current -> Dates.addYear(Dates.floorYYYY(current), 1));
testRemovePartitionReload(PartitionBy.YEAR, "2017", 0, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 1));
}
@Test
public void testRemoveFirstPartitionByYearReloadTwo() throws Exception {
testRemovePartitionReload(PartitionBy.YEAR, "2017", 0, current -> Dates.addYear(Dates.floorYYYY(current), 2));
testRemovePartitionReload(PartitionBy.YEAR, "2017", 0, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 2));
}
@Test
public void testRemoveFirstPartitionByYearTwo() throws Exception {
testRemovePartition(PartitionBy.YEAR, "2017", 0, current -> Dates.addYear(Dates.floorYYYY(current), 2));
testRemovePartition(PartitionBy.YEAR, "2017", 0, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 2));
}
@Test
public void testRemovePartitionByDay() throws Exception {
testRemovePartition(PartitionBy.DAY, "2017-12-14", 3000, current -> Dates.addDays(Dates.floorDD(current), 1));
testRemovePartition(PartitionBy.DAY, "2017-12-14", 3000, current -> Timestamps.addDays(Timestamps.floorDD(current), 1));
}
@Test
......@@ -2465,14 +2465,14 @@ public class TableReaderTest extends AbstractCairoTest {
writer.commit();
timestampUs += stride;
}
timestampUs = Dates.addDays(Dates.floorDD(timestampUs), 1);
timestampUs = Timestamps.addDays(Timestamps.floorDD(timestampUs), 1);
}
Assert.assertEquals(N * N_PARTITIONS, writer.size());
DateFormat fmt = TableWriter.selectPartitionDirFmt(PartitionBy.DAY);
TimestampFormat fmt = TableWriter.selectPartitionDirFmt(PartitionBy.DAY);
assert fmt != null;
final long timestamp = fmt.parse("2017-12-14", DateLocaleFactory.INSTANCE.getDefaultDateLocale());
final long timestamp = fmt.parse("2017-12-14", TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale());
Assert.assertTrue(writer.removePartition(timestamp));
Assert.assertFalse(writer.removePartition(timestamp));
......@@ -2513,27 +2513,27 @@ public class TableReaderTest extends AbstractCairoTest {
@Test
public void testRemovePartitionByDayReload() throws Exception {
testRemovePartitionReload(PartitionBy.DAY, "2017-12-14", 3000, current -> Dates.addDays(Dates.floorDD(current), 1));
testRemovePartitionReload(PartitionBy.DAY, "2017-12-14", 3000, current -> Timestamps.addDays(Timestamps.floorDD(current), 1));
}
@Test
public void testRemovePartitionByMonth() throws Exception {
testRemovePartition(PartitionBy.MONTH, "2018-01", 1000, current -> Dates.addMonths(Dates.floorMM(current), 1));
testRemovePartition(PartitionBy.MONTH, "2018-01", 1000, current -> Timestamps.addMonths(Timestamps.floorMM(current), 1));
}
@Test
public void testRemovePartitionByMonthReload() throws Exception {
testRemovePartitionReload(PartitionBy.MONTH, "2018-01", 1000, current -> Dates.addMonths(Dates.floorMM(current), 1));
testRemovePartitionReload(PartitionBy.MONTH, "2018-01", 1000, current -> Timestamps.addMonths(Timestamps.floorMM(current), 1));
}
@Test
public void testRemovePartitionByYear() throws Exception {
testRemovePartition(PartitionBy.YEAR, "2020", 3000, current -> Dates.addYear(Dates.floorYYYY(current), 1));
testRemovePartition(PartitionBy.YEAR, "2020", 3000, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 1));
}
@Test
public void testRemovePartitionByYearReload() throws Exception {
testRemovePartitionReload(PartitionBy.YEAR, "2020", 3000, current -> Dates.addYear(Dates.floorYYYY(current), 1));
testRemovePartitionReload(PartitionBy.YEAR, "2020", 3000, current -> Timestamps.addYear(Timestamps.floorYYYY(current), 1));
}
@Test
......@@ -3759,10 +3759,10 @@ public class TableReaderTest extends AbstractCairoTest {
Assert.assertEquals(500, totalCount);
DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
TimestampFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
assert fmt != null;
Assert.assertFalse(
writer.removePartition(fmt.parse(partitionNameToDelete, DateLocaleFactory.INSTANCE.getDefaultDateLocale()))
writer.removePartition(fmt.parse(partitionNameToDelete, TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale()))
);
Assert.assertEquals(500, writer.size());
......@@ -3816,9 +3816,9 @@ public class TableReaderTest extends AbstractCairoTest {
Assert.assertEquals(N * N_PARTITIONS, writer.size());
DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
TimestampFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
assert fmt != null;
final long timestamp = fmt.parse(partitionNameToDelete, DateLocaleFactory.INSTANCE.getDefaultDateLocale());
final long timestamp = fmt.parse(partitionNameToDelete, TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale());
Assert.assertTrue(writer.removePartition(timestamp));
Assert.assertFalse(writer.removePartition(timestamp));
......@@ -3900,10 +3900,10 @@ public class TableReaderTest extends AbstractCairoTest {
Assert.assertEquals(N * N_PARTITIONS, totalCount);
DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
TimestampFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
assert fmt != null;
Assert.assertTrue(
writer.removePartition(fmt.parse(partitionNameToDelete, DateLocaleFactory.INSTANCE.getDefaultDateLocale()))
writer.removePartition(fmt.parse(partitionNameToDelete, TimestampLocaleFactory.INSTANCE.getDefaultTimestampLocale()))
);
Assert.assertEquals(N * (N_PARTITIONS - 1), writer.size());
......
......@@ -3204,8 +3204,8 @@ public class TableWriterTest extends AbstractCairoTest {
void verifyTimestampPartitions(VirtualMemory vmem) {
int i;
DateFormatCompiler compiler = new DateFormatCompiler();
DateFormat fmt = compiler.compile("yyyy-MM-dd");
DateLocale enGb = DateLocaleFactory.INSTANCE.getDateLocale("en-gb");
TimestampFormat fmt = compiler.compile("yyyy-MM-dd");
TimestampLocale enGb = TimestampLocaleFactory.INSTANCE.getDateLocale("en-gb");
try (Path vp = new Path()) {
for (i = 0; i < 10000; i++) {
......
......@@ -39,6 +39,8 @@ import io.questdb.log.LogFactory;
import io.questdb.mp.*;
import io.questdb.network.*;
import io.questdb.std.*;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.Path;
import io.questdb.std.str.StringSink;
import io.questdb.std.time.DateFormatFactory;
......@@ -59,8 +61,8 @@ public class IODispatcherTest {
private static final InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
new DateFormatFactory(),
DateLocaleFactory.INSTANCE,
new io.questdb.std.microtime.DateFormatFactory(),
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
new TimestampFormatFactory(),
TimestampLocaleFactory.INSTANCE
);
@Rule
public TemporaryFolder temp = new TemporaryFolder();
......
......@@ -35,6 +35,8 @@ import io.questdb.griffin.AbstractGriffinTest;
import io.questdb.griffin.SqlException;
import io.questdb.std.Files;
import io.questdb.std.Unsafe;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.Path;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocale;
......@@ -54,8 +56,8 @@ public class TextLoaderTest extends AbstractGriffinTest {
private static final InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
new DateFormatFactory(),
DateLocaleFactory.INSTANCE,
new io.questdb.std.microtime.DateFormatFactory(),
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
new TimestampFormatFactory(),
TimestampLocaleFactory.INSTANCE
);
private static final JsonLexer jsonLexer = new JsonLexer(1024, 1024);
......
......@@ -28,6 +28,8 @@ import io.questdb.cutlass.json.JsonLexer;
import io.questdb.cutlass.text.types.InputFormatConfiguration;
import io.questdb.cutlass.text.types.TypeManager;
import io.questdb.std.Unsafe;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.DirectCharSink;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocaleFactory;
......@@ -46,8 +48,8 @@ public class TextMetadataParserTest {
InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
new DateFormatFactory(),
DateLocaleFactory.INSTANCE,
new io.questdb.std.microtime.DateFormatFactory(),
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
new TimestampFormatFactory(),
TimestampLocaleFactory.INSTANCE
);
try (JsonLexer jsonLexer = new JsonLexer(1024, 1024)) {
inputFormatConfiguration.parseConfiguration(jsonLexer, new DefaultTextConfiguration().getAdapterSetConfigurationFileName());
......
......@@ -30,6 +30,8 @@ import io.questdb.cutlass.json.JsonLexer;
import io.questdb.cutlass.text.DefaultTextConfiguration;
import io.questdb.cutlass.text.TextConfiguration;
import io.questdb.std.Misc;
import io.questdb.std.microtime.TimestampFormatFactory;
import io.questdb.std.microtime.TimestampLocaleFactory;
import io.questdb.std.str.DirectCharSink;
import io.questdb.std.time.DateFormatFactory;
import io.questdb.std.time.DateLocaleFactory;
......@@ -202,8 +204,8 @@ public class TypeManagerTest {
InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
new DateFormatFactory(),
DateLocaleFactory.INSTANCE,
new io.questdb.std.microtime.DateFormatFactory(),
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
new TimestampFormatFactory(),
TimestampLocaleFactory.INSTANCE
);
inputFormatConfiguration.parseConfiguration(jsonLexer, fileResource);
......@@ -225,8 +227,8 @@ public class TypeManagerTest {
InputFormatConfiguration inputFormatConfiguration = new InputFormatConfiguration(
new DateFormatFactory(),
DateLocaleFactory.INSTANCE,
new io.questdb.std.microtime.DateFormatFactory(),
io.questdb.std.microtime.DateLocaleFactory.INSTANCE
new TimestampFormatFactory(),
TimestampLocaleFactory.INSTANCE
);
inputFormatConfiguration.parseConfiguration(jsonLexer, textConfiguration.getAdapterSetConfigurationFileName());
......
......@@ -26,7 +26,7 @@ package io.questdb.griffin.engine.groupby;
import io.questdb.griffin.SqlException;
import io.questdb.std.NumericException;
import io.questdb.std.microtime.DateFormatUtils;
import io.questdb.std.microtime.Dates;
import io.questdb.std.microtime.Timestamps;
import io.questdb.std.str.StringSink;
import io.questdb.test.tools.TestUtils;
import org.junit.Assert;
......@@ -58,13 +58,13 @@ public class TimestampSamplerFactoryTest {
TimestampSampler sampler = TimestampSamplerFactory.getInstance(sink, 120);
Assert.assertNotNull(sampler);
final long n = Dates.MINUTE_MICROS * (k == 0 ? 1 : k);
final long n = Timestamps.MINUTE_MICROS * (k == 0 ? 1 : k);
long timestamp = DateFormatUtils.parseTimestamp("2018-04-15T10:23:00.000000Z");
timestamp = timestamp - timestamp % n;
for (int i = 0; i < 60; i++) {
long actual = sampler.round(timestamp + i * Dates.SECOND_MICROS);
long actual = sampler.round(timestamp + i * Timestamps.SECOND_MICROS);
if (timestamp != actual) {
Assert.fail("Failed at: " + sink + ". Expected: " + Dates.toString(timestamp) + ", actual: " + Dates.toString(actual));
Assert.fail("Failed at: " + sink + ". Expected: " + Timestamps.toString(timestamp) + ", actual: " + Timestamps.toString(actual));
}
}
}
......@@ -93,13 +93,13 @@ public class TimestampSamplerFactoryTest {
TimestampSampler sampler = TimestampSamplerFactory.getInstance(sink, 120);
Assert.assertNotNull(sampler);
final long n = Dates.SECOND_MICROS * (k == 0 ? 1 : k);
final long n = Timestamps.SECOND_MICROS * (k == 0 ? 1 : k);
long timestamp = DateFormatUtils.parseTimestamp("2018-04-15T10:23:00.000000Z");
timestamp = timestamp - timestamp % n;
for (int i = 0; i < n; i += 4) {
long actual = sampler.round(timestamp + i);
if (timestamp != actual) {
Assert.fail("Failed at: " + sink + ". Expected: " + Dates.toString(timestamp) + ", actual: " + Dates.toString(actual));
Assert.fail("Failed at: " + sink + ". Expected: " + Timestamps.toString(timestamp) + ", actual: " + Timestamps.toString(actual));
}
}
}
......
......@@ -36,17 +36,24 @@ import org.junit.Test;
public class DateFormatCompilerTest {
private static final DateFormatCompiler compiler = new DateFormatCompiler();
private static final DateLocale defaultLocale = DateLocaleFactory.INSTANCE.getDateLocale("en-GB");
private static final TimestampLocale defaultLocale = TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB");
private final static StringSink sink = new StringSink();
private final static DateFormat REFERENCE = compiler.compile("yyyy-MM-ddTHH:mm:ss.SSSUUUz");
private final static TimestampFormat REFERENCE = compiler.compile("yyyy-MM-ddTHH:mm:ss.SSSUUUz");
@BeforeClass
public static void setUp() {
DateFormatUtils.updateReferenceYear(Dates.toMicros(1997, 1, 1, 0, 0));
DateFormatUtils.updateReferenceYear(Timestamps.toMicros(1997, 1, 1, 0, 0));
}
private static DateFormat get(CharSequence pattern) {
return compiler.compile(pattern, true);
@Test
public void testBasicParserCompiler() throws Exception {
TimestampFormat fmt = compiler.compile("E, dd MMM yyyy a KK:m:s.S Z");
String utcPattern = "yyyy-MM-ddTHH:mm:ss.SSSz";
TimestampFormat utc = compiler.compile(utcPattern);
long millis = fmt.parse("Mon, 08 Apr 2017 PM 11:11:10.123 UTC", defaultLocale);
sink.clear();
utc.format(millis, defaultLocale, "Z", sink);
TestUtils.assertEquals("2017-04-08T23:11:10.123Z", sink);
}
@Test(expected = NumericException.class)
......@@ -70,14 +77,16 @@ public class DateFormatCompilerTest {
}
@Test
public void testBasicParserCompiler() throws Exception {
DateFormat fmt = compiler.compile("E, dd MMM yyyy a KK:m:s.S Z");
String utcPattern = "yyyy-MM-ddTHH:mm:ss.SSSz";
DateFormat utc = compiler.compile(utcPattern);
long millis = fmt.parse("Mon, 08 Apr 2017 PM 11:11:10.123 UTC", defaultLocale);
public void testFormatBSTtoMSK() throws Exception {
TimestampFormat fmt = get("dd-MM-yyyy HH:mm:ss Z");
String targetTimezoneName = "MSK";
long millis = fmt.parse("06-04-2017 01:09:30 BST", defaultLocale);
millis += defaultLocale.getRules(targetTimezoneName).getOffset(millis);
sink.clear();
utc.format(millis, defaultLocale, "Z", sink);
TestUtils.assertEquals("2017-04-08T23:11:10.123Z", sink);
fmt.format(millis, defaultLocale, targetTimezoneName, sink);
TestUtils.assertEquals("06-04-2017 03:09:30 MSK", sink);
// assertThat("dd-MM-yyyy HH:mm:ss Z", "06-04-2017 03:09:30 MSK", "06-04-2017 01:09:30 BST");
}
@Test
......@@ -117,16 +126,17 @@ public class DateFormatCompilerTest {
}
@Test
public void testFormatBSTtoMSK() throws Exception {
DateFormat fmt = get("dd-MM-yyyy HH:mm:ss Z");
String targetTimezoneName = "MSK";
long millis = fmt.parse("06-04-2017 01:09:30 BST", defaultLocale);
millis += defaultLocale.getRules(targetTimezoneName).getOffset(millis);
sink.clear();
fmt.format(millis, defaultLocale, targetTimezoneName, sink);
TestUtils.assertEquals("06-04-2017 03:09:30 MSK", sink);
// assertThat("dd-MM-yyyy HH:mm:ss Z", "06-04-2017 03:09:30 MSK", "06-04-2017 01:09:30 BST");
public void testGreedyYear2() throws Exception {
long referenceYear = DateFormatUtils.getReferenceYear();
try {
DateFormatUtils.updateReferenceYear(Timestamps.toMicros(2015, 1, 20, 0, 0));
assertThat("y-MM", "1564-03-01T00:00:00.000Z", "1564-03");
assertThat("y-MM", "2006-03-01T00:00:00.000Z", "06-03");
assertThat("y-MM", "1955-03-01T00:00:00.000Z", "55-03");
assertThat("y-MM", "0137-03-01T00:00:00.000Z", "137-03");
} finally {
DateFormatUtils.updateReferenceYear(referenceYear);
}
}
@Test
......@@ -411,17 +421,16 @@ public class DateFormatCompilerTest {
}
@Test
public void testGreedyYear2() throws Exception {
long referenceYear = DateFormatUtils.getReferenceYear();
try {
DateFormatUtils.updateReferenceYear(Dates.toMicros(2015, 1, 20, 0, 0));
assertThat("y-MM", "1564-03-01T00:00:00.000Z", "1564-03");
assertThat("y-MM", "2006-03-01T00:00:00.000Z", "06-03");
assertThat("y-MM", "1955-03-01T00:00:00.000Z", "55-03");
assertThat("y-MM", "0137-03-01T00:00:00.000Z", "137-03");
} finally {
DateFormatUtils.updateReferenceYear(referenceYear);
}
public void testNegativeYear() throws Exception {
assertThat("yyyy MMM dd", "-2010-09-01T00:00:00.000Z", "-2010 Sep 01");
TimestampFormat fmt1 = compiler.compile("G yyyy MMM", true);
TimestampFormat fmt2 = compiler.compile("yyyy MMM dd", true);
long millis = fmt2.parse("-2010 Sep 01", defaultLocale);
sink.clear();
fmt1.format(millis, defaultLocale, "Z", sink);
TestUtils.assertEquals("BC -2010 Sep", sink);
}
@Test(expected = NumericException.class)
......@@ -595,17 +604,8 @@ public class DateFormatCompilerTest {
assertThat("My", "2010-04-01T00:00:00.000Z", "410");
}
@Test
public void testNegativeYear() throws Exception {
assertThat("yyyy MMM dd", "-2010-09-01T00:00:00.000Z", "-2010 Sep 01");
DateFormat fmt1 = compiler.compile("G yyyy MMM", true);
DateFormat fmt2 = compiler.compile("yyyy MMM dd", true);
long millis = fmt2.parse("-2010 Sep 01", defaultLocale);
sink.clear();
fmt1.format(millis, defaultLocale, "Z", sink);
TestUtils.assertEquals("BC -2010 Sep", sink);
private static TimestampFormat get(CharSequence pattern) {
return compiler.compile(pattern, true);
}
@Test
......@@ -755,18 +755,18 @@ public class DateFormatCompilerTest {
}
private void assertThat(String pattern, String expected, String input, CharSequence localeId) throws NumericException {
assertThat(pattern, expected, input, DateLocaleFactory.INSTANCE.getDateLocale(localeId));
assertThat(pattern, expected, input, TimestampLocaleFactory.INSTANCE.getDateLocale(localeId));
}
private void assertThat(String pattern, String expected, String input) throws NumericException {
assertThat(pattern, expected, input, defaultLocale);
}
private void assertThat(String pattern, String expected, String input, DateLocale locale) throws NumericException {
DateFormat format = get(pattern);
TestUtils.assertEquals(expected, Dates.toString(format.parse(input, locale)));
private void assertThat(String pattern, String expected, String input, TimestampLocale locale) throws NumericException {
TimestampFormat format = get(pattern);
TestUtils.assertEquals(expected, Timestamps.toString(format.parse(input, locale)));
DateFormat compiled = compiler.compile(pattern);
TestUtils.assertEquals(expected, Dates.toString(compiled.parse(input, locale)));
TimestampFormat compiled = compiler.compile(pattern);
TestUtils.assertEquals(expected, Timestamps.toString(compiled.parse(input, locale)));
}
}
\ No newline at end of file
......@@ -30,11 +30,11 @@ import org.junit.Test;
public class OffsetParserTest {
private static void assertError(String offset) {
Assert.assertEquals(Long.MIN_VALUE, Dates.parseOffset(offset, 0, offset.length()));
Assert.assertEquals(Long.MIN_VALUE, Timestamps.parseOffset(offset, 0, offset.length()));
}
private static void assertThat(int expected, String offset) {
long r = Dates.parseOffset(offset, 0, offset.length());
long r = Timestamps.parseOffset(offset, 0, offset.length());
Assert.assertEquals(expected, Numbers.decodeLowInt(r));
}
......
......@@ -50,14 +50,14 @@ public class TimeZoneRulesImplTest {
zoneRules.add(new TimeZoneRulesImpl(z, zone.getRules()));
}
long micros = Dates.toMicros(1900, 1, 1, 0, 0);
long deadline = Dates.toMicros(2115, 12, 31, 0, 0);
long micros = Timestamps.toMicros(1900, 1, 1, 0, 0);
long deadline = Timestamps.toMicros(2115, 12, 31, 0, 0);
while (micros < deadline) {
int y = Dates.getYear(micros);
boolean leap = Dates.isLeapYear(y);
int m = Dates.getMonthOfYear(micros, y, leap);
int d = Dates.getDayOfMonth(micros, y, m, leap);
int y = Timestamps.getYear(micros);
boolean leap = Timestamps.isLeapYear(y);
int m = Timestamps.getMonthOfYear(micros, y, leap);
int d = Timestamps.getDayOfMonth(micros, y, m, leap);
LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
......@@ -69,23 +69,23 @@ public class TimeZoneRulesImplTest {
long expected = zdt.getOffset().getTotalSeconds();
// find out how much algo added to datetime itself
long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * Dates.SECOND_MICROS;
long changed = Timestamps.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * Timestamps.SECOND_MICROS;
// add any extra time
expected += (changed - micros) / Dates.SECOND_MICROS;
expected += (changed - micros) / Timestamps.SECOND_MICROS;
long offset = rules.getOffset(micros, y, leap);
try {
Assert.assertEquals(expected, offset / Dates.SECOND_MICROS);
Assert.assertEquals(expected, offset / Timestamps.SECOND_MICROS);
} catch (Throwable e) {
System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(micros + offset));
System.out.println(zone.getId() + "; " + zdt + "; " + Timestamps.toString(micros + offset));
System.out.println("e: " + expected + "; a: " + offset);
System.out.println(dt);
System.out.println(Dates.toString(micros));
System.out.println(Timestamps.toString(micros));
throw e;
}
}
micros += Dates.DAY_MICROS;
micros += Timestamps.DAY_MICROS;
}
}
......@@ -103,14 +103,14 @@ public class TimeZoneRulesImplTest {
zoneRules.add(new TimeZoneRulesImpl(z, zone.getRules()));
}
long millis = Dates.toMicros(1900, 1, 1, 0, 0);
long deadline = Dates.toMicros(2615, 12, 31, 0, 0);
long millis = Timestamps.toMicros(1900, 1, 1, 0, 0);
long deadline = Timestamps.toMicros(2615, 12, 31, 0, 0);
while (millis < deadline) {
for (int i = 0, n = zones.size(); i < n; i++) {
zoneRules.get(i).getOffset(millis);
}
millis += Dates.DAY_MICROS;
millis += Timestamps.DAY_MICROS;
}
}
......@@ -124,21 +124,21 @@ public class TimeZoneRulesImplTest {
int d = 29;
LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
long millis = Dates.toMicros(y, m, d, 0, 0);
long millis = Timestamps.toMicros(y, m, d, 0, 0);
ZonedDateTime zdt = dt.atZone(zone);
long expected = zdt.getOffset().getTotalSeconds();
// find out how much algo added to datetime itself
long changed = Dates.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * 1000;
long changed = Timestamps.toMicros(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * 1000;
// add any extra time
expected += (changed - millis) / 1000;
long offset = rules.getOffset(millis, y, Dates.isLeapYear(y));
long offset = rules.getOffset(millis, y, Timestamps.isLeapYear(y));
try {
Assert.assertEquals(expected, offset / 1000);
} catch (Throwable e) {
System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(millis + offset));
System.out.println(zone.getId() + "; " + zdt + "; " + Timestamps.toString(millis + offset));
throw e;
}
}
......
......@@ -28,23 +28,23 @@ import io.questdb.std.NumericException;
import org.junit.Assert;
import org.junit.Test;
public class DateLocaleTest {
public class TimestampLocaleTest {
@Test(expected = NumericException.class)
public void testBadMonth() throws Exception {
String date = "23 Dek 2010";
DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
}
@Test(expected = NumericException.class)
public void testBadMonth2() throws Exception {
String date = "23 Zek 2010";
DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
}
@Test
public void testLongMonth() throws Exception {
String date = "23 December 2010";
long result = DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
long result = TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
Assert.assertEquals(8, Numbers.decodeHighInt(result));
Assert.assertEquals(11, Numbers.decodeLowInt(result));
}
......@@ -52,7 +52,7 @@ public class DateLocaleTest {
@Test
public void testLowCaseLongMonth() throws Exception {
String date = "23 december 2010";
long result = DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
long result = TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
Assert.assertEquals(8, Numbers.decodeHighInt(result));
Assert.assertEquals(11, Numbers.decodeLowInt(result));
}
......@@ -60,7 +60,7 @@ public class DateLocaleTest {
@Test
public void testRTLMonth() throws Exception {
String s = "23مارس";
long result = DateLocaleFactory.INSTANCE.getDateLocale("ar-DZ").matchMonth(s, 2, s.length());
long result = TimestampLocaleFactory.INSTANCE.getDateLocale("ar-DZ").matchMonth(s, 2, s.length());
Assert.assertEquals(4, Numbers.decodeHighInt(result));
Assert.assertEquals(2, Numbers.decodeLowInt(result));
}
......@@ -68,7 +68,7 @@ public class DateLocaleTest {
@Test
public void testShortMonth() throws Exception {
String date = "23 Sep 2010";
long result = DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
long result = TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 3, date.length());
Assert.assertEquals(3, Numbers.decodeHighInt(result));
Assert.assertEquals(8, Numbers.decodeLowInt(result));
}
......@@ -76,6 +76,6 @@ public class DateLocaleTest {
@Test(expected = NumericException.class)
public void testWrongLength() throws Exception {
String date = "23 Zek 2010";
DateLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 30, date.length());
TimestampLocaleFactory.INSTANCE.getDateLocale("en-GB").matchMonth(date, 30, date.length());
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class DatesTest {
public class TimestampsTest {
private final StringSink sink = new StringSink();
......@@ -42,100 +42,100 @@ public class DatesTest {
@Test
public void testAddDaysPrevEpoch() throws Exception {
long millis = DateFormatUtils.parseDateTime("1888-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.addDays(millis, 24));
DateFormatUtils.appendDateTime(sink, Timestamps.addDays(millis, 24));
TestUtils.assertEquals("1888-06-05T23:45:51.045Z", sink);
}
@Test
public void testAddMonths() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.addMonths(millis, -10));
DateFormatUtils.appendDateTime(sink, Timestamps.addMonths(millis, -10));
TestUtils.assertEquals("2007-07-12T23:45:51.045Z", sink);
}
@Test
public void testAddMonthsPrevEpoch() throws Exception {
long millis = DateFormatUtils.parseDateTime("1888-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.addMonths(millis, -10));
DateFormatUtils.appendDateTime(sink, Timestamps.addMonths(millis, -10));
TestUtils.assertEquals("1887-07-12T23:45:51.045Z", sink);
}
@Test
public void testAddYears() throws Exception {
long millis = DateFormatUtils.parseDateTime("1988-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.addYear(millis, 10));
DateFormatUtils.appendDateTime(sink, Timestamps.addYear(millis, 10));
TestUtils.assertEquals("1998-05-12T23:45:51.045Z", sink);
}
@Test
public void testAddYears3() throws Exception {
long millis = DateFormatUtils.parseDateTime("2014-01-01T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.addYear(millis, 1));
DateFormatUtils.appendDateTime(sink, Timestamps.addYear(millis, 1));
TestUtils.assertEquals("2015-01-01T00:00:00.000Z", sink);
}
@Test
public void testAddYearsNonLeapToLeap() throws Exception {
long millis = DateFormatUtils.parseDateTime("2015-01-01T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.addYear(millis, 1));
DateFormatUtils.appendDateTime(sink, Timestamps.addYear(millis, 1));
TestUtils.assertEquals("2016-01-01T00:00:00.000Z", sink);
}
@Test
public void testAddYearsPrevEpoch() throws Exception {
long millis = DateFormatUtils.parseDateTime("1888-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.addYear(millis, 10));
DateFormatUtils.appendDateTime(sink, Timestamps.addYear(millis, 10));
TestUtils.assertEquals("1898-05-12T23:45:51.045Z", sink);
}
@Test
public void testCeilDD() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.ceilDD(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.ceilDD(millis));
TestUtils.assertEquals("2008-05-12T23:59:59.999Z", sink);
}
@Test
public void testCeilDDPrevEpoch() throws Exception {
long millis = DateFormatUtils.parseDateTime("1888-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.ceilDD(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.ceilDD(millis));
TestUtils.assertEquals("1888-05-12T23:59:59.999Z", sink);
}
@Test
public void testCeilMM() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.ceilMM(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.ceilMM(millis));
TestUtils.assertEquals("2008-05-31T23:59:59.999Z", sink);
}
@Test
public void testCeilYYYY() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.ceilYYYY(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.ceilYYYY(millis));
TestUtils.assertEquals("2008-12-31T23:59:59.999Z", sink);
}
@Test
public void testDayOfWeek() throws Exception {
long millis = DateFormatUtils.parseDateTime("1893-03-19T17:16:30.192Z");
Assert.assertEquals(7, Dates.getDayOfWeek(millis));
Assert.assertEquals(1, Dates.getDayOfWeekSundayFirst(millis));
Assert.assertEquals(7, Timestamps.getDayOfWeek(millis));
Assert.assertEquals(1, Timestamps.getDayOfWeekSundayFirst(millis));
millis = DateFormatUtils.parseDateTime("2017-04-09T17:16:30.192Z");
Assert.assertEquals(7, Dates.getDayOfWeek(millis));
Assert.assertEquals(1, Dates.getDayOfWeekSundayFirst(millis));
Assert.assertEquals(7, Timestamps.getDayOfWeek(millis));
Assert.assertEquals(1, Timestamps.getDayOfWeekSundayFirst(millis));
}
@Test
public void testDaysBetween() throws Exception {
Assert.assertEquals(41168,
Dates.getDaysBetween(
Timestamps.getDaysBetween(
DateFormatUtils.parseDateTime("1904-11-05T23:45:41.045Z"),
DateFormatUtils.parseDateTime("2017-07-24T23:45:31.045Z")
)
);
Assert.assertEquals(41169,
Dates.getDaysBetween(
Timestamps.getDaysBetween(
DateFormatUtils.parseDateTime("1904-11-05T23:45:41.045Z"),
DateFormatUtils.parseDateTime("2017-07-24T23:45:51.045Z")
)
......@@ -145,28 +145,28 @@ public class DatesTest {
@Test
public void testFloorDD() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.floorDD(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.floorDD(millis));
TestUtils.assertEquals("2008-05-12T00:00:00.000Z", sink);
}
@Test
public void testFloorHH() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.floorHH(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.floorHH(millis));
TestUtils.assertEquals("2008-05-12T23:00:00.000Z", sink);
}
@Test
public void testFloorMM() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.floorMM(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.floorMM(millis));
TestUtils.assertEquals("2008-05-01T00:00:00.000Z", sink);
}
@Test
public void testFloorYYYY() throws Exception {
long millis = DateFormatUtils.parseDateTime("2008-05-12T23:45:51.045Z");
DateFormatUtils.appendDateTime(sink, Dates.floorYYYY(millis));
DateFormatUtils.appendDateTime(sink, Timestamps.floorYYYY(millis));
TestUtils.assertEquals("2008-01-01T00:00:00.000Z", sink);
}
......@@ -212,7 +212,7 @@ public class DatesTest {
public void testMonthsBetween() throws Exception {
// a < b, same year
Assert.assertEquals(2,
Dates.getMonthsBetween(
Timestamps.getMonthsBetween(
DateFormatUtils.parseDateTime("2014-05-12T23:45:51.045Z"),
DateFormatUtils.parseDateTime("2014-07-15T23:45:51.045Z")
)
......@@ -220,7 +220,7 @@ public class DatesTest {
// a > b, same year
Assert.assertEquals(2,
Dates.getMonthsBetween(
Timestamps.getMonthsBetween(
DateFormatUtils.parseDateTime("2014-07-15T23:45:51.045Z"),
DateFormatUtils.parseDateTime("2014-05-12T23:45:51.045Z")
)
......@@ -228,7 +228,7 @@ public class DatesTest {
// a < b, different year
Assert.assertEquals(26,
Dates.getMonthsBetween(
Timestamps.getMonthsBetween(
DateFormatUtils.parseDateTime("2014-05-12T23:45:51.045Z"),
DateFormatUtils.parseDateTime("2016-07-15T23:45:51.045Z")
)
......@@ -236,13 +236,13 @@ public class DatesTest {
// a < b, same year, a has higher residuals
Assert.assertEquals(1,
Dates.getMonthsBetween(DateFormatUtils.parseDateTime("2014-05-12T23:45:51.045Z"),
Timestamps.getMonthsBetween(DateFormatUtils.parseDateTime("2014-05-12T23:45:51.045Z"),
DateFormatUtils.parseDateTime("2014-07-03T23:45:51.045Z"))
);
// a < b, a before epoch, a has higher residuals
Assert.assertEquals(109 * 12 + 1,
Dates.getMonthsBetween(DateFormatUtils.parseDateTime("1905-05-12T23:45:51.045Z"),
Timestamps.getMonthsBetween(DateFormatUtils.parseDateTime("1905-05-12T23:45:51.045Z"),
DateFormatUtils.parseDateTime("2014-07-03T23:45:51.045Z"))
);
}
......@@ -251,7 +251,7 @@ public class DatesTest {
public void testNExtOrSameDow3() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.nextOrSameDayOfWeek(millis, 4));
DateFormatUtils.appendDateTime(sink, Timestamps.nextOrSameDayOfWeek(millis, 4));
TestUtils.assertEquals("2017-04-06T00:00:00.000Z", sink);
}
......@@ -259,7 +259,7 @@ public class DatesTest {
public void testNextOrSameDow1() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.nextOrSameDayOfWeek(millis, 3));
DateFormatUtils.appendDateTime(sink, Timestamps.nextOrSameDayOfWeek(millis, 3));
TestUtils.assertEquals("2017-04-12T00:00:00.000Z", sink);
}
......@@ -267,13 +267,13 @@ public class DatesTest {
public void testNextOrSameDow2() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.nextOrSameDayOfWeek(millis, 6));
DateFormatUtils.appendDateTime(sink, Timestamps.nextOrSameDayOfWeek(millis, 6));
TestUtils.assertEquals("2017-04-08T00:00:00.000Z", sink);
}
@Test
public void testOverflowDate() {
Assert.assertEquals("6477-07-27T03:15:50.400Z", Dates.toString(142245170150400000L));
Assert.assertEquals("6477-07-27T03:15:50.400Z", Timestamps.toString(142245170150400000L));
}
@Test
......@@ -345,7 +345,7 @@ public class DatesTest {
public void testPreviousOrSameDow1() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.previousOrSameDayOfWeek(millis, 3));
DateFormatUtils.appendDateTime(sink, Timestamps.previousOrSameDayOfWeek(millis, 3));
TestUtils.assertEquals("2017-04-05T00:00:00.000Z", sink);
}
......@@ -353,7 +353,7 @@ public class DatesTest {
public void testPreviousOrSameDow2() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.previousOrSameDayOfWeek(millis, 6));
DateFormatUtils.appendDateTime(sink, Timestamps.previousOrSameDayOfWeek(millis, 6));
TestUtils.assertEquals("2017-04-01T00:00:00.000Z", sink);
}
......@@ -361,21 +361,21 @@ public class DatesTest {
public void testPreviousOrSameDow3() throws Exception {
// thursday
long millis = DateFormatUtils.parseDateTime("2017-04-06T00:00:00.000Z");
DateFormatUtils.appendDateTime(sink, Dates.previousOrSameDayOfWeek(millis, 4));
DateFormatUtils.appendDateTime(sink, Timestamps.previousOrSameDayOfWeek(millis, 4));
TestUtils.assertEquals("2017-04-06T00:00:00.000Z", sink);
}
@Test
public void testYearsBetween() throws Exception {
Assert.assertEquals(112,
Dates.getYearsBetween(
Timestamps.getYearsBetween(
DateFormatUtils.parseDateTime("1904-11-05T23:45:41.045Z"),
DateFormatUtils.parseDateTime("2017-07-24T23:45:31.045Z")
)
);
Assert.assertEquals(113,
Dates.getYearsBetween(
Timestamps.getYearsBetween(
DateFormatUtils.parseDateTime("1904-11-05T23:45:41.045Z"),
DateFormatUtils.parseDateTime("2017-12-24T23:45:51.045Z")
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册