2222import org .apache .doris .common .jni .vec .ColumnValueConverter ;
2323import org .apache .doris .common .jni .vec .VectorTable ;
2424
25- import com .google .common .collect .Lists ;
26-
27- import java .lang .reflect .Array ;
2825import java .math .BigDecimal ;
29- import java .math .BigInteger ;
30- import java .net .InetAddress ;
26+ import java .sql .Date ;
3127import java .sql .SQLException ;
32- import java .time .LocalDate ;
33- import java .time .LocalDateTime ;
34- import java .util .ArrayList ;
35- import java .util .List ;
28+ import java .sql .Timestamp ;
3629
3730public class Hive2JdbcExecutor extends BaseJdbcExecutor {
3831
@@ -56,169 +49,52 @@ protected void initializeBlock(int columnCount, String[] replaceStringList, int
5649 protected Object getColumnValue (int columnIndex , ColumnType type , String [] replaceStringList ) throws SQLException {
5750 switch (type .getType ()) {
5851 case BOOLEAN :
59- return resultSet .getObject (columnIndex + 1 , Boolean .class );
52+ boolean boolVal = resultSet .getBoolean (columnIndex + 1 );
53+ return resultSet .wasNull () ? null : boolVal ;
6054 case TINYINT :
61- return resultSet .getObject (columnIndex + 1 , Byte .class );
55+ byte tinyIntVal = resultSet .getByte (columnIndex + 1 );
56+ return resultSet .wasNull () ? null : tinyIntVal ;
6257 case SMALLINT :
63- return resultSet .getObject (columnIndex + 1 , Short .class );
58+ short smallIntVal = resultSet .getShort (columnIndex + 1 );
59+ return resultSet .wasNull () ? null : smallIntVal ;
6460 case INT :
65- return resultSet .getObject (columnIndex + 1 , Integer .class );
61+ int intVal = resultSet .getInt (columnIndex + 1 );
62+ return resultSet .wasNull () ? null : intVal ;
6663 case BIGINT :
67- return resultSet .getObject (columnIndex + 1 , Long .class );
68- case LARGEINT :
69- return resultSet .getObject (columnIndex + 1 , BigInteger .class );
64+ long bigIntVal = resultSet .getLong (columnIndex + 1 );
65+ return resultSet .wasNull () ? null : bigIntVal ;
7066 case FLOAT :
71- return resultSet .getObject (columnIndex + 1 , Float .class );
67+ float floatVal = resultSet .getFloat (columnIndex + 1 );
68+ return resultSet .wasNull () ? null : floatVal ;
7269 case DOUBLE :
73- return resultSet .getObject (columnIndex + 1 , Double .class );
70+ double doubleVal = resultSet .getDouble (columnIndex + 1 );
71+ return resultSet .wasNull () ? null : doubleVal ;
7472 case DECIMALV2 :
7573 case DECIMAL32 :
7674 case DECIMAL64 :
7775 case DECIMAL128 :
78- return resultSet .getObject (columnIndex + 1 , BigDecimal .class );
76+ BigDecimal decimalVal = resultSet .getBigDecimal (columnIndex + 1 );
77+ return resultSet .wasNull () ? null : decimalVal ;
7978 case DATE :
8079 case DATEV2 :
81- return resultSet .getObject (columnIndex + 1 , LocalDate .class );
80+ Date dateVal = resultSet .getDate (columnIndex + 1 );
81+ return resultSet .wasNull () ? null : dateVal .toLocalDate ();
8282 case DATETIME :
8383 case DATETIMEV2 :
84- return resultSet .getObject (columnIndex + 1 , LocalDateTime .class );
84+ Timestamp timestampVal = resultSet .getTimestamp (columnIndex + 1 );
85+ return resultSet .wasNull () ? null : timestampVal .toLocalDateTime ();
8586 case CHAR :
8687 case VARCHAR :
8788 case STRING :
88- return resultSet .getObject (columnIndex + 1 , String .class );
89- case ARRAY :
90- return convertArrayToList (resultSet .getArray (columnIndex + 1 ).getArray ());
89+ String stringVal = resultSet .getString (columnIndex + 1 );
90+ return resultSet .wasNull () ? null : stringVal ;
9191 default :
9292 throw new IllegalArgumentException ("Unsupported column type: " + type .getType ());
9393 }
9494 }
9595
9696 @ Override
9797 protected ColumnValueConverter getOutputConverter (ColumnType columnType , String replaceString ) {
98- if (columnType .getType () == Type .ARRAY ) {
99- return createConverter (
100- (Object input ) -> convertArray ((List <?>) input , columnType .getChildTypes ().get (0 )),
101- List .class );
102- } else {
103- return null ;
104- }
105- }
106-
107- private List <Object > convertArrayToList (Object array ) {
108- if (array == null ) {
109- return null ;
110- }
111-
112- int length = Array .getLength (array );
113- List <Object > list = new ArrayList <>(length );
114-
115- for (int i = 0 ; i < length ; i ++) {
116- Object element = Array .get (array , i );
117- list .add (element );
118- }
119-
120- return list ;
121- }
122-
123- private List <?> convertArray (List <?> array , ColumnType type ) {
124- if (array == null ) {
125- return null ;
126- }
127- switch (type .getType ()) {
128- case SMALLINT : {
129- List <Short > result = Lists .newArrayList ();
130- for (Object element : array ) {
131- if (element == null ) {
132- result .add (null );
133- } else {
134- if (element instanceof Byte ) {
135- result .add (((Byte ) element ).shortValue ());
136- } else if (element instanceof Number ) {
137- result .add (((Number ) element ).shortValue ());
138- } else {
139- throw new IllegalArgumentException ("Unsupported element type: " + element .getClass ());
140- }
141- }
142- }
143- return result ;
144- }
145- case INT : {
146- List <Integer > result = Lists .newArrayList ();
147- for (Object element : array ) {
148- if (element == null ) {
149- result .add (null );
150- } else {
151- if (element instanceof Short ) {
152- result .add (((Short ) element ).intValue ());
153- } else if (element instanceof Number ) {
154- result .add (((Number ) element ).intValue ());
155- } else {
156- throw new IllegalArgumentException ("Unsupported element type: " + element .getClass ());
157- }
158- }
159- }
160- return result ;
161- }
162- case BIGINT : {
163- List <Long > result = Lists .newArrayList ();
164- for (Object element : array ) {
165- if (element == null ) {
166- result .add (null );
167- } else {
168- if (element instanceof Integer ) {
169- result .add (((Integer ) element ).longValue ());
170- } else if (element instanceof Number ) {
171- result .add (((Number ) element ).longValue ());
172- } else {
173- throw new IllegalArgumentException ("Unsupported element type: " + element .getClass ());
174- }
175- }
176- }
177- return result ;
178- }
179- case LARGEINT : {
180- List <BigInteger > result = Lists .newArrayList ();
181- for (Object element : array ) {
182- if (element == null ) {
183- result .add (null );
184- } else {
185- if (element instanceof BigDecimal ) {
186- result .add (((BigDecimal ) element ).toBigInteger ());
187- } else if (element instanceof Number ) {
188- result .add (BigInteger .valueOf (((Number ) element ).longValue ()));
189- } else {
190- throw new IllegalArgumentException ("Unsupported element type: " + element .getClass ());
191- }
192- }
193- }
194- return result ;
195- }
196- case STRING : {
197- List <String > result = Lists .newArrayList ();
198- for (Object element : array ) {
199- if (element == null ) {
200- result .add (null );
201- } else if (element instanceof InetAddress ) {
202- result .add (((InetAddress ) element ).getHostAddress ());
203- } else {
204- result .add (element .toString ());
205- }
206- }
207- return result ;
208- }
209- case ARRAY :
210- List <List <?>> resultArray = Lists .newArrayList ();
211- for (Object element : array ) {
212- if (element == null ) {
213- resultArray .add (null );
214- } else {
215- resultArray .add (
216- Lists .newArrayList (convertArray ((List <?>) element , type .getChildTypes ().get (0 ))));
217- }
218- }
219- return resultArray ;
220- default :
221- return array ;
222- }
98+ return null ;
22399 }
224100}
0 commit comments