Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add storage support for Date, Time and DateTime to InMemory table #3673

Merged
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
- [Removed `Array.set_at`.][3634]
- [Added various date part functions to `Date` and `Date_Time`.][3669]
- [Implemented `Table.take` and `Table.drop` for the in-memory backend.][3647]
- [Implemented specialized storage for the in-memory Table.][3673]

[debug-shortcuts]:
https://github.com/enso-org/enso/blob/develop/app/gui/docs/product/shortcuts.md#debug
Expand Down Expand Up @@ -299,6 +300,7 @@
[3634]: https://github.com/enso-org/enso/pull/3634
[3669]: https://github.com/enso-org/enso/pull/3669
[3647]: https://github.com/enso-org/enso/pull/3647
[3673]: https://github.com/enso-org/enso/pull/3673

#### Enso Compiler

Expand Down
40 changes: 16 additions & 24 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,8 @@ type Column
storage_type : Storage.Type
storage_type self =
tp = self.java_column.getStorage.getType
if tp == storage_type_string then Storage.Text else
if tp == storage_type_long then Storage.Integer else
if tp == storage_type_double then Storage.Decimal else
if tp == storage_type_bool then Storage.Boolean else
Storage.Any
storage_types.at tp . catch Index_Out_Of_Bounds_Error _->
Panic.throw (Illegal_State_Error "Unknown storage type: "+tp.to_text)

## UNSTABLE

Expand Down Expand Up @@ -1327,29 +1324,19 @@ run_vectorized_unary_op column name fallback_fn =
Column_Data (Java_Column.new "Result" ix rs)

## PRIVATE

Keep this in sync with `org.enso.table.data.Storage.Type.LONG`
storage_type_long : Integer
storage_type_long = 1

## PRIVATE

Keep this in sync with `org.enso.table.data.Storage.Type.DOUBLE`
storage_type_double : Integer
storage_type_double = 2
Enumerates storage types in a way that is consistent with
`org.enso.table.data.Storage.Type`, i.e.
`storage_type.at org.enso.table.data.Storage.Type.LONG` will yield the
corresponding `Storage.Integer`.
storage_types : Vector Storage.Type
storage_types = [Storage.Any, Storage.Integer, Storage.Decimal, Storage.Text, Storage.Boolean, Storage.Date, Storage.Time_Of_Day, Storage.Date_Time]

## PRIVATE

Keep this in sync with `org.enso.table.data.Storage.Type.STRING`
storage_type_string : Integer
radeusgd marked this conversation as resolved.
Show resolved Hide resolved
storage_type_string = 3

## PRIVATE

Keep this in sync with `org.enso.table.data.Storage.Type.BOOL`
storage_type_bool : Integer
storage_type_bool = 4

## PRIVATE

A helper function for converting a column storage to JSON.
Expand All @@ -1372,9 +1359,14 @@ storage_to_json storage factory =
- ix: The index in the column from which to get the item.
get_item_string : Column -> Integer -> Text
get_item_string column ix =
tp = column.getType
if tp == storage_type_string then column.getItem ix else
column.getItem ix . to_text
item = column.getItem ix
## TODO This special handling of `Text` is because `"a".to_text` evaluates
to "'a'" and not just "a". The code can be simplified once the following
task is implemented:
https://www.pivotaltracker.com/story/show/181499256
case item of
Text -> item
_ -> item.to_text

## PRIVATE
A helper to create a new table consisting of slices of the original table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ polyglot java import org.enso.table.parsing.IntegerParser
polyglot java import org.enso.table.parsing.DecimalParser
polyglot java import org.enso.table.parsing.BooleanParser
polyglot java import org.enso.table.parsing.DateParser
polyglot java import org.enso.table.parsing.TimeParser
polyglot java import org.enso.table.parsing.TimeOfDayParser
polyglot java import org.enso.table.parsing.DateTimeParser
polyglot java import org.enso.table.parsing.WhitespaceStrippingParser
polyglot java import org.enso.table.parsing.IdentityParser
Expand Down Expand Up @@ -156,12 +156,12 @@ type Data_Formatter
DateParser.new self.date_formats.to_array self.datetime_locale.java_locale

## PRIVATE
make_datetime_parser self = self.wrap_base_parser <|
make_date_time_parser self = self.wrap_base_parser <|
DateTimeParser.new self.datetime_formats.to_array self.datetime_locale.java_locale

## PRIVATE
make_time_parser self = self.wrap_base_parser <|
TimeParser.new self.time_formats.to_array self.datetime_locale.java_locale
make_time_of_day_parser self = self.wrap_base_parser <|
TimeOfDayParser.new self.time_formats.to_array self.datetime_locale.java_locale

## PRIVATE
make_identity_parser self = self.wrap_base_parser IdentityParser.new
Expand All @@ -172,13 +172,13 @@ type Data_Formatter
Decimal -> self.make_decimal_parser
Boolean -> self.make_boolean_parser
Date -> self.make_date_parser
Date_Time -> self.make_datetime_parser
Time_Of_Day -> self.make_time_parser
Date_Time -> self.make_date_time_parser
Time_Of_Day -> self.make_time_of_day_parser
_ -> Error.throw (Illegal_Argument_Error_Data "Unsupported datatype: "+datatype.to_text)

## PRIVATE
get_specific_type_parsers self =
[self.make_integer_parser, self.make_decimal_parser, self.make_datetime_parser, self.make_date_parser, self.make_time_parser, self.make_boolean_parser]
[self.make_integer_parser, self.make_decimal_parser, self.make_date_time_parser, self.make_date_parser, self.make_time_of_day_parser, self.make_boolean_parser]

