Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updateBy functionality to Deephaven Community #2516

Merged
merged 26 commits into from
Jun 30, 2022
Merged
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5150614
End of Week commit
lbooker42 Jun 10, 2022
7b49e94
merged upstream
lbooker42 Jun 10, 2022
3e981fc
spotless and WIP
lbooker42 Jun 10, 2022
8216802
Merge branch 'deephaven:main' into lab-updateby-oa
lbooker42 Jun 14, 2022
a7271b0
Tests passing, ready for initial review
lbooker42 Jun 14, 2022
5784fdc
Merge remote-tracking branch 'origin/lab-updateby-oa' into lab-update…
lbooker42 Jun 14, 2022
50f6724
minor doc changes
lbooker42 Jun 14, 2022
5c6b87a
Addressed immutable PR comments
lbooker42 Jun 16, 2022
1449e7f
Renames to remove 'index' references
lbooker42 Jun 16, 2022
00c4978
More PR comments addressed
lbooker42 Jun 21, 2022
9c2c4e0
Moved TimeScale to a new Immutable class
lbooker42 Jun 21, 2022
92a077c
updated hash table files to add constructor visibility
lbooker42 Jun 22, 2022
5be99f1
converted interface to use Selectable
lbooker42 Jun 22, 2022
746192b
Merge branch 'main' into lab-updateby-oa
lbooker42 Jun 22, 2022
94b7a38
Merge branch 'deephaven:main' into lab-updateby-oa
lbooker42 Jun 23, 2022
213968a
API changes
lbooker42 Jun 23, 2022
2f4b891
Merge branch 'lab-updateby-oa' of github.com:lbooker42/deephaven-core…
lbooker42 Jun 23, 2022
78b7254
spotless applied
lbooker42 Jun 23, 2022
6c2e894
spotless applied
lbooker42 Jun 23, 2022
b7fb32b
Another round of PR comments addressed
lbooker42 Jun 28, 2022
8937bee
More PR-related updates
lbooker42 Jun 28, 2022
c6ed557
Moved UpdateByControl to 'table-api' and cleanup
lbooker42 Jun 29, 2022
dbc48f9
PR comments addressed
lbooker42 Jun 29, 2022
3d405b5
spotless and PR changes
lbooker42 Jun 29, 2022
7145cb2
Fixed OOB failure (caused by bug in CumMinMaxSpec.applicableTo)
lbooker42 Jun 29, 2022
be260ef
Merge upstream
lbooker42 Jun 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.deephaven.engine.table;

