diff --git a/std-bits/table/src/main/java/org/enso/table/aggregations/First.java b/std-bits/table/src/main/java/org/enso/table/aggregations/First.java index 8f027b22a5..621d8a91e7 100644 --- a/std-bits/table/src/main/java/org/enso/table/aggregations/First.java +++ b/std-bits/table/src/main/java/org/enso/table/aggregations/First.java @@ -27,7 +27,7 @@ public class First extends Aggregator { Column[] orderByColumns, Long[] orderByDirections, Comparator objectComparator) { - super(name, Storage.Type.OBJECT); + super(name, column.getStorage().getType()); this.storage = column.getStorage(); this.orderByColumns = orderByColumns == null diff --git a/std-bits/table/src/main/java/org/enso/table/aggregations/GroupBy.java b/std-bits/table/src/main/java/org/enso/table/aggregations/GroupBy.java index 0d613321f8..a9342d7766 100644 --- a/std-bits/table/src/main/java/org/enso/table/aggregations/GroupBy.java +++ b/std-bits/table/src/main/java/org/enso/table/aggregations/GroupBy.java @@ -10,7 +10,7 @@ public class GroupBy extends Aggregator { private final Storage storage; public GroupBy(String name, Column column) { - super(name, Storage.Type.OBJECT); + super(name, column.getStorage().getType()); storage = column.getStorage(); } diff --git a/std-bits/table/src/main/java/org/enso/table/aggregations/Last.java b/std-bits/table/src/main/java/org/enso/table/aggregations/Last.java index a5ecbc836b..129689ed26 100644 --- a/std-bits/table/src/main/java/org/enso/table/aggregations/Last.java +++ b/std-bits/table/src/main/java/org/enso/table/aggregations/Last.java @@ -26,7 +26,7 @@ public class Last extends Aggregator { Column[] orderByColumns, Long[] orderByDirections, Comparator objectComparator) { - super(name, Storage.Type.OBJECT); + super(name, column.getStorage().getType()); this.storage = column.getStorage(); this.orderByColumns = orderByColumns == null diff --git a/std-bits/table/src/main/java/org/enso/table/aggregations/MinOrMax.java b/std-bits/table/src/main/java/org/enso/table/aggregations/MinOrMax.java index 214385899a..761c7b8219 100644 --- a/std-bits/table/src/main/java/org/enso/table/aggregations/MinOrMax.java +++ b/std-bits/table/src/main/java/org/enso/table/aggregations/MinOrMax.java @@ -23,7 +23,7 @@ public class MinOrMax extends Aggregator { * @param minOrMax <0 for minimum, >0 for maximum */ public MinOrMax(String name, Column column, int minOrMax, Comparator objectComparator) { - super(name, Storage.Type.OBJECT); + super(name, column.getStorage().getType()); this.storage = column.getStorage(); this.minOrMax = Integer.signum(minOrMax); this.objectComparator = objectComparator; diff --git a/std-bits/table/src/main/java/org/enso/table/aggregations/Mode.java b/std-bits/table/src/main/java/org/enso/table/aggregations/Mode.java index b6bf656358..6414b567db 100644 --- a/std-bits/table/src/main/java/org/enso/table/aggregations/Mode.java +++ b/std-bits/table/src/main/java/org/enso/table/aggregations/Mode.java @@ -13,7 +13,7 @@ public class Mode extends Aggregator { private final Storage storage; public Mode(String name, Column column) { - super(name, Storage.Type.OBJECT); + super(name, column.getStorage().getType()); this.storage = column.getStorage(); } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java index 0095c9cb69..d56abba407 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/BoolStorage.java @@ -39,7 +39,7 @@ public class BoolStorage extends Storage { } @Override - public long getType() { + public int getType() { return Type.BOOL; } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateStorage.java index ab1a395425..2cd593be8a 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateStorage.java @@ -30,7 +30,7 @@ public class DateStorage extends SpecializedStorage { } @Override - public long getType() { + public int getType() { return Type.DATE; } } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateTimeStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateTimeStorage.java index 8d803dd50e..4dbd5e922a 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateTimeStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DateTimeStorage.java @@ -30,7 +30,7 @@ public class DateTimeStorage extends SpecializedStorage { } @Override - public long getType() { + public int getType() { return Type.DATE_TIME; } } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java index 491e218a08..e023dccee1 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/DoubleStorage.java @@ -63,7 +63,7 @@ public class DoubleStorage extends NumericStorage { /** @inheritDoc */ @Override - public long getType() { + public int getType() { return Type.DOUBLE; } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/LongStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/LongStorage.java index 4924fc14f9..bf6931fbdc 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/LongStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/LongStorage.java @@ -71,7 +71,7 @@ public class LongStorage extends NumericStorage { /** @inheritDoc */ @Override - public long getType() { + public int getType() { return Type.LONG; } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java index 65484e056a..e2102c7985 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/ObjectStorage.java @@ -26,7 +26,7 @@ public class ObjectStorage extends SpecializedStorage { } @Override - public long getType() { + public int getType() { return Type.OBJECT; } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/SpecializedStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/SpecializedStorage.java index 178d880d0d..b2a5f78c0d 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/SpecializedStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/SpecializedStorage.java @@ -15,7 +15,7 @@ public abstract class SpecializedStorage extends Storage { protected abstract T[] newUnderlyingArray(int size); @Override - public abstract long getType(); + public abstract int getType(); /** * @param data the underlying data diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/Storage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/Storage.java index aa35d7f29a..f606de1c69 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/Storage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/Storage.java @@ -24,7 +24,7 @@ public abstract class Storage { public abstract int countMissing(); /** @return the type tag of this column's storage. Must be one of {@link Type} */ - public abstract long getType(); + public abstract int getType(); /** * Checks whether the value at {@code idx} is missing. diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/StringStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/StringStorage.java index b01725b49c..f681846975 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/StringStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/StringStorage.java @@ -29,7 +29,7 @@ public class StringStorage extends SpecializedStorage { } @Override - public long getType() { + public int getType() { return Type.STRING; } diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/storage/TimeOfDayStorage.java b/std-bits/table/src/main/java/org/enso/table/data/column/storage/TimeOfDayStorage.java index 70dde526ce..36d4510645 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/storage/TimeOfDayStorage.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/storage/TimeOfDayStorage.java @@ -30,7 +30,7 @@ public class TimeOfDayStorage extends SpecializedStorage { } @Override - public long getType() { + public int getType() { return Type.TIME_OF_DAY; } } diff --git a/std-bits/table/src/main/java/org/enso/table/data/index/MultiValueIndex.java b/std-bits/table/src/main/java/org/enso/table/data/index/MultiValueIndex.java index ec9317f860..5de9c069a2 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/index/MultiValueIndex.java +++ b/std-bits/table/src/main/java/org/enso/table/data/index/MultiValueIndex.java @@ -102,11 +102,14 @@ public class MultiValueIndex { private static Builder getBuilderForType(int type, int size) { return switch (type) { - case Storage.Type.BOOL -> new BoolBuilder(); - case Storage.Type.DOUBLE -> NumericBuilder.createDoubleBuilder(size); - case Storage.Type.LONG -> NumericBuilder.createLongBuilder(size); - case Storage.Type.STRING -> new StringBuilder(size); case Storage.Type.OBJECT -> new ObjectBuilder(size); + case Storage.Type.LONG -> NumericBuilder.createLongBuilder(size); + case Storage.Type.DOUBLE -> NumericBuilder.createDoubleBuilder(size); + case Storage.Type.STRING -> new StringBuilder(size); + case Storage.Type.BOOL -> new BoolBuilder(); + case Storage.Type.DATE -> new DateBuilder(size); + case Storage.Type.TIME_OF_DAY -> new TimeOfDayBuilder(size); + case Storage.Type.DATE_TIME -> new DateTimeBuilder(size); default -> new InferredBuilder(size); }; } diff --git a/test/Table_Tests/src/Table_Spec.enso b/test/Table_Tests/src/Table_Spec.enso index 801275f192..210516f9da 100644 --- a/test/Table_Tests/src/Table_Spec.enso +++ b/test/Table_Tests/src/Table_Spec.enso @@ -5,6 +5,8 @@ from Standard.Table import Column, Sort_Column, Sort_Column_Selector from Standard.Table.Data.Table import Empty_Error from Standard.Table.Errors as Table_Errors import Invalid_Output_Column_Names_Data, Duplicate_Output_Column_Names_Data, No_Input_Columns_Selected, Missing_Input_Columns_Data import Standard.Table.Data.Storage +import Standard.Table.Data.Aggregate_Column +from Standard.Table.Data.Aggregate_Column import all hiding First, Last import Standard.Visualization @@ -617,4 +619,31 @@ spec = problems = [Duplicate_Output_Column_Names_Data ["A", "A", "A"]] Problems.test_problem_handling action problems tester + Test.group "[In-Memory] Table.aggregate" <| + Test.specify "should return columns with correct types" <| + dates = ["dates", [Date.new 1999, Date.new 2000, Date.new 2000, Date.new 2000]] + texts = ["texts", ["a", "bb", "a", "bb"]] + mixed = ["mixed", [1, "a", "a", 1]] + ints = ["ints", [0, 1, 1, 0]] + floats = ["floats", [0.1, 1.0, 2.0, 1.5]] + objects = ["objects", [My_Data 0 1, My_Data 0 1, My_Data 2 2, My_Data 2 2]] + table = Table.new [dates, texts, mixed, ints, floats, objects] + + t1 = table.aggregate [Group_By "dates", Shortest "texts", Aggregate_Column.First "texts", Aggregate_Column.First "objects", Aggregate_Column.First "ints", Aggregate_Column.Last "mixed"] + t1.info.at "Column" . to_vector . should_equal ["dates", "Shortest texts", "First texts", "First objects", "First ints", "Last mixed"] + t1.info.at "Storage Type" . to_vector . should_equal [Storage.Date, Storage.Text, Storage.Text, Storage.Any, Storage.Integer, Storage.Any] + + t2 = table.aggregate [Mode "dates", Count_Distinct "objects", Count_Distinct "texts", Minimum "ints", Maximum "floats"] + t2.info.at "Column" . to_vector . should_equal ["Mode dates", "Count Distinct objects", "Count Distinct texts", "Minimum ints", "Maximum floats"] + t2.info.at "Storage Type" . to_vector . should_equal [Storage.Date, Storage.Integer, Storage.Integer, Storage.Integer, Storage.Decimal] + + t3 = table.aggregate [Group_By "texts", Group_By "ints", Aggregate_Column.Last "floats"] + t3.info.at "Column" . to_vector . should_equal ["texts", "ints", "Last floats"] + t3.info.at "Storage Type" . to_vector . should_equal [Storage.Text, Storage.Integer, Storage.Decimal] + + t4 = table.aggregate [Group_By "mixed", Sum "ints", Sum "floats"] + t4.info.at "Column" . to_vector . should_equal ["mixed", "Sum ints", "Sum floats"] + t4.info.at "Storage Type" . to_vector . should_equal [Storage.Any, Storage.Decimal, Storage.Decimal] + + main = Test.Suite.run_main spec