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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- Boolean column flags (`flag`, `!flag`) are no longer supported. Use `flag == true` / `flag == false`.
- A query that is a single word is parsed as full-text search, which is not supported by DataFrame, and raises a `PredicateCompilerException`.
- Decimal numbers with a comma (`1,5`) are no longer supported because `,` separates the values of `in (..)` lists. Use `1.5`.
- CSV columns without a declared type are now also checked for ISO-8601 date and time values (`LocalDate`, `LocalTime`, `LocalDateTime`,
`Instant`, `OffsetDateTime`) after `Boolean`, `Integer`, `Long` and `Double`. Columns that used to be loaded as `String` columns
(e.g. `2020-03-01` or `13:45`) now get a temporal column type. Declare the column as `String` with `setColumnType(name, String.class)`
to keep the old behaviour.
- `csv.ColumnSettings` was renamed to `csv.CSVColumnSettings` to avoid a name clash with `settings.ColumnSettings`.

### Added
- Temporal column types: `LocalDateColumn`, `LocalTimeColumn`, `LocalDateTimeColumn`, `InstantColumn`, `OffsetDateTimeColumn` and
`ZonedDateTimeColumn` with matching value types, `add...Column` / `get...Column` methods in `DataFrame` and `DataFrameBuilder`,
binary and CSV support and ISO-8601 auto-detection.
- Per-column settings (`dev.gruen.dataframe.settings`): `ColumnSettings`, `DataFrameSettings`, `ColumnMatchers` and the settings
`TemporalFormatSetting` (pattern and locale), `TimeZoneSetting` and `EncodingSetting` (charset of `StringType`).
Settings are passed with `withSettings(DataFrameSettings)` of `CSVReaderBuilder` and are kept when columns are copied.
- Filter queries support `in (1, 2)`, `!in (1, 2)` and `*=` (contains) operators.

## [0.8.0]
Expand Down
80 changes: 39 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,48 +72,10 @@ sources and javadoc jars, signs the artifacts with GPG and uploads them using th
The GitHub Actions workflow `release.yml` runs this for tags named `v*` and needs the secrets
`CENTRAL_USERNAME`, `CENTRAL_PASSWORD`, `GPG_PRIVATE_KEY` and `GPG_PASSPHRASE`.

