Skip to content

Commit

Permalink
Rewrite Java Time Libs (deephaven#3856)
Browse files Browse the repository at this point in the history
A complete rewrite of the time libraries and standardization of engine operations in terms of java.time.* types.
* Replace Joda and Deephaven types with standard java.time.* types.
* Remove deprecated methods.
* Consistently name methods and parameters.
* Add missing methods.
* Handle parsing more data formats, especially ISO formats.
* Change literal formats to be in line with ISO.
* User customizable time zone aliases.
* Use the java default time zone as the default time zone.
* High test coverage.

---------

Co-authored-by: Ryan Caudy <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
  • Loading branch information
3 people authored Jun 2, 2023
1 parent 4ef4d32 commit a4f154d
Show file tree
Hide file tree
Showing 1,987 changed files with 136,722 additions and 132,567 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
*/
package io.deephaven.benchmarking;

import io.deephaven.configuration.Configuration;
import io.deephaven.configuration.DataDir;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.TableDefinition;
import io.deephaven.time.DateTime;
import io.deephaven.util.annotations.ScriptApi;
import io.deephaven.benchmarking.generator.*;
import io.deephaven.benchmarking.impl.PersistentBenchmarkTableBuilder;
Expand All @@ -18,6 +16,7 @@
import org.openjdk.jmh.infra.BenchmarkParams;

import java.nio.file.Path;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -147,24 +146,24 @@ public static ColumnGenerator<Character> charCol(String name, char min, char max

/**
* @param name The name of the column
* @return a {@link ColumnGenerator< DateTime >} for use with
* @return a {@link ColumnGenerator< Instant >} for use with
* {@link BenchmarkTableBuilder#addColumn(ColumnGenerator)}
*/
@ScriptApi
public static ColumnGenerator<DateTime> dateCol(String name) {
return new DateColumnGenerator(name);
public static ColumnGenerator<Instant> instantCol(String name) {
return new InstantColumnGenerator(name);
}

/**
* @param name The name of the column
* @param min the minimum value
* @param max the maximum value
* @return a {@link ColumnGenerator< DateTime >} for use with
* @return a {@link ColumnGenerator< Instant >} for use with
* {@link BenchmarkTableBuilder#addColumn(ColumnGenerator)}
*/
@ScriptApi
public static ColumnGenerator<DateTime> dateCol(String name, DateTime min, DateTime max) {
return new DateColumnGenerator(name, min, max);
public static ColumnGenerator<Instant> instantCol(String name, Instant min, Instant max) {
return new InstantColumnGenerator(name, min, max);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.benchmarking.generator;

import io.deephaven.engine.table.ColumnDefinition;
import io.deephaven.time.DateTimeUtils;
import io.deephaven.benchmarking.generator.random.ExtendedRandom;

import java.time.Instant;

public class InstantColumnGenerator implements ColumnGenerator<Instant> {

private NumGenerator gen;
private final ColumnDefinition<Instant> def;
private final long min;
private final long max;

public InstantColumnGenerator(String name) {
this(name, 0, Long.MAX_VALUE);
}

public InstantColumnGenerator(String name, Instant min, Instant max) {
this(name, DateTimeUtils.epochNanos(min), DateTimeUtils.epochNanos(max));
}

private InstantColumnGenerator(String name, long min, long max) {
def = ColumnDefinition.ofTime(name);
this.min = min;
this.max = max;
}

@Override
public ColumnDefinition<Instant> getDefinition() {
return def;
}

@Override
public String getUpdateString(String varName) {
return def.getName() + "=(DateTime)" + varName + ".get()";
}

@Override
public String getName() {
return def.getName();
}

@Override
public void init(ExtendedRandom random) {
gen = new NumGenerator(min, max, random);
}

public Instant get() {
return DateTimeUtils.epochNanosToInstant(gen.getLong());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.deephaven.clientsupport.gotorow;

import java.time.Instant;
import java.util.function.Function;
import gnu.trove.set.TLongSet;
import gnu.trove.set.hash.TLongHashSet;
Expand All @@ -12,7 +13,7 @@
import io.deephaven.engine.table.Table;
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.io.logger.Logger;
import io.deephaven.time.DateTime;
import io.deephaven.time.DateTimeUtils;

import java.util.Random;

Expand Down Expand Up @@ -112,10 +113,10 @@ public Long apply(Table table) {
log.info().append("Using numerical distance (").appendDouble(dl).append(", ").appendDouble(du)
.append(")").endl();
return index.find(du < dl ? closestUpperRowYet : closestLowerRowYet);
} else if (DateTime.class.isAssignableFrom(columnType)) {
long nu = ((DateTime) closestUpperValueYet).getNanos();
long nl = ((DateTime) closestLowerValueYet).getNanos();
long ns = ((DateTime) seekValue).getNanos();
} else if (Instant.class.isAssignableFrom(columnType)) {
long nu = DateTimeUtils.epochNanos(((Instant) closestUpperValueYet));
long nl = DateTimeUtils.epochNanos(((Instant) closestLowerValueYet));
long ns = DateTimeUtils.epochNanos(((Instant) seekValue));
long du = Math.abs(nu - ns);
long dl = Math.abs(nl - ns);
log.info().append("Using nano distance (").append(dl).append(", ").append(du).append(")").endl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import io.deephaven.engine.rowset.chunkattributes.OrderedRowKeys;
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.function.Numeric;
import io.deephaven.time.DateTime;
import io.deephaven.hash.KeyedLongObjectHash;
import io.deephaven.hash.KeyedLongObjectHashMap;
import io.deephaven.hash.KeyedLongObjectKey;
Expand All @@ -30,6 +29,7 @@
import org.apache.commons.lang3.mutable.MutableObject;
import org.jetbrains.annotations.Nullable;

import java.time.Instant;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -275,7 +275,9 @@ public BucketState newValue(final Long key) {
}
};

private DownsamplerListener(final QueryTable sourceTable, final QueryTable resultTable,
private DownsamplerListener(
final QueryTable sourceTable,
final QueryTable resultTable,
final DownsampleKey key) {
super("downsample listener", sourceTable, resultTable);
this.sourceTable = sourceTable;
Expand All @@ -284,14 +286,14 @@ private DownsamplerListener(final QueryTable sourceTable, final QueryTable resul
this.key = key;

final ColumnSource xSource = sourceTable.getColumnSource(key.xColumnName);
if (xSource.getType() == DateTime.class) {
this.xColumnSource = ReinterpretUtils.dateTimeToLongSource(xSource);
if (xSource.getType() == Instant.class) {
this.xColumnSource = ReinterpretUtils.instantToLongSource(xSource);
} else if (xSource.allowsReinterpret(long.class)) {
// noinspection unchecked
this.xColumnSource = xSource.reinterpret(long.class);
} else {
throw new IllegalArgumentException(
"Cannot use non-DateTime, non-long x column " + key.xColumnName + " in downsample");
"Cannot use non-Instant, non-long x column " + key.xColumnName + " in downsample");
}

this.valueColumnSources = Arrays.stream(this.key.yColumnNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.*;
import java.time.ZoneId;
import java.util.*;

/**
Expand Down Expand Up @@ -160,7 +161,7 @@ private static String getRootPath() {
* @return the TimeZone the server is running in
*/
public TimeZone getServerTimezone() {
return TimeZone.getTimeZone(getProperty("server.timezone"));
return TimeZone.getTimeZone(ZoneId.systemDefault());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,20 @@ public Boolean isTime() {
}
});

types.put("DateTime", new Type() {
types.put("Instant", new Type() {
@Override
public String getGenericSignature(int index) {
return null;
}

@Override
public String getVariableType(int index) {
return "DateTime[]";
return "Instant[]";
}

@Override
public String getIndexableDataCode(String variableName) {
return "new IndexableNumericDataArrayDateTime(" + variableName + ", " + PLOT_INFO_ID + ")";
return "new IndexableNumericDataArrayInstant(" + variableName + ", " + PLOT_INFO_ID + ")";
}

@Override
Expand Down Expand Up @@ -568,7 +568,7 @@ private static ArrayList<ArrayList<Type>> constructRestrictedNumericalTypes(fina

private static final String[] timeTypes = {
"Date",
"DateTime"
"Instant"
};

private static final String[] numberTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,8 @@ private static Map<String, PyArg> getPyArgs() {
final String[] taTable = new String[] {"Table", "SelectableDataSet"};

final String[] taDataCategory = new String[] {"str", "List[str]", "List[int]", "List[float]"};
final String[] taDataNumeric = new String[] {"str", "List[int]", "List[float]", "List[DateTime]"};
final String[] taDataTime = new String[] {"str", "List[DateTime]"};
final String[] taDataNumeric = new String[] {"str", "List[int]", "List[float]", "List[Instant]"};
final String[] taDataTime = new String[] {"str", "List[Instant]"};
final String[] taMultiSeriesKey = new String[] {"List[Any]"}; // todo keys are technically Object[]. How to
// support?
final String[] taColor = new String[] {"str", "int", "Color"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from deephaven import DHError, dtypes
from deephaven._wrapper import JObjectWrapper
from deephaven.dtypes import DateTime, PyObject
from deephaven.dtypes import Instant, PyObject
from deephaven.plot import LineStyle, PlotStyle, Color, Font, AxisFormat, Shape, AxisTransform, \
SelectableDataSet
from deephaven.table import Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
*/
package io.deephaven.integrations.common;

import io.deephaven.time.DateTime;
import io.deephaven.time.DateTimeUtils;
import io.deephaven.util.BooleanUtils;

import java.time.Instant;

/**
* General purpose helper methods for array conversion methods from specific object types to/from primitive types. This
* is specifically intended to improve performance in integration with Python, where conversion of primitive type arrays
Expand Down Expand Up @@ -44,31 +45,31 @@ public static Boolean[] translateArrayByteToBoolean(final byte[] array) {
}

/**
* Translates a DateTime array to a long array. The mapping will be performed according to
* {@link DateTimeUtils#nanos(DateTime)}. This is the (psuedo)inverse of `translateArrayLongToDateTime`.
* Translates an Instant array to a long array. The mapping will be performed according to
* {@link DateTimeUtils#epochNanos(Instant)}. This is the (psuedo)inverse of `translateArrayLongToInstant`.
*
* @param array - the DateTime array
* @param array - the Instant array
* @return the corresponding long array
*/
public static long[] translateArrayDateTimeToLong(final DateTime[] array) {
public static long[] translateArrayInstantToLong(final Instant[] array) {
final long[] out = new long[array.length];
for (int ai = 0; ai < array.length; ai++) {
out[ai] = DateTimeUtils.nanos(array[ai]);
out[ai] = DateTimeUtils.epochNanos(array[ai]);
}
return out;
}

/**
* Translates a long array to a DateTime array. The mapping will be performed according to
* {@link DateTimeUtils#nanosToTime(long)}. This is the (psuedo)inverse of `translateArrayLongToDateTime`.
* Translates a long array to an Instant array. The mapping will be performed according to
* {@link DateTimeUtils#epochNanosToInstant(long)}. This is the (psuedo)inverse of `translateArrayLongToInstant`.
*
* @param array - the long array
* @return the corresponding DateTime array
*/
public static DateTime[] translateArrayLongToDateTime(final long[] array) {
final DateTime[] out = new DateTime[array.length];
public static Instant[] translateArrayLongToInstant(final long[] array) {
final Instant[] out = new Instant[array.length];
for (int ai = 0; ai < array.length; ai++) {
out[ai] = DateTimeUtils.nanosToTime(array[ai]);
out[ai] = DateTimeUtils.epochNanosToInstant(array[ai]);
}
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import io.deephaven.base.verify.Require;
import io.deephaven.engine.table.Table;
import io.deephaven.vector.*;
import io.deephaven.time.DateTime;

import java.time.Instant;

/**
* Utilities for building model farms.
Expand Down Expand Up @@ -53,9 +54,9 @@ public static String[] arrayString(final Object o) {
* @param o table cell value.
* @return date time array.
*/
public static DateTime[] arrayDateTime(final Object o) {
public static Instant[] arrayInstant(final Object o) {
// noinspection unchecked
return o == null ? null : ((ObjectVector<DateTime>) o).toArray();
return o == null ? null : ((ObjectVector<Instant>) o).toArray();
}

/**
Expand Down
Loading

0 comments on commit a4f154d

Please sign in to comment.