|
| 1 | +--- |
| 2 | +title: Analyze data via Open Source Server |
| 3 | +order: 4 |
| 4 | +--- |
| 5 | + |
| 6 | +The Rerun Cloud offering builds on the open source core. |
| 7 | +Towards that end the Open Source Server provides the capability for small scale local analysis using a similar API surface. |
| 8 | +This supports a workflow to develop or debug locally on a single recording then scale up that same workflow on the cloud for production use. |
| 9 | + |
| 10 | +<!-- TODO(RR-2818) add link to doc --> |
| 11 | + |
| 12 | +# Open source server |
| 13 | + |
| 14 | +## Launching the server |
| 15 | + |
| 16 | +The server needs to be opened in a separate window. |
| 17 | +Launch the server using the rerun cli. |
| 18 | + |
| 19 | +```console |
| 20 | +rerun server |
| 21 | +``` |
| 22 | + |
| 23 | +For full details run |
| 24 | + |
| 25 | +```console |
| 26 | +rerun server --help |
| 27 | +``` |
| 28 | + |
| 29 | +with the most common utility opening a directory of rrds as a dataset in the server |
| 30 | + |
| 31 | +```console |
| 32 | +rerun server -d <directory_containing_rrds> |
| 33 | +``` |
| 34 | + |
| 35 | +## Connecting to the server |
| 36 | + |
| 37 | +When launching the server the cli will print out the host and port it is listening on |
| 38 | +(defaulting to: `localhost:51234`). |
| 39 | + |
| 40 | +### From the viewer |
| 41 | + |
| 42 | +Either specify the network location with the cli at launch |
| 43 | + |
| 44 | +```console |
| 45 | +rerun connect localhost:51234 |
| 46 | +``` |
| 47 | + |
| 48 | +or after the viewer opens open the command palette select `open redap server` |
| 49 | +set the scheme to `http` and enter the hostname and port. |
| 50 | + |
| 51 | +### From the SDK |
| 52 | + |
| 53 | +```python |
| 54 | +import rerun as rr |
| 55 | +CATALOG_URL = "rerun+http://localhost:51234" |
| 56 | +client = rr.catalog.CatalogClient(CATALOG_URL) |
| 57 | +``` |
| 58 | + |
| 59 | +## Querying the server |
| 60 | + |
| 61 | +Everything below assumes that the server has been launched and a client has been constructed based on instructions above. |
| 62 | + |
| 63 | +### Datasets overview |
| 64 | + |
| 65 | +A dataset is a collection of recordings that can be queried against. |
| 66 | +If we have already created a dataset we can retrieve it, |
| 67 | + |
| 68 | +```python |
| 69 | +dataset = client.get_dataset_entry(name="oss_demo") |
| 70 | +``` |
| 71 | + |
| 72 | +otherwise we can create it. |
| 73 | + |
| 74 | +```python |
| 75 | +dataset = client.create_dataset( |
| 76 | + name="oss_demo", |
| 77 | +) |
| 78 | +``` |
| 79 | + |
| 80 | +In order to add additional recordings to a dataset we use the `register` api. |
| 81 | + |
| 82 | +```python |
| 83 | +# For OSS server you must register files local to your machine |
| 84 | +# To synchronously register a single recording |
| 85 | +dataset.register(f"file://{os.path.abspath('oss_demo.rrd')}") |
| 86 | +# To asynchronously register many recordings |
| 87 | +timeout_seconds = 100 |
| 88 | +tasks = dataset.register_batch([f"file://{os.path.abspath('oss_demo.rrd')}"]) |
| 89 | +tasks.wait(100) |
| 90 | +``` |
| 91 | + |
| 92 | +### Inspecting datasets |
| 93 | + |
| 94 | +Ultimately, we will end up rendering the data as a [DataFusion DataFrame](https://datafusion.apache.org/python/user-guide/dataframe/index.html) |
| 95 | +However, there is an intermediate step that allows for some optimization. |
| 96 | +This generates a `DataFrameQueryView`. <!-- TODO(nick) add link to doc --> |
| 97 | +The `DataFrameQueryView` allows selection of the subset of interest for the dataset (index column, and content columns), filtering to specific time ranges, and managing the sparsity of the data (`fill_latest_at`). |
| 98 | +All of these operations occur on the server prior to evaluating future queries so avoid unnecessary computation. |
| 99 | + |
| 100 | +```python |
| 101 | +view = ( |
| 102 | + dataset |
| 103 | + .dataframe_query_view(index="log_time", contents="/**") |
| 104 | + # Select only a single or subset of recordings |
| 105 | + .filter_partition_id(record_of_interest) |
| 106 | + # Select subset of time range |
| 107 | + .filter_range_nanos(start=start_of_interest, end=end_of_interest) |
| 108 | + # Forward fill for time alignment |
| 109 | + .fill_latest_at() |
| 110 | +) |
| 111 | +``` |
| 112 | + |
| 113 | +After we have identified what data we want we can get a DataFrame. |
| 114 | + |
| 115 | +```python |
| 116 | +df = view.df() |
| 117 | +``` |
| 118 | + |
| 119 | +[DataFusion](https://datafusion.apache.org/python/) provides a pythonic dataframe interface to your data as well as [SQL](https://datafusion.apache.org/python/user-guide/sql.html). |
| 120 | +After performing a series of operations this dataframe can be materialized and returned in common data formats. |
| 121 | + |
| 122 | +```python |
| 123 | +pandas_df = df.to_pandas() |
| 124 | +polars_df = df.to_polars() |
| 125 | +arrow_table = df.to_arrow_table() |
| 126 | +``` |
0 commit comments