Skip to content

Commit

Permalink
Add existing examples (#1)
Browse files Browse the repository at this point in the history
* Added cpp, go, python examples

* Updated Go steps in README
  • Loading branch information
SuperTails authored Jul 18, 2022
1 parent 38f9892 commit e91d35c
Show file tree
Hide file tree
Showing 7 changed files with 838 additions and 1 deletion.
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
# deephaven-client-examples
# Deephaven Client Examples

This collection of client examples performs (roughly) the same operations
in several different client languages to compare their interfaces.

The examples do not currently run, because some irrelevant code is omitted.
However, they do compile.

## Python

Ensure a recent version of the pydeephaven package is installed.

```sh
$ cd ./python
$ python3 main.py
```

## C++

First, build and install the C++ client packages according to `deephaven-core/cpp-client/README.md`.
Most of the build steps only need to be done once.
However, `CMAKE_PREFIX_PATH` must always be set appropriately when building the example.

Then, edit `./cpp/CMakeLists.txt` where indicated to set the correct path for the client library.

```sh
$ cd ./cpp
$ mkdir build && cd build
$ cmake ..
$ make
$ ./example
```

## Go

First, ensure you have the Go client present somewhere.
Since the Go client has not yet been officially released,
this requires checking out the `go-client-api` branch of
[this fork](https://github.com/SuperTails/deephaven-core).

Then, edit `./go/go.mod` where indicated to set the correct path for the client library.

```sh
$ cd ./go
$ go mod tidy
$ go build
$ ./go_client_example
```
19 changes: 19 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.16)
project(example)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CHANGE THIS TO THE APPROPRIATE DIRECTORY
add_subdirectory(/deephaven/deephaven-core/cpp-client/deephaven deephaven_dir)

find_package(Arrow REQUIRED)
find_package(ArrowFlight REQUIRED HINTS ${Arrow_DIR})
find_package(Protobuf REQUIRED)
find_package(gRPC REQUIRED)
find_package(Threads REQUIRED)

add_executable(example main.cpp)

target_link_libraries(example deephaven::client)
48 changes: 48 additions & 0 deletions cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <exception>
#include <iostream>
#include "deephaven/client/highlevel/client.h"

using namespace deephaven::client::highlevel;

int main() {
try {
const char *server = "localhost:10000";

auto client = Client::connect(server);

// TODO: Check about information related to field syncing or ListFields.

auto manager = client.getManager();

/*
Creation of handle1 omitted.
The C++ client does not have a direct equivalent of importTable,
and uses TableMaker or Arrow Flight instead.
*/
auto handle1 = TableHandle(/* omitted */);

auto handle2 = manager.emptyTable(10);

auto handle3 = handle2.where("a > 10 && b % 2 == 0");

auto handle4 = handle1.merge("a", { handle3 }); // Note that merge is a method on the table handle here.

auto combo_agg = aggCombo({
aggSum("foo = a", "bar = c"),
aggAvg("avgA = a", "avgB = b")
});
auto handle5 = handle4.by(combo_agg, { "g" });

/*
There is no equivalent of the snapshot method in the C++ client.
The C++ client only supports reading table data through Arrow Flight.
There is a convenience method to print the table data, though.
*/
std::cout << handle5.stream(true) << '\n';
} catch (const std::exception &e) {
std::cerr << "Caught exception: " << e.what() << '\n';
}

return 0;
}

36 changes: 36 additions & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module example.com/go_client_example

go 1.18

require (
github.com/apache/arrow/go/v8 v8.0.0
github.com/deephaven/deephaven-core/go-client v0.1.0-alpha.0
)

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/apache/thrift v0.15.0 // indirect
github.com/goccy/go-json v0.9.6 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v2.0.5+incompatible // indirect
github.com/klauspost/asmfmt v1.3.1 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect
github.com/pierrec/lz4/v4 v4.1.12 // indirect
github.com/zeebo/xxh3 v1.0.1 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/net v0.0.0-20220607020251-c690dde0001d // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/genproto v0.0.0-20220126215142-9970aeb2e350 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

// CHANGE /deephaven/deephaven-core/go-client TO THE APPROPRIATE DIRECTORY
replace github.com/deephaven/deephaven-core/go-client => /deephaven/deephaven-core/go-client
Loading

0 comments on commit e91d35c

Please sign in to comment.