@@ -328,9 +328,16 @@ public boolean getBoolean(String columnName) throws StatementExecutionException
328328 return getBooleanByTsBlockColumnIndex (getTsBlockColumnIndexForColumnName (columnName ));
329329 }
330330
331+ // Note: tsBlockColumnIndex < 0 indicates the time pseudo-column in tree model.
332+ // Only getLong and getString support reading the time column directly.
333+ // All other typed getters throw StatementExecutionException to prevent
334+ // ArrayIndexOutOfBoundsException from TsBlock.getColumn with a negative index.
331335 private boolean getBooleanByTsBlockColumnIndex (int tsBlockColumnIndex )
332336 throws StatementExecutionException {
333337 checkRecord ();
338+ if (tsBlockColumnIndex < 0 ) {
339+ throw new StatementExecutionException ("Cannot read boolean from time column" );
340+ }
334341 if (!isNull (tsBlockColumnIndex , tsBlockIndex )) {
335342 lastReadWasNull = false ;
336343 return curTsBlock .getColumn (tsBlockColumnIndex ).getBoolean (tsBlockIndex );
@@ -351,6 +358,9 @@ public double getDouble(String columnName) throws StatementExecutionException {
351358 private double getDoubleByTsBlockColumnIndex (int tsBlockColumnIndex )
352359 throws StatementExecutionException {
353360 checkRecord ();
361+ if (tsBlockColumnIndex < 0 ) {
362+ throw new StatementExecutionException ("Cannot read double from time column" );
363+ }
354364 if (!isNull (tsBlockColumnIndex , tsBlockIndex )) {
355365 lastReadWasNull = false ;
356366 return curTsBlock .getColumn (tsBlockColumnIndex ).getDouble (tsBlockIndex );
@@ -371,6 +381,9 @@ public float getFloat(String columnName) throws StatementExecutionException {
371381 private float getFloatByTsBlockColumnIndex (int tsBlockColumnIndex )
372382 throws StatementExecutionException {
373383 checkRecord ();
384+ if (tsBlockColumnIndex < 0 ) {
385+ throw new StatementExecutionException ("Cannot read float from time column" );
386+ }
374387 if (!isNull (tsBlockColumnIndex , tsBlockIndex )) {
375388 lastReadWasNull = false ;
376389 return curTsBlock .getColumn (tsBlockColumnIndex ).getFloat (tsBlockIndex );
@@ -391,6 +404,9 @@ public int getInt(String columnName) throws StatementExecutionException {
391404 private int getIntByTsBlockColumnIndex (int tsBlockColumnIndex )
392405 throws StatementExecutionException {
393406 checkRecord ();
407+ if (tsBlockColumnIndex < 0 ) {
408+ throw new StatementExecutionException ("Cannot read int32 from time column" );
409+ }
394410 if (!isNull (tsBlockColumnIndex , tsBlockIndex )) {
395411 lastReadWasNull = false ;
396412 TSDataType type = curTsBlock .getColumn (tsBlockColumnIndex ).getDataType ();
@@ -449,6 +465,9 @@ public Binary getBinary(String columnName) throws StatementExecutionException {
449465 private Binary getBinaryTsBlockColumnIndex (int tsBlockColumnIndex )
450466 throws StatementExecutionException {
451467 checkRecord ();
468+ if (tsBlockColumnIndex < 0 ) {
469+ throw new StatementExecutionException ("Cannot read binary from time column" );
470+ }
452471 if (!isNull (tsBlockColumnIndex , tsBlockIndex )) {
453472 lastReadWasNull = false ;
454473 return curTsBlock .getColumn (tsBlockColumnIndex ).getBinary (tsBlockIndex );
@@ -469,6 +488,9 @@ public Object getObject(String columnName) throws StatementExecutionException {
469488 private Object getObjectByTsBlockIndex (int tsBlockColumnIndex )
470489 throws StatementExecutionException {
471490 checkRecord ();
491+ if (tsBlockColumnIndex < 0 ) {
492+ throw new StatementExecutionException ("Cannot read object from time column" );
493+ }
472494 if (isNull (tsBlockColumnIndex , tsBlockIndex )) {
473495 lastReadWasNull = true ;
474496 return null ;
@@ -483,10 +505,7 @@ private Object getObjectByTsBlockIndex(int tsBlockColumnIndex)
483505 case DOUBLE :
484506 return curTsBlock .getColumn (tsBlockColumnIndex ).getObject (tsBlockIndex );
485507 case TIMESTAMP :
486- long timestamp =
487- (tsBlockColumnIndex == -1
488- ? curTsBlock .getTimeByIndex (tsBlockIndex )
489- : curTsBlock .getColumn (tsBlockColumnIndex ).getLong (tsBlockIndex ));
508+ long timestamp = curTsBlock .getColumn (tsBlockColumnIndex ).getLong (tsBlockIndex );
490509 return convertToTimestamp (timestamp , timeFactor );
491510 case TEXT :
492511 case STRING :
0 commit comments