## PRIVATE
make_auto_parser self =
Expand All @@ -199,12 +199,12 @@ type Data_Formatter
DateFormatter.new self.date_formats.first self.datetime_locale.java_locale

## PRIVATE
make_time_formatter self =
make_time_of_day_formatter self =
if self.time_formats.is_empty then Error.throw (Illegal_Argument_Error_Data "Formatting times requires at least one entry in the `time_formats` parameter") else
TimeFormatter.new self.time_formats.first self.datetime_locale.java_locale

## PRIVATE
make_datetime_formatter self =
make_date_time_formatter self =
if self.datetime_formats.is_empty then Error.throw (Illegal_Argument_Error_Data "Formatting date-times requires at least one entry in the `datetime_formats` parameter") else
DateTimeFormatter.new self.datetime_formats.first self.datetime_locale.java_locale

Expand All @@ -220,7 +220,7 @@ type Data_Formatter

## PRIVATE
get_specific_type_formatters self =
[self.make_integer_formatter, self.make_decimal_formatter, self.make_boolean_formatter, self.make_datetime_formatter, self.make_date_formatter, self.make_time_formatter, self.make_text_formatter]
[self.make_integer_formatter, self.make_decimal_formatter, self.make_boolean_formatter, self.make_date_time_formatter, self.make_date_formatter, self.make_time_of_day_formatter, self.make_text_formatter]

## PRIVATE
make_auto_formatter self =
Expand All @@ -234,4 +234,7 @@ type Data_Formatter
Storage.Integer -> self.make_integer_formatter
Storage.Decimal -> self.make_decimal_formatter
Storage.Boolean -> self.make_boolean_formatter
Storage.Date -> self.make_date_formatter
Storage.Time_Of_Day -> self.make_time_of_day_formatter
Storage.Date_Time -> self.make_date_time_formatter
Storage.Any -> self.make_auto_formatter
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ type Type
## A column storing boolean data.
Boolean

## A column storing dates.
Date

## A column storing date-times.
Date_Time

## A column storing time-of-day.
Time_Of_Day

## A column storing arbitrary data.
Any
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,8 @@ run_spec ~behavior =
case ex of
Failure _ -> ex
Finished_With_Error_Data err stack_trace_text ->
Failure ("An unexpected error was returned: " + err.to_display_text + '\n' + stack_trace_text)
_ -> Failure ("An unexpected panic was thrown: " + ex.to_display_text + '\n' + maybeExc.get_stack_trace_text)
Failure ("An unexpected error was returned: " + err.to_text + '\n' + stack_trace_text)
_ -> Failure ("An unexpected panic was thrown: " + ex.to_text + '\n' + maybeExc.get_stack_trace_text)
result

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.enso.table.data.column.builder.object;

import java.util.BitSet;
import org.enso.table.data.column.storage.BoolStorage;
import org.enso.table.data.column.storage.Storage;

import java.util.BitSet;

/** A builder for boolean columns. */
public class BoolBuilder extends TypedBuilder {
private final BitSet vals;
Expand Down Expand Up @@ -32,6 +33,11 @@ public void appendNoGrow(Object o) {
size++;
}

@Override
public boolean accepts(Object o) {
return o instanceof Boolean;
}

@Override
public void append(Object o) {
appendNoGrow(o);
Expand Down Expand Up @@ -65,11 +71,6 @@ public int getCurrentSize() {
return size;
}

@Override
public int getCurrentCapacity() {
return vals.size();
}

@Override
public void writeTo(Object[] items) {
for (int i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ public abstract class Builder {
/** @return the number of appended elements */
public abstract int getCurrentSize();

/**
* @return how many elements this builder can hold without growing (including already existing
* elements)
*/
public abstract int getCurrentCapacity();

/** @return a storage containing all the items appended so far */
public abstract Storage seal();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.enso.table.data.column.builder.object;

import org.enso.table.data.column.storage.DateStorage;
import org.enso.table.data.column.storage.Storage;

import java.time.LocalDate;

/** A builder for string columns. */
public class DateBuilder extends TypedBuilderImpl<LocalDate> {
@Override
protected LocalDate[] newArray(int size) {
return new LocalDate[size];
}

public DateBuilder(int size) {
super(size);
}

@Override
public int getType() {
return Storage.Type.DATE;
}

@Override
public void appendNoGrow(Object o) {
data[currentSize++] = (LocalDate) o;
}

@Override
public boolean accepts(Object o) {
return o instanceof LocalDate;
}

@Override
public Storage seal() {
return new DateStorage(data, currentSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.enso.table.data.column.builder.object;

import org.enso.table.data.column.storage.DateTimeStorage;
import org.enso.table.data.column.storage.Storage;

import java.time.ZonedDateTime;

/** A builder for string columns. */
public class DateTimeBuilder extends TypedBuilderImpl<ZonedDateTime> {
@Override
protected ZonedDateTime[] newArray(int size) {
return new ZonedDateTime[size];
}

public DateTimeBuilder(int size) {
super(size);
}

@Override
public int getType() {
return Storage.Type.DATE_TIME;
}

@Override
public void appendNoGrow(Object o) {
data[currentSize++] = (ZonedDateTime) o;
}

@Override
public boolean accepts(Object o) {
return o instanceof ZonedDateTime;
}

@Override
public Storage seal() {
return new DateTimeStorage(data, currentSize);
}
}
Loading