-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add slice API for TableOperations (#6272)
- Loading branch information
1 parent
5da544b
commit e33e9d7
Showing
13 changed files
with
213 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
java-client/session-dagger/src/test/java/io/deephaven/client/SliceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
// | ||
package io.deephaven.client; | ||
|
||
import io.deephaven.client.impl.TableHandle; | ||
import io.deephaven.client.impl.TableHandle.TableHandleException; | ||
import io.deephaven.qst.table.TableSpec; | ||
import io.deephaven.qst.table.TimeTable; | ||
import org.junit.Test; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; | ||
|
||
public class SliceTest extends DeephavenSessionTestBase { | ||
|
||
private static final TableSpec STATIC_BASE = TableSpec.empty(100).view("I=ii"); | ||
private static final TableSpec TICKING_BASE = TimeTable.of(Duration.ofMillis(100)).view("I=ii"); | ||
|
||
@Test | ||
public void bothNonNegativeStartBeforeEnd() throws InterruptedException, TableHandleException { | ||
allow(0, 50); | ||
allow(25, 75); | ||
} | ||
|
||
@Test | ||
public void bothNonNegativeStartAfterEnd() throws IllegalArgumentException { | ||
disallow(50, 0); | ||
} | ||
|
||
@Test | ||
public void bothNegativeStartBeforeEnd() throws InterruptedException, TableHandleException { | ||
allow(-50, -25); | ||
} | ||
|
||
@Test | ||
public void bothNegativeStartAfterEnd() throws IllegalArgumentException { | ||
disallow(-25, -50); | ||
} | ||
|
||
@Test | ||
public void diffSignStartBeforeEnd() throws InterruptedException, TableHandleException { | ||
allow(-25, 25); | ||
} | ||
|
||
@Test | ||
public void diffSignStartAfterEnd() throws InterruptedException, TableHandleException { | ||
allow(25, -25); | ||
} | ||
|
||
@Test | ||
public void startZeroEndNegative() throws InterruptedException, TableHandleException { | ||
allow(0, -25); | ||
} | ||
|
||
private void allow(long start, long end) | ||
throws InterruptedException, TableHandleException { | ||
try (final TableHandle handle = session.batch().execute(STATIC_BASE.slice(start, end))) { | ||
assertThat(handle.isSuccessful()).isTrue(); | ||
} | ||
try (final TableHandle handle = session.batch().execute(TICKING_BASE.slice(start, end))) { | ||
assertThat(handle.isSuccessful()).isTrue(); | ||
} | ||
} | ||
|
||
private void disallow(long start, long end) throws IllegalArgumentException { | ||
try { | ||
STATIC_BASE.slice(start, end); | ||
failBecauseExceptionWasNotThrown(TableHandle.TableHandleException.class); | ||
} catch (IllegalArgumentException e) { | ||
// expected | ||
} | ||
try { | ||
TICKING_BASE.slice(start, end); | ||
failBecauseExceptionWasNotThrown(TableHandle.TableHandleException.class); | ||
} catch (IllegalArgumentException e) { | ||
// expected | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending | ||
// | ||
package io.deephaven.qst.table; | ||
|
||
import io.deephaven.annotations.NodeStyle; | ||
import org.immutables.value.Value.Check; | ||
import org.immutables.value.Value.Immutable; | ||
import org.immutables.value.Value.Parameter; | ||
|
||
@Immutable | ||
@NodeStyle | ||
public abstract class SliceTable extends TableBase implements SingleParentTable { | ||
|
||
public static SliceTable of(TableSpec parent, long firstPositionInclusive, long lastPositionExclusive) { | ||
return ImmutableSliceTable.of(parent, firstPositionInclusive, lastPositionExclusive); | ||
} | ||
|
||
@Parameter | ||
public abstract TableSpec parent(); | ||
|
||
@Parameter | ||
public abstract long firstPositionInclusive(); | ||
|
||
@Parameter | ||
public abstract long lastPositionExclusive(); | ||
|
||
@Override | ||
public final <T> T walk(Visitor<T> visitor) { | ||
return visitor.visit(this); | ||
} | ||
|
||
@Check | ||
final void checkPositions() { | ||
if (firstPositionInclusive() >= 0 && lastPositionExclusive() >= 0 | ||
&& lastPositionExclusive() < firstPositionInclusive()) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Cannot slice with a non-negative start position (%d) that is after a non-negative end position (%d).", | ||
firstPositionInclusive(), lastPositionExclusive())); | ||
} | ||
if (firstPositionInclusive() < 0 && lastPositionExclusive() < 0 | ||
&& lastPositionExclusive() < firstPositionInclusive()) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Cannot slice with a negative start position (%d) that is after a negative end position (%d).", | ||
firstPositionInclusive(), lastPositionExclusive())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters