17
17
18
18
package org .apache .arrow .adapter .jdbc ;
19
19
20
- import static org .apache .arrow .vector .types .FloatingPointPrecision .DOUBLE ;
21
- import static org .apache .arrow .vector .types .FloatingPointPrecision .SINGLE ;
22
-
23
- import java .sql .Types ;
24
20
import java .util .Calendar ;
25
21
import java .util .Map ;
26
22
import java .util .function .Function ;
27
23
28
24
import org .apache .arrow .memory .BufferAllocator ;
29
25
import org .apache .arrow .util .Preconditions ;
30
- import org .apache .arrow .vector .types .DateUnit ;
31
- import org .apache .arrow .vector .types .TimeUnit ;
32
26
import org .apache .arrow .vector .types .pojo .ArrowType ;
33
27
34
28
/**
55
49
*/
56
50
public final class JdbcToArrowConfig {
57
51
52
+ public static final int DEFAULT_TARGET_BATCH_SIZE = 1024 ;
53
+ public static final int NO_LIMIT_BATCH_SIZE = -1 ;
58
54
private final Calendar calendar ;
59
55
private final BufferAllocator allocator ;
60
56
private final boolean includeMetadata ;
61
57
private final boolean reuseVectorSchemaRoot ;
62
58
private final Map <Integer , JdbcFieldInfo > arraySubTypesByColumnIndex ;
63
59
private final Map <String , JdbcFieldInfo > arraySubTypesByColumnName ;
64
-
65
- public static final int DEFAULT_TARGET_BATCH_SIZE = 1024 ;
66
- public static final int NO_LIMIT_BATCH_SIZE = -1 ;
67
-
68
60
/**
69
61
* The maximum rowCount to read each time when partially convert data.
70
62
* Default value is 1024 and -1 means disable partial read.
@@ -82,7 +74,7 @@ public final class JdbcToArrowConfig {
82
74
/**
83
75
* Constructs a new configuration from the provided allocator and calendar. The <code>allocator</code>
84
76
* is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define
85
- * Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
77
+ * Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
86
78
*
87
79
* @param allocator The memory allocator to construct the Arrow vectors with.
88
80
* @param calendar The calendar to use when constructing Timestamp fields and reading time-based results.
@@ -99,7 +91,7 @@ public final class JdbcToArrowConfig {
99
91
/**
100
92
* Constructs a new configuration from the provided allocator and calendar. The <code>allocator</code>
101
93
* is used when constructing the Arrow vectors from the ResultSet, and the calendar is used to define
102
- * Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
94
+ * Arrow Timestamp fields, and to read time-based fields from the JDBC <code>ResultSet</code>.
103
95
*
104
96
* @param allocator The memory allocator to construct the Arrow vectors with.
105
97
* @param calendar The calendar to use when constructing Timestamp fields and reading time-based results.
@@ -134,6 +126,8 @@ public final class JdbcToArrowConfig {
134
126
* <li>TIMESTAMP --> ArrowType.Timestamp(TimeUnit.MILLISECOND, calendar timezone)</li>
135
127
* <li>CLOB --> ArrowType.Utf8</li>
136
128
* <li>BLOB --> ArrowType.Binary</li>
129
+ * <li>ARRAY --> ArrowType.List</li>
130
+ * <li>STRUCT --> ArrowType.Struct</li>
137
131
* <li>NULL --> ArrowType.Null</li>
138
132
* </ul>
139
133
*/
@@ -157,64 +151,7 @@ public final class JdbcToArrowConfig {
157
151
158
152
// set up type converter
159
153
this .jdbcToArrowTypeConverter = jdbcToArrowTypeConverter != null ? jdbcToArrowTypeConverter :
160
- fieldInfo -> {
161
- final String timezone ;
162
- if (calendar != null ) {
163
- timezone = calendar .getTimeZone ().getID ();
164
- } else {
165
- timezone = null ;
166
- }
167
-
168
- switch (fieldInfo .getJdbcType ()) {
169
- case Types .BOOLEAN :
170
- case Types .BIT :
171
- return new ArrowType .Bool ();
172
- case Types .TINYINT :
173
- return new ArrowType .Int (8 , true );
174
- case Types .SMALLINT :
175
- return new ArrowType .Int (16 , true );
176
- case Types .INTEGER :
177
- return new ArrowType .Int (32 , true );
178
- case Types .BIGINT :
179
- return new ArrowType .Int (64 , true );
180
- case Types .NUMERIC :
181
- case Types .DECIMAL :
182
- int precision = fieldInfo .getPrecision ();
183
- int scale = fieldInfo .getScale ();
184
- return new ArrowType .Decimal (precision , scale , 128 );
185
- case Types .REAL :
186
- case Types .FLOAT :
187
- return new ArrowType .FloatingPoint (SINGLE );
188
- case Types .DOUBLE :
189
- return new ArrowType .FloatingPoint (DOUBLE );
190
- case Types .CHAR :
191
- case Types .NCHAR :
192
- case Types .VARCHAR :
193
- case Types .NVARCHAR :
194
- case Types .LONGVARCHAR :
195
- case Types .LONGNVARCHAR :
196
- case Types .CLOB :
197
- return new ArrowType .Utf8 ();
198
- case Types .DATE :
199
- return new ArrowType .Date (DateUnit .DAY );
200
- case Types .TIME :
201
- return new ArrowType .Time (TimeUnit .MILLISECOND , 32 );
202
- case Types .TIMESTAMP :
203
- return new ArrowType .Timestamp (TimeUnit .MILLISECOND , timezone );
204
- case Types .BINARY :
205
- case Types .VARBINARY :
206
- case Types .LONGVARBINARY :
207
- case Types .BLOB :
208
- return new ArrowType .Binary ();
209
- case Types .ARRAY :
210
- return new ArrowType .List ();
211
- case Types .NULL :
212
- return new ArrowType .Null ();
213
- default :
214
- // no-op, shouldn't get here
215
- return null ;
216
- }
217
- };
154
+ jdbcFieldInfo -> JdbcToArrowUtils .getArrowTypeFromJdbcType (jdbcFieldInfo , calendar );
218
155
}
219
156
220
157
/**
@@ -230,6 +167,7 @@ public Calendar getCalendar() {
230
167
231
168
/**
232
169
* The Arrow memory allocator.
170
+ *
233
171
* @return the allocator.
234
172
*/
235
173
public BufferAllocator getAllocator () {
0 commit comments