@@ -457,7 +457,7 @@ Boolean getBoolean(int idx) throws SQLException {
457457
458458 protected ByteBuffer getbuf (int idx , int typeWidth ) {
459459 ByteBuffer buf = constlen_data ;
460- buf .order (ByteOrder .LITTLE_ENDIAN );
460+ buf .order (ByteOrder .nativeOrder () );
461461 buf .position (idx * typeWidth );
462462 return buf ;
463463 }
@@ -505,9 +505,7 @@ short getUint8(int idx) throws SQLException {
505505 return 0 ;
506506 }
507507 if (isType (DuckDBColumnType .UTINYINT )) {
508- ByteBuffer buf = ByteBuffer .allocate (2 );
509- getbuf (idx , 1 ).get (buf .array (), 1 , 1 );
510- return buf .getShort ();
508+ return (short ) Byte .toUnsignedInt (getbuf (idx , 1 ).get ());
511509 }
512510 throw new SQLFeatureNotSupportedException ("getUint8" );
513511 }
@@ -517,10 +515,7 @@ long getUint32(int idx) throws SQLException {
517515 return 0 ;
518516 }
519517 if (isType (DuckDBColumnType .UINTEGER )) {
520- ByteBuffer buf = ByteBuffer .allocate (8 );
521- buf .order (ByteOrder .LITTLE_ENDIAN );
522- getbuf (idx , 4 ).get (buf .array (), 0 , 4 );
523- return buf .getLong ();
518+ return Integer .toUnsignedLong (getbuf (idx , 4 ).getInt ());
524519 }
525520 throw new SQLFeatureNotSupportedException ("getUint32" );
526521 }
@@ -530,10 +525,7 @@ int getUint16(int idx) throws SQLException {
530525 return 0 ;
531526 }
532527 if (isType (DuckDBColumnType .USMALLINT )) {
533- ByteBuffer buf = ByteBuffer .allocate (4 );
534- buf .order (ByteOrder .LITTLE_ENDIAN );
535- getbuf (idx , 2 ).get (buf .array (), 0 , 2 );
536- return buf .getInt ();
528+ return Short .toUnsignedInt (getbuf (idx , 2 ).getShort ());
537529 }
538530 throw new SQLFeatureNotSupportedException ("getUint16" );
539531 }
@@ -543,13 +535,10 @@ BigInteger getUint64(int idx) throws SQLException {
543535 return BigInteger .ZERO ;
544536 }
545537 if (isType (DuckDBColumnType .UBIGINT )) {
546- byte [] buf_res = new byte [16 ];
547- byte [] buf = new byte [8 ];
548- getbuf (idx , 8 ).get (buf );
549- for (int i = 0 ; i < 8 ; i ++) {
550- buf_res [i + 8 ] = buf [7 - i ];
551- }
552- return new BigInteger (buf_res );
538+ byte [] buf_res = new byte [8 ];
539+ long value = getbuf (idx , 8 ).getLong ();
540+ ByteBuffer .wrap (buf_res ).putLong (value );
541+ return new BigInteger (1 , buf_res );
553542 }
554543 throw new SQLFeatureNotSupportedException ("getUint64" );
555544 }
@@ -601,14 +590,12 @@ BigInteger getHugeint(int idx) throws SQLException {
601590 return BigInteger .ZERO ;
602591 }
603592 if (isType (DuckDBColumnType .HUGEINT )) {
604- byte [] buf = new byte [16 ];
605- getbuf (idx , 16 ).get (buf );
606- for (int i = 0 ; i < 8 ; i ++) {
607- byte keep = buf [i ];
608- buf [i ] = buf [15 - i ];
609- buf [15 - i ] = keep ;
610- }
611- return new BigInteger (buf );
593+ byte [] buf_res = new byte [16 ];
594+ ByteBuffer buf = getbuf (idx , 16 );
595+ long lower = buf .getLong ();
596+ long upper = buf .getLong ();
597+ ByteBuffer .wrap (buf_res ).putLong (upper ).putLong (lower );
598+ return new BigInteger (buf_res );
612599 }
613600 Object o = getObject (idx );
614601 return new BigInteger (o .toString ());
@@ -619,14 +606,12 @@ BigInteger getUhugeint(int idx) throws SQLException {
619606 return BigInteger .ZERO ;
620607 }
621608 if (isType (DuckDBColumnType .UHUGEINT )) {
622- byte [] buf = new byte [16 ];
623- getbuf (idx , 16 ).get (buf );
624- for (int i = 0 ; i < 8 ; i ++) {
625- byte keep = buf [i ];
626- buf [i ] = buf [15 - i ];
627- buf [15 - i ] = keep ;
628- }
629- return new BigInteger (1 , buf );
609+ byte [] buf_res = new byte [16 ];
610+ ByteBuffer buf = getbuf (idx , 16 );
611+ long lower = buf .getLong ();
612+ long upper = buf .getLong ();
613+ ByteBuffer .wrap (buf_res ).putLong (upper ).putLong (lower );
614+ return new BigInteger (1 , buf_res );
630615 }
631616 Object o = getObject (idx );
632617 return new BigInteger (o .toString ());
0 commit comments