/**
* Directives for how to handle {@code null} and {@code NaN} values while processing EMAs
*/
public enum BadDataBehavior {
/** Reset the state for the bucket to {@code null} when invalid data is encountered */
Reset,

/** Skip and do not process the invalid data without changing state */
Skip,

/** Throw an exception and abort processing when bad data is encountered */
Throw,

/** Allow the bad data to poison the result. This is only valid for use with NaN */
Poison
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.deephaven.engine.table;

import io.deephaven.engine.table.updateBySpec.UpdateBySpec;
import org.jetbrains.annotations.NotNull;

public class ColumnUpdateClause implements UpdateByClause {
private final UpdateBySpec spec;
@NotNull
private final String[] columns;

ColumnUpdateClause(@NotNull final UpdateBySpec spec, @NotNull final String... columns) {
this.spec = spec;
this.columns = columns;
}

public UpdateBySpec getSpec() {
return spec;
}

@NotNull
public String[] getColumns() {
return columns;
}

@Override
public <V extends Visitor> V walk(@NotNull V v) {
v.visit(this);
return v;
}
}
209 changes: 209 additions & 0 deletions engine/api/src/main/java/io/deephaven/engine/table/EmaControl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
package io.deephaven.engine.table;

import org.jetbrains.annotations.NotNull;

import java.math.MathContext;
import java.util.Collection;

/**
* <p>
* Control parameters for performing EMAs with {@link Table#updateBy(Collection, String...)}
* </p>
* <p>
* Defaults are as follows
* </p>
* <ul>
* <li>On null Values - Skip</li>
* <li>On NaN Values - Skip</li>
* <li>On null timestamps - Skip</li>
* <li>On zero delta Time - Skip</li>
* <li>On negative delta time - Throw Exception</li>
* <li>BigDecimal / BigInteger MathContext - Decimal 128</li>
* </ul>
*/
public class EmaControl {
public final BadDataBehavior onNullValue;
public final BadDataBehavior onNanValue;
public final BadDataBehavior onNullTime;
public final BadDataBehavior onZeroDeltaTime;
public final BadDataBehavior onNegativeDeltaTime;
public final MathContext bigValueContext;

@NotNull
public static Builder get() {
return new Builder();
}

private EmaControl(@NotNull final BadDataBehavior onNullValue,
@NotNull final BadDataBehavior onNanValue,
@NotNull final BadDataBehavior onNullTime,
BadDataBehavior onZeroDeltaTime, BadDataBehavior onNegativeDeltaTime,
@NotNull final MathContext bigValueContext) {
this.onNullValue = onNullValue;
this.onNanValue = onNanValue;
this.onNullTime = onNullTime;
this.onZeroDeltaTime = onZeroDeltaTime;
this.onNegativeDeltaTime = onNegativeDeltaTime;
this.bigValueContext = bigValueContext;
}

/**
* Get the behavior for when null values are encountered.
*
* @return the behavior for null values.
*/
public BadDataBehavior getOnNullValue() {
return onNullValue;
}

/**
* Get the behavior for when NaN values are encountered.
*
* @return the behavior for NaN values
*/
public BadDataBehavior getOnNanValue() {
return onNanValue;
}

/**
* Get the behavior for when null timestamps are encountered.
*
* @return the behavior for null timestamps.
*/
public BadDataBehavior getOnNullTime() {
return onNullTime;
}

/**
* Get the behavior for when negative sample-to-sample time differences are encountered
*
* @return the behavior for when dt is negative
*/
public BadDataBehavior getOnNegativeDeltaTime() {
return onNegativeDeltaTime;
}

/**
* Get the behavior for when zero sample-to-sample-time differences are encountered.
*
* @return the behavior for when dt is zero
*/
public BadDataBehavior getOnZeroDeltaTime() {
return onZeroDeltaTime;
}

/**
* Get the {@link MathContext} to use when processing {@link java.math.BigInteger} and {@link java.math.BigDecimal}
* values.
*
* @return the {@link MathContext}
*/
public MathContext getBigValueContext() {
return bigValueContext;
}

@Override
public String toString() {
return "EmaControl{" +
"onNullValue=" + onNullValue +
", onNanValue=" + onNanValue +
", bigValueContext=" + bigValueContext +
'}';
}

@SuppressWarnings("unused")
public static class Builder {
private BadDataBehavior onNullValue = BadDataBehavior.Skip;
private BadDataBehavior onNanValue = BadDataBehavior.Skip;
private BadDataBehavior onNullTime = BadDataBehavior.Skip;
private BadDataBehavior onZeroDeltaTime = BadDataBehavior.Skip;
private BadDataBehavior onNegativeDeltaTime = BadDataBehavior.Throw;
private MathContext bigValueContext = MathContext.DECIMAL128;

/**
* Set the behavior for when null samples are encountered. Defaults to {@link BadDataBehavior#Skip}.
*
* @param behavior the desired behavior
* @return this builder
*/
@NotNull
public Builder onNullValue(@NotNull final BadDataBehavior behavior) {
this.onNullValue = behavior;
return this;
}

/**
* Set the behavior for when NaN samples are encountered. Defaults to {@link BadDataBehavior#Skip}.
*
* @param behavior the desired behavior
* @return this builder
*/
@NotNull
public Builder onNanValue(@NotNull final BadDataBehavior behavior) {
this.onNanValue = behavior;
return this;
}

/**
* Set the behavior for when null timestamps are encountered. Defaults to {@link BadDataBehavior#Skip}.
*
* @param behavior the desired behavior
* @return this builder
*/
@NotNull
public Builder onNullTime(@NotNull final BadDataBehavior behavior) {
this.onNullTime = behavior;
return this;
}

/**
* Set the behavior for when zero sample-to-sample times are encountered. Defaults to
* {@link BadDataBehavior#Skip}.
*
* @param behavior the desired behavior
* @return this builder
*/
@NotNull
public Builder onZeroDeltaTime(@NotNull final BadDataBehavior behavior) {
this.onZeroDeltaTime = behavior;
return this;
}

/**
* Set the behavior for when negative sample-to-sample times are encountered. Defaults to
* {@link BadDataBehavior#Throw}.
*
* @param behavior the desired behavior
* @return this builder
*/
@NotNull
public Builder onNegativeDeltaTime(@NotNull final BadDataBehavior behavior) {
this.onNegativeDeltaTime = behavior;
return this;
}

/**
* Set the {@link MathContext} to use for processing {@link java.math.BigDecimal} and
* {@link java.math.BigInteger} types. Defaults to {@link MathContext#DECIMAL128}.
*
* @param bigValueContext the desired behavior
* @return this builder
*/
@NotNull
public Builder bigValueContext(@NotNull final MathContext bigValueContext) {
this.bigValueContext = bigValueContext;
return this;
}

/**
* Construct an {@link EmaControl} from this builder.
*
* @return
*/
@NotNull
public EmaControl build() {
return new EmaControl(onNullValue, onNanValue, onNullTime, onZeroDeltaTime, onNegativeDeltaTime,
bigValueContext);
}
}
}
Loading