Package com.illumon.iris.downsampling
Class Downsampler
java.lang.Object
com.illumon.iris.downsampling.Downsampler
public class Downsampler extends Object
A simple utility for downsampling time-series data.
This uses a "builder" style as opposed to a collection of overloads due to the large number of options.
By default, this runs in "online" mode and uses a ticking time table to update as new sample data arrives in the
underlying table. The default this uses upperBin for sampling. This can be overridden by setting timeBinMode.
The output is grouped by the specified timestamp and "key columns" and aggregates are specified with the
last/first/min/max etc methods.
Example of sampling trade data:
downsampledTrades = downsample(trades, "Timestamp", "00:05:00", "Sym")
.last("Price", "Size")
.sum("Volume=Size")
.execute()
Example of sampling quote data:
downsampledQuotes = downsample(quotes, "Timestamp", "00:05:00", "Sym")
.last("Bid", "BidSize", "Ask", "AskSize")
.maintainState("Bid", "BidSize", "Ask", "AskSize")
.execute()
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Downsampler.Builder
A class to supporting building a Downsampler in a fluent manner.static class
Downsampler.TimeBinMode
-
Method Summary
Modifier and Type Method Description static Downsampler.Builder
downsample(Database db, Table table, MatchPair timestampColumn, long periodValue, String... keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.static Downsampler.Builder
downsample(Database db, Table table, MatchPair timestampColumn, String period, String... keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.static Downsampler.Builder
downsample(Database db, Table table, MatchPair timestampColumn, String period, Collection<String> keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.static Downsampler.Builder
downsample(Database db, Table table, String timestampColumn, long periodValue, String... keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.static Downsampler.Builder
downsample(Database db, Table table, String timestampColumn, String period, String... keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.static Downsampler.Builder
downsample(Database db, Table table, String timestampColumn, String period, Collection<String> keyColumns)
Initialize a downsampler builder that will sample the given table at the given time period.
-
Method Details
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, MatchPair timestampColumn, long periodValue, String... keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiodValue
- Sampling period/frequency in nanosecondskeyColumns
- Columns by which to group the result- Returns:
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, MatchPair timestampColumn, String period, String... keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiod
- Sampling period/frequency in HH:mm:ss formatkeyColumns
- Columns by which to group the result- Returns:
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, MatchPair timestampColumn, String period, Collection<String> keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiod
- Sampling period/frequency in HH:mm:ss formatkeyColumns
- Columns by which to group the result- Returns:
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, String timestampColumn, long periodValue, String... keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiodValue
- Sampling period/frequency in nanosecondskeyColumns
- Columns by which to group the result- Returns:
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, String timestampColumn, String period, String... keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiod
- Sampling period/frequency in HH:mm:ss formatkeyColumns
- Columns by which to group the result- Returns:
-
downsample
public static Downsampler.Builder downsample(Database db, Table table, String timestampColumn, String period, Collection<String> keyColumns)Initialize a downsampler builder that will sample the given table at the given time period. The sampling will use time bins based on the given timestamp column and grouped by the given keys.- Parameters:
db
- Database that will be used to generate time tabletable
- Raw data to tabletimestampColumn
- Column from which to generate time binsperiod
- Sampling period/frequency in HH:mm:ss formatkeyColumns
- Columns by which to group the result- Returns:
-