@@ -40,23 +40,28 @@ public static Column apply(
4040 /** Construct a StorageConverter for the given target type. */
4141 private static StorageConverter <?> fromStorageType (StorageType <?> storageType ) {
4242 return switch (StorageType .makeLocal (storageType )) {
43- case AnyObjectType anyObjectType -> new ToMixedStorageConverter ();
44- case BooleanType booleanType -> new ToBooleanStorageConverter ();
45- case DateType dateType -> new ToDateStorageConverter ();
46- case DateTimeType dateTimeType -> new ToDateTimeStorageConverter ();
43+ case AnyObjectType _ -> new ToMixedStorageConverter ();
44+ case BooleanType _ -> new ToBooleanStorageConverter ();
45+ case DateType _ -> new ToDateStorageConverter ();
46+ case DateTimeType _ -> new ToDateTimeStorageConverter ();
4747 case FloatType floatType -> new ToFloatStorageConverter (floatType );
4848 case IntegerType integerType -> new ToIntegerStorageConverter (integerType );
4949 case TextType textType -> new ToTextStorageConverter (textType );
50- case TimeOfDayType timeOfDayType -> new ToTimeOfDayStorageConverter ();
51- case BigIntegerType bigIntegerType -> new ToBigIntegerConverter ();
52- case BigDecimalType bigDecimalType -> new ToBigDecimalConverter ();
53- case NullType nullType -> throw new IllegalArgumentException ("Cannot cast to Null type." );
50+ case TimeOfDayType _ -> new ToTimeOfDayStorageConverter ();
51+ case BigIntegerType _ -> new ToBigIntegerConverter ();
52+ case BigDecimalType _ -> new ToBigDecimalConverter ();
53+ case NullType _ -> throw new IllegalArgumentException ("Cannot cast to Null type." );
5454 default ->
5555 throw new IllegalStateException (
5656 "Unsupported type: " + storageType + " - this is a bug in the Table library." );
5757 };
5858 }
5959
60+ /** Helper method until Java Problems code in Enso is re-visited. */
61+ public static StorageType <?> makeLocalType (StorageType <?> type ) {
62+ return StorageType .makeLocal (type );
63+ }
64+
6065 public static StorageType <?> inferPreciseType (Column column ) {
6166 return inferPreciseType (column , PreciseTypeOptions .DEFAULT );
6267 }
@@ -65,13 +70,14 @@ public static StorageType<?> inferPreciseType(Column column, PreciseTypeOptions
6570 var columnStorage = column .getStorage ();
6671 var storage = ColumnStorageWithInferredStorage .resolveStorage (columnStorage );
6772
68- return switch (storage .getType ()) {
69- case TextType textType -> inferTextType (storage , options );
70- case IntegerType integerType -> inferIntegerType (storage , options );
71- case FloatType floatType -> inferFloatType (storage , options );
72- case BigIntegerType bigIntegerType -> inferBigIntegerType (storage , options );
73- case BigDecimalType bigDecimalType -> inferBigDecimalType (storage , options );
74- default -> storage .getType ();
73+ var storageType = StorageType .makeLocal (storage .getType ());
74+ return switch (storageType ) {
75+ case TextType textType -> inferTextType (storage , textType , options );
76+ case IntegerType integerType -> inferIntegerType (storage , integerType , options );
77+ case FloatType floatType -> inferFloatType (storage , floatType , options );
78+ case BigIntegerType bigIntegerType -> inferBigIntegerType (storage , bigIntegerType , options );
79+ case BigDecimalType bigDecimalType -> inferBigDecimalType (storage , bigDecimalType , options );
80+ default -> storageType ;
7581 };
7682 }
7783
@@ -104,17 +110,8 @@ public long getMinLength() {
104110 }
105111
106112 private static StorageType <?> inferTextType (
107- ColumnStorage <?> columnStorage , PreciseTypeOptions options ) {
108- if (!options .shrinkText ()) {
109- return columnStorage .getType ();
110- }
111-
112- if (!(columnStorage .getType () instanceof TextType textType )) {
113- throw new IllegalArgumentException (
114- "Cannot infer text type from non-text storage: " + columnStorage .getType ());
115- }
116-
117- if (textType .fixedLength ()) {
113+ ColumnStorage <?> columnStorage , TextType textType , PreciseTypeOptions options ) {
114+ if (!options .shrinkText () || textType .fixedLength ()) {
118115 return textType ;
119116 }
120117
@@ -180,14 +177,9 @@ public IntegerType resolveType() {
180177 }
181178
182179 private static StorageType <?> inferIntegerType (
183- ColumnStorage <?> columnStorage , PreciseTypeOptions options ) {
180+ ColumnStorage <?> columnStorage , IntegerType integerType , PreciseTypeOptions options ) {
184181 if (!options .shrinkIntegers ()) {
185- return columnStorage .getType ();
186- }
187-
188- if (!(columnStorage .getType () instanceof IntegerType integerType )) {
189- throw new IllegalArgumentException (
190- "Cannot infer integer type from non-integer storage: " + columnStorage .getType ());
182+ return integerType ;
191183 }
192184
193185 if (integerType .size () <= 16 ) {
@@ -206,12 +198,7 @@ private static StorageType<?> inferIntegerType(
206198 }
207199
208200 private static StorageType <?> inferBigIntegerType (
209- ColumnStorage <?> columnStorage , PreciseTypeOptions options ) {
210- if (!(columnStorage .getType () instanceof BigIntegerType bigIntegerType )) {
211- throw new IllegalArgumentException (
212- "Cannot infer integer type from non-integer storage: " + columnStorage .getType ());
213- }
214-
201+ ColumnStorage <?> columnStorage , BigIntegerType bigIntegerType , PreciseTypeOptions options ) {
215202 // Build the min and max of values in the column.
216203 var accumulator = new LongAccumulator ();
217204 var endedEarly =
@@ -239,14 +226,9 @@ private static StorageType<?> inferBigIntegerType(
239226 }
240227
241228 private static StorageType <?> inferFloatType (
242- ColumnStorage <?> columnStorage , PreciseTypeOptions options ) {
229+ ColumnStorage <?> columnStorage , FloatType floatType , PreciseTypeOptions options ) {
243230 if (!options .wholeFloatsBecomeIntegers ()) {
244- return columnStorage .getType ();
245- }
246-
247- if (!(columnStorage .getType () instanceof FloatType floatType )) {
248- throw new IllegalArgumentException (
249- "Cannot infer float type from non-integer storage: " + columnStorage .getType ());
231+ return floatType ;
250232 }
251233
252234 // Build the min and max of values in the column.
@@ -301,14 +283,9 @@ public boolean getOverflowed() {
301283 }
302284
303285 private static StorageType <?> inferBigDecimalType (
304- ColumnStorage <?> columnStorage , PreciseTypeOptions options ) {
286+ ColumnStorage <?> columnStorage , BigDecimalType bigDecimalType , PreciseTypeOptions options ) {
305287 if (!options .wholeFloatsBecomeIntegers ()) {
306- return columnStorage .getType ();
307- }
308-
309- if (!(columnStorage .getType () instanceof BigDecimalType bigDecimalType )) {
310- throw new IllegalArgumentException (
311- "Cannot infer decimal type from non-decimal storage: " + columnStorage .getType ());
288+ return bigDecimalType ;
312289 }
313290
314291 // Build the min and max of values in the column.
0 commit comments