diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Type/Value_Type_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Type/Value_Type_Helpers.enso index 8a71cbb5dbed2..9e922e95b301b 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Type/Value_Type_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data/Type/Value_Type_Helpers.enso @@ -112,7 +112,7 @@ type Operation_Type_Helpers > Example type_helpers.check_argument_type other Value_Type.expect_text <| operation - check_argument_type self value type_check action = + check_argument_type self value type_check ~action = typ = self.find_argument_type value if typ.is_nothing then action else related_column = if self.is_column value then value.name else Nothing diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/numeric/DoubleBooleanOp.java b/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/numeric/DoubleBooleanOp.java index 1728cb51a2252..33bb747d3c8a4 100644 --- a/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/numeric/DoubleBooleanOp.java +++ b/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/numeric/DoubleBooleanOp.java @@ -79,7 +79,7 @@ public BoolStorage runZip(DoubleStorage storage, Storage arg, MapOperationPro BitSet newMissing = new BitSet(); for (int i = 0; i < storage.size(); i++) { if (!storage.isNa(i) && i < v.size() && !v.isNa(i)) { - if (doDouble(storage.getItem(i), v.getItem(i))) { + if (doDouble(storage.getItem(i), v.getItemDouble(i))) { newVals.set(i); } } else { diff --git a/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/text/StringStringOp.java b/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/text/StringStringOp.java new file mode 100644 index 0000000000000..88b33f395bd16 --- /dev/null +++ b/std-bits/table/src/main/java/org/enso/table/data/column/operation/map/text/StringStringOp.java @@ -0,0 +1,58 @@ +package org.enso.table.data.column.operation.map.text; + +import org.enso.table.data.column.builder.object.StringBuilder; +import org.enso.table.data.column.operation.map.MapOperation; +import org.enso.table.data.column.operation.map.MapOperationProblemBuilder; +import org.enso.table.data.column.storage.SpecializedStorage; +import org.enso.table.data.column.storage.Storage; +import org.enso.table.data.column.storage.StringStorage; +import org.enso.table.error.UnexpectedTypeException; + +public abstract class StringStringOp extends MapOperation> { + public StringStringOp(String name) { + super(name); + } + + protected abstract String doString(String a, String b); + + @Override + public Storage runMap(SpecializedStorage storage, Object arg, MapOperationProblemBuilder problemBuilder) { + int size = storage.size(); + if (arg == null) { + StringBuilder builder = new StringBuilder(size); + builder.appendNulls(size); + return builder.seal(); + } else if (arg instanceof String argString) { + String[] newVals = new String[size]; + for (int i = 0; i < size; i++) { + if (storage.isNa(i)) { + newVals[i] = null; + } else { + newVals[i] = doString(storage.getItem(i), argString); + } + } + return new StringStorage(newVals, size); + } else { + throw new UnexpectedTypeException("a Text"); + } + } + + @Override + public Storage runZip(SpecializedStorage storage, Storage arg, + MapOperationProblemBuilder problemBuilder) { + if (arg instanceof StringStorage v) { + int size = storage.size(); + String[] newVals = new String[size]; + for (int i = 0; i < size; i++) { + if (storage.isNa(i) || v.isNa(i)) { + newVals[i] = null; + } else { + newVals[i] = doString(storage.getItem(i), v.getItem(i)); + } + } + return new StringStorage(newVals, size); + } else { + throw new UnexpectedTypeException("a Text column"); + } + } +} 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 131c2b211a1fb..0404dbef49dd4 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 @@ -72,7 +72,7 @@ public long getItem(int idx) { @Override public double getItemDouble(int idx) { - return getItem(idx); + return (double) getItem(idx); } @Override @@ -338,7 +338,7 @@ protected boolean doLong(long a, long b) { @Override protected boolean doDouble(long a, double b) { - return a > b; + return a < b; } }) .add( 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 5d83818d01f7e..7548ff2fda260 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 @@ -12,6 +12,7 @@ import org.enso.table.data.column.operation.map.text.LikeOp; import org.enso.table.data.column.operation.map.text.StringBooleanOp; import org.enso.table.data.column.operation.map.text.StringIsInOp; +import org.enso.table.data.column.operation.map.text.StringStringOp; import org.enso.table.data.column.storage.type.StorageType; import org.enso.table.data.column.storage.type.TextType; import org.graalvm.polyglot.Value; @@ -139,6 +140,12 @@ protected boolean doString(String a, String b) { }); t.add(new LikeOp()); t.add(new StringIsInOp<>()); + t.add(new StringStringOp(Maps.ADD) { + @Override + protected String doString(String a, String b) { + return a + b; + } + }); return t; } } diff --git a/test/Table_Tests/src/Common_Table_Operations/Column_Operations_Spec.enso b/test/Table_Tests/src/Common_Table_Operations/Column_Operations_Spec.enso index 14c45e4f3849e..a9055bfc66fab 100644 --- a/test/Table_Tests/src/Common_Table_Operations/Column_Operations_Spec.enso +++ b/test/Table_Tests/src/Common_Table_Operations/Column_Operations_Spec.enso @@ -43,7 +43,7 @@ spec setup = (x || Nothing).to_vector . should_equal nulls Test.specify "should check types" <| - t = table_builder [["X", [1, 2, 3], ["Y", ['a', 'b', 'c']]], ["Z", [True, False, Nothing]]] + t = table_builder [["X", [1, 2, 3]], ["Y", ['a', 'b', 'c']], ["Z", [True, False, Nothing]]] ((t.at "X") && (t.at "Z")) . to_vector . should_fail_with Invalid_Value_Type ((t.at "Z") && (t.at "X")) . to_vector . should_fail_with Invalid_Value_Type @@ -384,7 +384,7 @@ spec setup = str.contains 42 . to_vector . should_fail_with Invalid_Value_Type # Mixing text and integers should not be allowed - str + int . should_fail_with Illegal_Argument + (str + int) . should_fail_with Illegal_Argument Test.specify "should return right types" <| [Case_Sensitivity.Default, Case_Sensitivity.Sensitive, Case_Sensitivity.Insensitive].each cs->