Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build/
!**/src/main/**/build/
!**/src/test/**/build/

target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dhcVersion=0.34.2
dhcVersion=0.35.2
93 changes: 93 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.deephaven</groupId>
<artifactId>basic-java-client</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dhcVersion>0.35.2</dhcVersion>
<junit.jupiter.version>5.9.1</junit.jupiter.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-bom</artifactId>
<version>${dhcVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-java-client-barrage</artifactId>
</dependency>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-log-to-slf4j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.12</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-hotspot-impl</artifactId>
<version>${dhcVersion}</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<properties>
<property>
<name>junit.platform.version</name>
<value>${junit.jupiter.version}</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
63 changes: 39 additions & 24 deletions src/main/java/io/deephaven/examples/BasicJavaClientExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,22 @@ public static void main(String[] args) throws Exception {
final BarrageSession barrageSession = factory.newBarrageSession(sessionConfig);
final Session clientSession = barrageSession.session()) {

// Define an append-only "InputTable" on the server. The client can send data to the server to append to this.
// Define a new table to publish to the server. This table has three columns: an integer column and two
// string columns.
final NewTable myTable = NewTable.of(
Column.ofInt("MyIntCol", 1, 1, 2, 3, 5, 8, 13, 21, 34),
Column.of("MyStrCol", String.class, "This", "is", "an", "example", "table", "created", "on", "the", "client"),
Column.of("MyStrCol2", String.class, "Row1", "Row2", "Row3", "Row4", "Row5", "Row6", "Row7", "Row8", "Row9")
);

// Push the table to the server. This returns a TableHandle, which is a reference to the table on the server
// that can be used to run queries against the table from the client.
final TableHandle myTableHandle = barrageSession.putExport(myTable, bufferAllocator);

// Publish the table on the server. This makes the table accessible via the Deephaven UI.
clientSession.publish("my_table", myTableHandle).get();

// For a modifiable table, define an append-only "InputTable" on the server. The client can send data to the server to append to this.
final TableSpec inputTableSpec = InMemoryAppendOnlyInputTable.of(TableHeader.of(
ColumnHeader.ofInt("MyIntCol"),
ColumnHeader.of("MyStrCol", String.class),
Expand All @@ -90,7 +105,7 @@ public static void main(String[] args) throws Exception {
final TableHandle inputTableHandle = clientSession.execute(inputTableSpec);

// Publish the input table on the server -- this makes the table accessible via the UI.
clientSession.publish("my_table", inputTableHandle);
clientSession.publish("my_input_table", inputTableHandle);

// Define (client-side) a table of new rows to add to the InputTable on the server
final NewTable dataToAdd = NewTable.of(
Expand Down Expand Up @@ -125,21 +140,21 @@ public static void main(String[] args) throws Exception {
"def my_function(my_int) -> int:\n" +
" return my_int * 2\n" +
"\n" +
"my_new_table = my_table.update('MyIntColDoubled = my_function(MyIntCol)')"
"my_updated_input_table = my_input_table.update('MyIntColDoubled = my_function(MyIntCol)')"
);
if (changes.errorMessage().isPresent()) {
throw new RuntimeException(changes.errorMessage().get());
}

// Get a TableHandle for my my_new_table, accessing it by its name in the scope. We will use this to pull
// the table over to the client.
// (We could also use the TicketTable to execute additional queries against my_new_table.)
final TicketTable myNewTable_ticket = TicketTable.fromQueryScopeField("my_new_table");
final TableHandle myNewTableHandle_handle = clientSession.of(myNewTable_ticket);
// Get a TableHandle for my my_updated_input_table, accessing it by its name in the scope. We will use this
// to pull the table over to the client.
// (We could also use the TicketTable to execute additional queries against my_updated_input_table.)
final TicketTable myUpdatedInputTable_ticket = TicketTable.fromQueryScopeField("my_updated_input_table");
final TableHandle myUpdatedTableHandle_handle = clientSession.of(myUpdatedInputTable_ticket);

// Pull myNewTable over from the server and print out its contents.
System.out.println("Printing 'myNewTable' locally:");
pullDataToClient(barrageSession, myNewTableHandle_handle);
// Pull myTable over from the server and print out its contents.
System.out.println("Printing 'my_updated_input_table' locally:");
pullDataToClient(barrageSession, myUpdatedTableHandle_handle);

// Do the same for myAggregatedTable
System.out.println("Printing 'myAggregatedTable' locally:");
Expand All @@ -162,30 +177,30 @@ public static void main(String[] args) throws Exception {
* </ol>
*
* @param barrageSession The Barrage session to use.
* @param myNewTableHandle The TableHandle for the table whose data will be pulled from the server.
* @param tableHandle The TableHandle for the table whose data will be pulled from the server.
* @throws InterruptedException If interrupted while pulling the Barrage snapshot
*/
private static void pullDataToClient(BarrageSession barrageSession, TableHandle myNewTableHandle) throws InterruptedException, ExecutionException {
// Take a snapshot of the server-side version of the new table we created, and pull it back to the client.
// For our example this is fine, but for tables with millions of rows, this may take some time and use a
// lot of memory!
final BarrageSnapshot snapshot = barrageSession.snapshot(myNewTableHandle, BarrageUtil.DEFAULT_SNAPSHOT_DESER_OPTIONS);
final Table tableFromServer = snapshot.entireTable().get();

// Print the table to STDOUT:
private static void pullDataToClient(BarrageSession barrageSession, TableHandle tableHandle) throws InterruptedException, ExecutionException {
// Take a snapshot of a table on the server and pull it back to the client.
// For the example in this file this will work great is fine -- but for tables with millions of rows, this may
// take some time and use a lot of memory!
final BarrageSnapshot snapshot = barrageSession.snapshot(tableHandle, BarrageUtil.DEFAULT_SNAPSHOT_DESER_OPTIONS);
final Table localTableRetrievedFromServer = snapshot.entireTable().get();

// Print the table to STDOUT with TableTools.show():
System.out.println("Printing table with TableTools.show():");
TableTools.show(tableFromServer);
TableTools.show(localTableRetrievedFromServer);
System.out.println();

// We can also extract data from the table row-by-row, for example to use in other Java code.
// See https://deephaven.io/core/groovy/docs/how-to-guides/extract-table-value/ for additional examples.
final String[] columnNames = tableFromServer.getDefinition().getColumnNamesArray();
final Map<String, ? extends ColumnSource<?>> columnSources = tableFromServer.getColumnSourceMap();
final String[] columnNames = localTableRetrievedFromServer.getDefinition().getColumnNamesArray();
final Map<String, ? extends ColumnSource<?>> columnSources = localTableRetrievedFromServer.getColumnSourceMap();


System.out.println("Printing table using RowSet and ColumnSources:");
int rowIdx = 0;
for (RowSet.Iterator iterator = tableFromServer.getRowSet().iterator(); iterator.hasNext(); ) {
for (RowSet.Iterator iterator = localTableRetrievedFromServer.getRowSet().iterator(); iterator.hasNext(); ) {
// Iterate over the RowSet to get the "row keys". Row keys are used to access data in a ColumnSource.
final long nextRowKey = iterator.nextLong();
System.out.println("Data for row " + (rowIdx++) + ":");
Expand Down