2424import javax .annotation .Nullable ;
2525import java .math .BigDecimal ;
2626import java .sql .Date ;
27- import java .util .Arrays ;
28- import java .util .HashSet ;
29- import java .util .List ;
30- import java .util .Set ;
27+ import java .util .*;
3128
3229import org .apache .spark .sql .Row ;
3330import org .apache .spark .sql .types .DataType ;
@@ -73,7 +70,7 @@ public final class UnsafeRow implements MutableRow {
7370 private StructType schema ;
7471
7572 private long getFieldOffset (int ordinal ) {
76- return baseOffset + bitSetWidthInBytes + ordinal * 8 ;
73+ return baseOffset + bitSetWidthInBytes + ordinal * 8L ;
7774 }
7875
7976 public static int calculateBitSetWidthInBytes (int numFields ) {
@@ -91,21 +88,25 @@ public static int calculateBitSetWidthInBytes(int numFields) {
9188 public static final Set <DataType > readableFieldTypes ;
9289
9390 static {
94- settableFieldTypes = new HashSet <DataType >(Arrays .asList (new DataType [] {
95- IntegerType ,
96- LongType ,
97- DoubleType ,
98- BooleanType ,
99- ShortType ,
100- ByteType ,
101- FloatType
102- }));
91+ settableFieldTypes = Collections .unmodifiableSet (
92+ new HashSet <DataType >(
93+ Arrays .asList (new DataType [] {
94+ IntegerType ,
95+ LongType ,
96+ DoubleType ,
97+ BooleanType ,
98+ ShortType ,
99+ ByteType ,
100+ FloatType
101+ })));
103102
104103 // We support get() on a superset of the types for which we support set():
105- readableFieldTypes = new HashSet <DataType >(Arrays .asList (new DataType [] {
106- StringType
107- }));
108- readableFieldTypes .addAll (settableFieldTypes );
104+ final Set <DataType > _readableFieldTypes = new HashSet <DataType >(
105+ Arrays .asList (new DataType []{
106+ StringType
107+ }));
108+ _readableFieldTypes .addAll (settableFieldTypes );
109+ readableFieldTypes = Collections .unmodifiableSet (_readableFieldTypes );
109110 }
110111
111112 /**
@@ -156,9 +157,6 @@ private void setNotNullAt(int i) {
156157
157158 @ Override
158159 public void update (int ordinal , Object value ) {
159- assert schema != null : "schema cannot be null when calling the generic update()" ;
160- final DataType type = schema .fields ()[ordinal ].dataType ();
161- // TODO: match based on the type, then set. This will be slow.
162160 throw new UnsupportedOperationException ();
163161 }
164162
@@ -240,6 +238,7 @@ public Object apply(int i) {
240238 @ Override
241239 public Object get (int i ) {
242240 assertIndexIsValid (i );
241+ assert (schema != null ) : "Schema must be defined when calling generic get() method" ;
243242 final DataType dataType = schema .fields ()[i ].dataType ();
244243 // The ordering of these `if` statements is intentional: internally, it looks like this only
245244 // gets invoked in JoinedRow when trying to access UTF8String columns. It's extremely unlikely
0 commit comments