3
3
import java .time .LocalDate ;
4
4
import java .time .LocalTime ;
5
5
import java .time .ZonedDateTime ;
6
- import java .time .temporal .Temporal ;
7
6
import java .util .function .BiFunction ;
7
+ import org .enso .base .Text_Utils ;
8
+ import org .enso .table .data .column .builder .Builder ;
9
+ import org .enso .table .data .column .builder .BuilderForType ;
8
10
import org .enso .table .data .column .operation .map .MapOperationProblemAggregator ;
9
11
import org .enso .table .data .column .storage .ColumnStorage ;
10
12
import org .enso .table .data .column .storage .Storage ;
11
13
import org .enso .table .data .column .storage .type .DateTimeType ;
12
14
import org .enso .table .data .column .storage .type .DateType ;
13
15
import org .enso .table .data .column .storage .type .NullType ;
16
+ import org .enso .table .data .column .storage .type .NumericType ;
14
17
import org .enso .table .data .column .storage .type .StorageType ;
18
+ import org .enso .table .data .column .storage .type .TextType ;
15
19
import org .enso .table .data .column .storage .type .TimeOfDayType ;
16
20
import org .enso .table .data .table .Column ;
17
21
import org .enso .table .error .UnexpectedTypeException ;
18
22
import org .enso .table .problems .BlackholeProblemAggregator ;
23
+ import org .graalvm .polyglot .Value ;
19
24
20
25
public class BinaryCoalescingOperation <T > implements BinaryOperation <T > {
21
26
private static Column applyOperation (
@@ -25,9 +30,8 @@ private static Column applyOperation(
25
30
StorageType <?> fallbackType ,
26
31
String name ,
27
32
MapOperationProblemAggregator problemBuilder ,
28
- BinaryOperation <? extends Temporal > operation ,
29
- Storage <?> leftStorage ,
30
- String fallbackName ) {
33
+ BinaryOperation <?> operation ,
34
+ Storage <?> leftStorage ) {
31
35
if (right instanceof Column rightColumn ) {
32
36
if (operation != null ) {
33
37
var rightStorage = rightColumn .getStorage ();
@@ -37,14 +41,14 @@ private static Column applyOperation(
37
41
}
38
42
return operation .apply (left , rightColumn , name );
39
43
} else {
44
+ // Null on left-hand side so just return the right-hand Column
45
+ if (leftStorage .getType () instanceof NullType ) {
46
+ return new Column (name , rightColumn .getStorage ());
47
+ }
48
+
40
49
var result =
41
- leftStorage .vectorizedOrFallbackZip (
42
- fallbackName ,
43
- problemBuilder ,
44
- fallback ,
45
- rightColumn .getStorage (),
46
- false ,
47
- fallbackType );
50
+ leftStorage .zip (
51
+ fallback , rightColumn .getStorage (), false , leftStorage .getType (), problemBuilder );
48
52
return new Column (name , result );
49
53
}
50
54
}
@@ -55,9 +59,15 @@ private static Column applyOperation(
55
59
}
56
60
return operation .apply (left , right , name );
57
61
} else {
58
- var result =
59
- leftStorage .vectorizedOrFallbackBinaryMap (
60
- fallbackName , problemBuilder , fallback , right , false , leftStorage .getType ());
62
+ // Null on left-hand side so just return the right-hand Column
63
+ if (leftStorage .getType () instanceof NullType ) {
64
+ int checkedSize = Builder .checkSize (leftStorage .getSize ());
65
+ var constantStorage =
66
+ Storage .fromRepeatedItem (Value .asValue (right ), checkedSize , problemBuilder );
67
+ return new Column (name , constantStorage );
68
+ }
69
+
70
+ var result = leftStorage .binaryMap (fallback , right , false , fallbackType , problemBuilder );
61
71
return new Column (name , result );
62
72
}
63
73
}
@@ -68,6 +78,16 @@ private static Column applyOperation(
68
78
new BinaryCoalescingOperation <>(DateTimeType .INSTANCE , (a , b ) -> a .isBefore (b ) ? a : b );
69
79
private static final BinaryOperation <LocalTime > TIME_MIN =
70
80
new BinaryCoalescingOperation <>(TimeOfDayType .INSTANCE , (a , b ) -> a .isBefore (b ) ? a : b );
81
+ private static final BinaryOperation <String > TEXT_MIN =
82
+ new BinaryCoalescingOperation <>(
83
+ TextType .VARIABLE_LENGTH , (a , b ) -> Text_Utils .compare_normalized (a , b ) < 0 ? a : b ) {
84
+ @ Override
85
+ protected BuilderForType <String > makeStorageBuilder (
86
+ long size , StorageType <?> leftType , StorageType <?> rightType ) {
87
+ return TextType .maxType (leftType , rightType )
88
+ .makeBuilder (size , BlackholeProblemAggregator .INSTANCE );
89
+ }
90
+ };
71
91
72
92
public static Column min (
73
93
Column left ,
@@ -82,10 +102,13 @@ public static Column min(
82
102
case DateType d -> DATE_MIN ;
83
103
case DateTimeType dt -> DATE_TIME_MIN ;
84
104
case TimeOfDayType t -> TIME_MIN ;
105
+ case TextType t -> TEXT_MIN ;
106
+ case NumericType n -> BinaryCoalescingOperationNumeric .create (
107
+ leftStorage .getType (), right , BinaryCoalescingOperationNumeric .MIN_OPERATION );
85
108
default -> null ;
86
109
};
87
110
return applyOperation (
88
- left , right , fallback , fallbackType , name , problemBuilder , operation , leftStorage , "min" );
111
+ left , right , fallback , fallbackType , name , problemBuilder , operation , leftStorage );
89
112
}
90
113
91
114
private static final BinaryOperation <LocalDate > DATE_MAX =
@@ -94,6 +117,16 @@ public static Column min(
94
117
new BinaryCoalescingOperation <>(DateTimeType .INSTANCE , (a , b ) -> a .isAfter (b ) ? a : b );
95
118
private static final BinaryOperation <LocalTime > TIME_MAX =
96
119
new BinaryCoalescingOperation <>(TimeOfDayType .INSTANCE , (a , b ) -> a .isAfter (b ) ? a : b );
120
+ private static final BinaryOperation <String > TEXT_MAX =
121
+ new BinaryCoalescingOperation <>(
122
+ TextType .VARIABLE_LENGTH , (a , b ) -> Text_Utils .compare_normalized (a , b ) > 0 ? a : b ) {
123
+ @ Override
124
+ protected BuilderForType <String > makeStorageBuilder (
125
+ long size , StorageType <?> leftType , StorageType <?> rightType ) {
126
+ return TextType .maxType (leftType , rightType )
127
+ .makeBuilder (size , BlackholeProblemAggregator .INSTANCE );
128
+ }
129
+ };
97
130
98
131
public static Column max (
99
132
Column left ,
@@ -108,16 +141,19 @@ public static Column max(
108
141
case DateType d -> DATE_MAX ;
109
142
case DateTimeType dt -> DATE_TIME_MAX ;
110
143
case TimeOfDayType t -> TIME_MAX ;
144
+ case TextType t -> TEXT_MAX ;
145
+ case NumericType n -> BinaryCoalescingOperationNumeric .create (
146
+ leftStorage .getType (), right , BinaryCoalescingOperationNumeric .MAX_OPERATION );
111
147
default -> null ;
112
148
};
113
149
return applyOperation (
114
- left , right , fallback , fallbackType , name , problemBuilder , operation , leftStorage , "max" );
150
+ left , right , fallback , fallbackType , name , problemBuilder , operation , leftStorage );
115
151
}
116
152
117
153
private final StorageType <T > validType ;
118
154
private final BiFunction <T , T , T > zipOperation ;
119
155
120
- private BinaryCoalescingOperation (StorageType <T > validType , BiFunction <T , T , T > zipOperation ) {
156
+ protected BinaryCoalescingOperation (StorageType <T > validType , BiFunction <T , T , T > zipOperation ) {
121
157
this .validType = validType ;
122
158
this .zipOperation = zipOperation ;
123
159
}
@@ -148,7 +184,7 @@ public ColumnStorage<T> applyMap(ColumnStorage<?> left, Object rightValue) {
148
184
return StorageIterators .mapOverStorage (
149
185
validType .asTypedStorage (left ),
150
186
false ,
151
- validType . makeBuilder (left .getSize (), BlackholeProblemAggregator . INSTANCE ),
187
+ makeStorageBuilder (left .getSize (), left . getType (), null ),
152
188
(idx , value ) -> zipOperation .apply (value , rightValueTyped ));
153
189
}
154
190
@@ -161,8 +197,13 @@ public ColumnStorage<T> applyZip(ColumnStorage<?> left, ColumnStorage<?> right)
161
197
return StorageIterators .zipOverStorages (
162
198
validType .asTypedStorage (left ),
163
199
validType .asTypedStorage (right ),
164
- size -> validType . makeBuilder (size , BlackholeProblemAggregator . INSTANCE ),
200
+ size -> makeStorageBuilder (size , left . getType (), right . getType () ),
165
201
false ,
166
202
(index , l , r ) -> l == null ? r : (r == null ? l : zipOperation .apply (l , r )));
167
203
}
204
+
205
+ protected BuilderForType <T > makeStorageBuilder (
206
+ long size , StorageType <?> leftType , StorageType <?> rightType ) {
207
+ return validType .makeBuilder (size , BlackholeProblemAggregator .INSTANCE );
208
+ }
168
209
}
0 commit comments