16
16
import java .util .HashMap ;
17
17
import java .util .List ;
18
18
import java .util .Map ;
19
+ import java .util .Objects ;
19
20
import org .apache .arrow .memory .BufferAllocator ;
20
21
import org .apache .arrow .memory .RootAllocator ;
21
22
import org .apache .arrow .vector .BigIntVector ;
@@ -57,80 +58,80 @@ public class ArrowHelper {
57
58
58
59
private static void setVectorData (FieldVector vector , Object data ) {
59
60
vector .allocateNew ();
60
- if (vector instanceof BigIntVector ) {
61
- (( BigIntVector ) vector ) .set (0 , (long ) data );
61
+ if (vector instanceof BigIntVector bigIntVector ) {
62
+ bigIntVector .set (0 , (long ) data );
62
63
return ;
63
64
}
64
- if (vector instanceof BitVector ) {
65
- (( BitVector ) vector ) .set (0 , (int ) data );
65
+ if (vector instanceof BitVector bitVector ) {
66
+ bitVector .set (0 , (int ) data );
66
67
return ;
67
68
}
68
- if (vector instanceof FixedSizeBinaryVector ) {
69
- (( FixedSizeBinaryVector ) vector ) .set (0 , (byte []) data );
69
+ if (vector instanceof FixedSizeBinaryVector fixedSizeBinaryVector ) {
70
+ fixedSizeBinaryVector .set (0 , (byte []) data );
70
71
return ;
71
72
}
72
- if (vector instanceof Float4Vector ) {
73
- (( Float4Vector ) vector ) .set (0 , (float ) data );
73
+ if (vector instanceof Float4Vector float4Vector ) {
74
+ float4Vector .set (0 , (float ) data );
74
75
return ;
75
76
}
76
- if (vector instanceof Float8Vector ) {
77
- (( Float8Vector ) vector ) .set (0 , (double ) data );
77
+ if (vector instanceof Float8Vector float8Vector ) {
78
+ float8Vector .set (0 , (double ) data );
78
79
return ;
79
80
}
80
- if (vector instanceof IntVector ) {
81
- (( IntVector ) vector ) .set (0 , (int ) data );
81
+ if (vector instanceof IntVector intVector ) {
82
+ intVector .set (0 , (int ) data );
82
83
return ;
83
84
}
84
- if (vector instanceof LargeVarBinaryVector ) {
85
- (( LargeVarBinaryVector ) vector ) .set (0 , (byte []) data );
85
+ if (vector instanceof LargeVarBinaryVector largeVarBinaryVector ) {
86
+ largeVarBinaryVector .set (0 , (byte []) data );
86
87
return ;
87
88
}
88
- if (vector instanceof LargeVarCharVector ) {
89
- (( LargeVarCharVector ) vector ) .set (0 , (Text ) data );
89
+ if (vector instanceof LargeVarCharVector largeVarCharVector ) {
90
+ largeVarCharVector .set (0 , (Text ) data );
90
91
return ;
91
92
}
92
- if (vector instanceof SmallIntVector ) {
93
- (( SmallIntVector ) vector ) .set (0 , (short ) data );
93
+ if (vector instanceof SmallIntVector smallIntVector ) {
94
+ smallIntVector .set (0 , (short ) data );
94
95
return ;
95
96
}
96
- if (vector instanceof TimeStampVector ) {
97
- (( TimeStampVector ) vector ) .set (0 , (long ) data );
97
+ if (vector instanceof TimeStampVector timeStampVector ) {
98
+ timeStampVector .set (0 , (long ) data );
98
99
return ;
99
100
}
100
- if (vector instanceof TinyIntVector ) {
101
- (( TinyIntVector ) vector ) .set (0 , (byte ) data );
101
+ if (vector instanceof TinyIntVector tinyIntVector ) {
102
+ tinyIntVector .set (0 , (byte ) data );
102
103
return ;
103
104
}
104
- if (vector instanceof UInt1Vector ) {
105
- (( UInt1Vector ) vector ) .set (0 , (byte ) data );
105
+ if (vector instanceof UInt1Vector uInt1Vector ) {
106
+ uInt1Vector .set (0 , (byte ) data );
106
107
return ;
107
108
}
108
- if (vector instanceof UInt2Vector ) {
109
- (( UInt2Vector ) vector ) .set (0 , (short ) data );
109
+ if (vector instanceof UInt2Vector uInt2Vector ) {
110
+ uInt2Vector .set (0 , (short ) data );
110
111
return ;
111
112
}
112
- if (vector instanceof UInt4Vector ) {
113
- (( UInt4Vector ) vector ) .set (0 , (int ) data );
113
+ if (vector instanceof UInt4Vector uInt4Vector ) {
114
+ uInt4Vector .set (0 , (int ) data );
114
115
return ;
115
116
}
116
- if (vector instanceof UInt8Vector ) {
117
- (( UInt8Vector ) vector ) .set (0 , (long ) data );
117
+ if (vector instanceof UInt8Vector uInt8Vector ) {
118
+ uInt8Vector .set (0 , (long ) data );
118
119
return ;
119
120
}
120
- if (vector instanceof VarBinaryVector ) {
121
- (( VarBinaryVector ) vector ) .set (0 , (byte []) data );
121
+ if (vector instanceof VarBinaryVector varBinaryVector ) {
122
+ varBinaryVector .set (0 , (byte []) data );
122
123
return ;
123
124
}
124
- if (vector instanceof VarCharVector ) {
125
- (( VarCharVector ) vector ) .set (0 , (Text ) data );
125
+ if (vector instanceof VarCharVector vectorCharVector ) {
126
+ vectorCharVector .set (0 , (Text ) data );
126
127
return ;
127
128
}
128
- if (vector instanceof UUIDVector ) {
129
- (( UUIDVector ) vector ) .set (0 , (java .util .UUID ) data );
129
+ if (vector instanceof UUIDVector uuidVector ) {
130
+ uuidVector .set (0 , (java .util .UUID ) data );
130
131
return ;
131
132
}
132
- if (vector instanceof JSONVector ) {
133
- (( JSONVector ) vector ) .setSafe (0 , (byte []) data );
133
+ if (vector instanceof JSONVector jsonVector ) {
134
+ jsonVector .setSafe (0 , (byte []) data );
134
135
return ;
135
136
}
136
137
@@ -168,9 +169,9 @@ public static Schema toArrowSchema(Table table) {
168
169
for (int i = 0 ; i < columns .size (); i ++) {
169
170
Column column = columns .get (i );
170
171
Map <String , String > metadata = new HashMap <>();
171
- metadata .put (CQ_EXTENSION_UNIQUE , column .isUnique () ? "true" : "false" );
172
- metadata .put (CQ_EXTENSION_PRIMARY_KEY , column .isPrimaryKey () ? "true" : "false" );
173
- metadata .put (CQ_EXTENSION_INCREMENTAL , column .isIncrementalKey () ? "true" : "false" );
172
+ metadata .put (CQ_EXTENSION_UNIQUE , Boolean . toString ( column .isUnique ()) );
173
+ metadata .put (CQ_EXTENSION_PRIMARY_KEY , Boolean . toString ( column .isPrimaryKey ()) );
174
+ metadata .put (CQ_EXTENSION_INCREMENTAL , Boolean . toString ( column .isIncrementalKey ()) );
174
175
Field field =
175
176
new Field (
176
177
column .getName (),
@@ -196,9 +197,11 @@ public static Schema toArrowSchema(Table table) {
196
197
public static Table fromArrowSchema (Schema schema ) {
197
198
List <Column > columns = new ArrayList <>();
198
199
for (Field field : schema .getFields ()) {
199
- boolean isUnique = field .getMetadata ().get (CQ_EXTENSION_UNIQUE ) == "true" ;
200
- boolean isPrimaryKey = field .getMetadata ().get (CQ_EXTENSION_PRIMARY_KEY ) == "true" ;
201
- boolean isIncrementalKey = field .getMetadata ().get (CQ_EXTENSION_INCREMENTAL ) == "true" ;
200
+ boolean isUnique = Objects .equals (field .getMetadata ().get (CQ_EXTENSION_UNIQUE ), "true" );
201
+ boolean isPrimaryKey =
202
+ Objects .equals (field .getMetadata ().get (CQ_EXTENSION_PRIMARY_KEY ), "true" );
203
+ boolean isIncrementalKey =
204
+ Objects .equals (field .getMetadata ().get (CQ_EXTENSION_INCREMENTAL ), "true" );
202
205
203
206
columns .add (
204
207
Column .builder ()
0 commit comments