Version 0.8.1
Changelog
-----
- use [query-compiler](https://github.com/nRo/query-compiler) library

Version 0.8.0
-----
See [CHANGELOG.md](CHANGELOG.md) for the complete list of changes.

- **Java 21 or newer is required**
- **UTF-8 is the default charset**
- **groupId and package changed to dev.gruen**

### Migration from 0.7
| Change | What to do |
|---|---|
| The Maven `groupId` changed from `de.unknownreality` to `dev.gruen`, and the Java packages changed from `de.unknownreality.dataframe` to `dev.gruen.dataframe` | Change the `groupId` in your dependency declaration and replace `de.unknownreality.dataframe` with `dev.gruen.dataframe` in your imports. Older releases stay available under the old `groupId`. Old meta files are remapped automatically. |
| Java 21 is required | Update your JDK and the `maven.compiler.release` of your project. |

Version 0.7.5
-----
- **direct value access for DataRow object.**

DataRows now directly access the respective values from the columns.
This improves runtime and memory footprint for most DataFrame operations.
DataRow objects are invalidated once the source DataFrame is changed.
Accessing an invalidated row results in an exception
- Row collections are now return as DataRows object.
DataRows can be converted to a new DataFrame
- improved 'groupBy' method


Version 0.7
-----
- The read and write functions have been rewritten from scratch for this version.
Some existing methods have been removed.

- Data grouping has been refactored and aggregation functions can now be applied to data groupings.
In general, data groupings can now be used like normal DataFrames.

- Java 8 is now required.

- Empty DataFrame instances are now created using DataFrame.create()
See [CHANGELOG.md](CHANGELOG.md) for the list of changes and breaking changes of each version
(including the migration from 0.7 to 0.8: new `groupId` and package `dev.gruen`, Java 21, UTF-8 default).

Examples
-----
Expand Down Expand Up @@ -462,3 +424,39 @@ DataFrame visitors = users.joinLeft(visits,"person_id");
DataFrame userOrders = users.joinInner(orders,new JoinColumn("person_id","customer_id"));
```

Date and time values are stored in typed columns. The following columns are available:

| Column | Value type | Default (ISO-8601) format |
|---|---|---|
| `LocalDateColumn` | `java.time.LocalDate` | `2020-03-01` |
| `LocalTimeColumn` | `java.time.LocalTime` | `13:45:10` |
| `LocalDateTimeColumn` | `java.time.LocalDateTime` | `2020-03-01T13:45:10` |
| `InstantColumn` | `java.time.Instant` | `2020-03-01T13:45:10Z` |
| `OffsetDateTimeColumn` | `java.time.OffsetDateTime` | `2020-03-01T13:45:10+02:00` |
| `ZonedDateTimeColumn` | `java.time.ZonedDateTime` | `2020-03-01T13:45:10+01:00[Europe/Berlin]` |

Columns are added with `addLocalDateColumn(name)` (and the matching methods for the other types) and read with
`getLocalDateColumn(name)`. Sorting, grouping, joining, printing and filtering (`created > '2020-01-01'`) work like for
all other column types. Values are written to CSV and printed with the format of their column.

**Auto-detection.** If a CSV column is not declared with a type, ISO-8601 values are detected in this order:
`LocalDate`, `LocalTime`, `LocalDateTime`, `Instant` (text ending with `Z`), `OffsetDateTime` (other offsets).
`ZonedDateTime` columns are not detected automatically; declare them with `setColumnType(name, ZonedDateTime.class)`.
A column stays a `String` column if one of the sampled values can not be parsed. If a column has a format setting,
the temporal types are checked first, using that format.

**Settings per column.** The format and the time zone of a column are configured with column settings. Settings are
assigned to columns with matchers (`byName`, `byIndex`, `byValueType`, `byColumnType`, `any`, `all`, `not`).
If a column has a format setting, the format is used for detection, parsing and writing.

```java
DataFrameSettings settings = DataFrameSettings.builder()
.add(new TemporalFormatSetting("dd.MM.yyyy HH:mm"), ColumnMatchers.byName("created"))
.add(new TimeZoneSetting(ZoneId.of("Europe/Berlin")), ColumnMatchers.byColumnType(InstantColumn.class))
.build();
DataFrame df = DataFrame.load(file, CSVReaderBuilder.create().withSettings(settings).build());
```

A `TimeZoneSetting` supplies the zone for text without zone information (`Instant`, `OffsetDateTime` and
`ZonedDateTime` columns). The default zone is UTC. Settings can also be changed on an existing column with
`column.getSettings().add(...)`.
102 changes: 102 additions & 0 deletions src/main/java/dev/gruen/dataframe/DataFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,54 @@ public interface DataFrame extends DataContainer<DataFrameHeader, DataRow> {
*/
DataFrame addByteColumn(String name);

/**
* Adds a new {@link LocalDateColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addLocalDateColumn(String name);

/**
* Adds a new {@link LocalTimeColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addLocalTimeColumn(String name);

/**
* Adds a new {@link LocalDateTimeColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addLocalDateTimeColumn(String name);

/**
* Adds a new {@link InstantColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addInstantColumn(String name);

/**
* Adds a new {@link OffsetDateTimeColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addOffsetDateTimeColumn(String name);

/**
* Adds a new {@link ZonedDateTimeColumn} to the dataframe.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
DataFrame addZonedDateTimeColumn(String name);

/**
* Adds a new {@link DoubleColumn} to the dataframe.
*
Expand Down Expand Up @@ -763,6 +811,60 @@ public interface DataFrame extends DataContainer<DataFrameHeader, DataRow> {
*/
ByteColumn getByteColumn(String name);

/**
* Returns a {@link LocalDateColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
LocalDateColumn getLocalDateColumn(String name);

/**
* Returns a {@link LocalTimeColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
LocalTimeColumn getLocalTimeColumn(String name);

/**
* Returns a {@link LocalDateTimeColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
LocalDateTimeColumn getLocalDateTimeColumn(String name);

/**
* Returns an {@link InstantColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
InstantColumn getInstantColumn(String name);

/**
* Returns an {@link OffsetDateTimeColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
OffsetDateTimeColumn getOffsetDateTimeColumn(String name);

/**
* Returns a {@link ZonedDateTimeColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
*
* @param name name of the column
* @return found column
*/
ZonedDateTimeColumn getZonedDateTimeColumn(String name);

/**
* Returns a {@link LongColumn}
* If the column is not found or has the wrong type a {@link DataFrameRuntimeException} is thrown.
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/dev/gruen/dataframe/DataFrameBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,66 @@ public DataFrameBuilder addByteColumn(String name) {
return addColumn(column);
}

/**
* Adds a new {@link LocalDateColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addLocalDateColumn(String name) {
return addColumn(new LocalDateColumn(name));
}

/**
* Adds a new {@link LocalTimeColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addLocalTimeColumn(String name) {
return addColumn(new LocalTimeColumn(name));
}

/**
* Adds a new {@link LocalDateTimeColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addLocalDateTimeColumn(String name) {
return addColumn(new LocalDateTimeColumn(name));
}

/**
* Adds a new {@link InstantColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addInstantColumn(String name) {
return addColumn(new InstantColumn(name));
}

/**
* Adds a new {@link OffsetDateTimeColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addOffsetDateTimeColumn(String name) {
return addColumn(new OffsetDateTimeColumn(name));
}

/**
* Adds a new {@link ZonedDateTimeColumn} to the builder.
*
* @param name name of the column
* @return <code>self</code> for method chaining
*/
public DataFrameBuilder addZonedDateTimeColumn(String name) {
return addColumn(new ZonedDateTimeColumn(name));
}

/**
* Adds a new {@link DoubleColumn} to the builder.
*
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/dev/gruen/dataframe/DataFrameColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package dev.gruen.dataframe;

import dev.gruen.dataframe.common.Row;
import dev.gruen.dataframe.settings.ColumnSettings;
import dev.gruen.dataframe.transform.ColumnDataFrameTransform;
import dev.gruen.dataframe.transform.ColumnTransform;
import dev.gruen.dataframe.type.ValueType;
Expand All @@ -44,6 +45,8 @@ public abstract class DataFrameColumn<T, C extends DataFrameColumn<T, C>> implem
private String name;
private DefaultDataFrame dataFrame;
private boolean dataFrameAppend = false;
private final ColumnSettings settings = new ColumnSettings();
private int columnIndex = -1;


/**
Expand All @@ -65,6 +68,39 @@ public abstract class DataFrameColumn<T, C extends DataFrameColumn<T, C>> implem

public abstract ValueType<T> getValueType();

/**
* Returns the settings of this column.
* Value types of this column read their configuration from these settings.
*
* @return column settings
*/
public ColumnSettings getSettings() {
return settings;
}

/**
* Returns the index of this column in its data frame.
* If the column is not part of a data frame, the index assigned with
* {@link #setColumnIndex(int)} is returned (<code>-1</code> if no index was assigned).
*
* @return column index
*/
public int getColumnIndex() {
if (dataFrame != null) {
return dataFrame.getHeader().getIndex(name);
}
return columnIndex;
}

/**
* Sets the index of this column while it is not part of a data frame.
*
* @param columnIndex column index
*/
public void setColumnIndex(int columnIndex) {
this.columnIndex = columnIndex;
}

/**
* Used to apply transformations on a column
*
Expand Down
Loading
Loading