Skip to content

Commit

Permalink
Merge pull request #5 from rcaudy/rwc-remove_dt
Browse files Browse the repository at this point in the history
Remove io.deephaven.time.DateTime and migrate all usages to java.time.Instant
  • Loading branch information
chipkent authored May 25, 2023
2 parents ebe4e31 + c9cfe18 commit afa53c2
Show file tree
Hide file tree
Showing 1,882 changed files with 127,247 additions and 128,969 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 @@ -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 @@ -3,7 +3,6 @@
*/
package io.deephaven.integrations.common;

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

Expand Down Expand Up @@ -45,36 +44,6 @@ public static Boolean[] translateArrayByteToBoolean(final byte[] array) {
return out;
}

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

/**
* 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`.
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
import io.deephaven.time.DateTimeUtils;
import io.deephaven.util.SafeCloseable;
import io.deephaven.vector.*;
import io.deephaven.time.DateTime;
import io.deephaven.engine.util.TableTools;
import org.junit.After;
import org.junit.Before;

import java.time.Instant;

public class TestModelFarmUtils extends BaseArrayTestCase {

private SafeCloseable executionContext;
Expand Down Expand Up @@ -63,13 +64,14 @@ public void testArrayString() {
assertNull(ModelFarmUtils.arrayString(null));
}

public void testArrayDateTime() {
final DateTime[] target = {DateTimeUtils.parseDateTime("2018-01-11T01:01:01 NY"),
DateTimeUtils.parseDateTime("2018-02-11T01:01:01 NY"),
DateTimeUtils.parseDateTime("2018-03-11T01:01:01 NY")};
final DateTime[] result = ModelFarmUtils.arrayDateTime(new ObjectVectorDirect<>(target));
public void testArrayInstant() {
final Instant[] target = {
DateTimeUtils.parseInstant("2018-01-11T01:01:01 NY"),
DateTimeUtils.parseInstant("2018-02-11T01:01:01 NY"),
DateTimeUtils.parseInstant("2018-03-11T01:01:01 NY")};
final Instant[] result = ModelFarmUtils.arrayInstant(new ObjectVectorDirect<>(target));
assertEquals(target, result);
assertNull(ModelFarmUtils.arrayDateTime(null));
assertNull(ModelFarmUtils.arrayInstant(null));
}

public void testArrayFloat() {
Expand Down
Loading

0 comments on commit afa53c2

Please sign in to comment.