diff --git a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java index 0f50d3c4a46..e095fd928e5 100644 --- a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java +++ b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessor.java @@ -68,7 +68,7 @@ public boolean wasNull() { } @Override - public String getString() { + public String getString() throws SQLException { final Object object = getObject(); if (object == null) { return null; @@ -78,107 +78,107 @@ public String getString() { } @Override - public boolean getBoolean() { + public boolean getBoolean() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public byte getByte() { + public byte getByte() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public short getShort() { + public short getShort() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public int getInt() { + public int getInt() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public long getLong() { + public long getLong() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public float getFloat() { + public float getFloat() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public double getDouble() { + public double getDouble() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public BigDecimal getBigDecimal() { + public BigDecimal getBigDecimal() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public BigDecimal getBigDecimal(final int i) { + public BigDecimal getBigDecimal(final int i) throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public byte[] getBytes() { + public byte[] getBytes() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public InputStream getAsciiStream() { + public InputStream getAsciiStream() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public InputStream getUnicodeStream() { + public InputStream getUnicodeStream() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public InputStream getBinaryStream() { + public InputStream getBinaryStream() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Object getObject() { + public Object getObject() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Reader getCharacterStream() { + public Reader getCharacterStream() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Object getObject(final Map> map) { + public Object getObject(final Map> map) throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Ref getRef() { + public Ref getRef() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Blob getBlob() { + public Blob getBlob() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Clob getClob() { + public Clob getClob() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Array getArray() { + public Array getArray() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Struct getStruct() { + public Struct getStruct() throws SQLException { throw getOperationNotSupported(this.getClass()); } @@ -198,34 +198,33 @@ public Timestamp getTimestamp(final Calendar calendar) throws SQLException { } @Override - public URL getURL() { + public URL getURL() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public NClob getNClob() { + public NClob getNClob() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public SQLXML getSQLXML() { + public SQLXML getSQLXML() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public String getNString() { + public String getNString() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public Reader getNCharacterStream() { + public Reader getNCharacterStream() throws SQLException { throw getOperationNotSupported(this.getClass()); } @Override - public T getObject(final Class type) { + public T getObject(final Class type) throws SQLException { final Object value; - if (type == Byte.class) { value = getByte(); } else if (type == Short.class) { @@ -249,7 +248,6 @@ public T getObject(final Class type) { } else { value = getObject(); } - return !type.isPrimitive() && wasNull ? null : type.cast(value); } } diff --git a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java index e276660cd04..0465765f183 100644 --- a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java +++ b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessor.java @@ -103,112 +103,112 @@ public boolean wasNull() { } @Override - public String getString() { + public String getString() throws SQLException { return getAccessor().getString(); } @Override - public boolean getBoolean() { + public boolean getBoolean() throws SQLException { return getAccessor().getBoolean(); } @Override - public byte getByte() { + public byte getByte() throws SQLException { return getAccessor().getByte(); } @Override - public short getShort() { + public short getShort() throws SQLException { return getAccessor().getShort(); } @Override - public int getInt() { + public int getInt() throws SQLException { return getAccessor().getInt(); } @Override - public long getLong() { + public long getLong() throws SQLException { return getAccessor().getLong(); } @Override - public float getFloat() { + public float getFloat() throws SQLException { return getAccessor().getFloat(); } @Override - public double getDouble() { + public double getDouble() throws SQLException { return getAccessor().getDouble(); } @Override - public BigDecimal getBigDecimal() { + public BigDecimal getBigDecimal() throws SQLException { return getAccessor().getBigDecimal(); } @Override - public BigDecimal getBigDecimal(int i) { + public BigDecimal getBigDecimal(int i) throws SQLException { return getAccessor().getBigDecimal(i); } @Override - public byte[] getBytes() { + public byte[] getBytes() throws SQLException { return getAccessor().getBytes(); } @Override - public InputStream getAsciiStream() { + public InputStream getAsciiStream() throws SQLException { return getAccessor().getAsciiStream(); } @Override - public InputStream getUnicodeStream() { + public InputStream getUnicodeStream() throws SQLException { return getAccessor().getUnicodeStream(); } @Override - public InputStream getBinaryStream() { + public InputStream getBinaryStream() throws SQLException { return getAccessor().getBinaryStream(); } @Override - public Object getObject() { + public Object getObject() throws SQLException { return getAccessor().getObject(); } @Override - public Reader getCharacterStream() { + public Reader getCharacterStream() throws SQLException { return getAccessor().getCharacterStream(); } @Override - public Object getObject(Map> map) { + public Object getObject(Map> map) throws SQLException { return getAccessor().getObject(map); } @Override - public Ref getRef() { + public Ref getRef() throws SQLException { return getAccessor().getRef(); } @Override - public Blob getBlob() { + public Blob getBlob() throws SQLException { return getAccessor().getBlob(); } @Override - public Clob getClob() { + public Clob getClob() throws SQLException { return getAccessor().getClob(); } @Override - public Array getArray() { + public Array getArray() throws SQLException { return getAccessor().getArray(); } @Override - public Struct getStruct() { + public Struct getStruct() throws SQLException { return getAccessor().getStruct(); } @@ -228,32 +228,32 @@ public Timestamp getTimestamp(Calendar calendar) throws SQLException { } @Override - public URL getURL() { + public URL getURL() throws SQLException { return getAccessor().getURL(); } @Override - public NClob getNClob() { + public NClob getNClob() throws SQLException { return getAccessor().getNClob(); } @Override - public SQLXML getSQLXML() { + public SQLXML getSQLXML() throws SQLException { return getAccessor().getSQLXML(); } @Override - public String getNString() { + public String getNString() throws SQLException { return getAccessor().getNString(); } @Override - public Reader getNCharacterStream() { + public Reader getNCharacterStream() throws SQLException { return getAccessor().getNCharacterStream(); } @Override - public T getObject(Class type) { + public T getObject(Class type) throws SQLException { return getAccessor().getObject(type); } } diff --git a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java index fc6d5458f0d..b81a744fffa 100644 --- a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java +++ b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessor.java @@ -106,43 +106,75 @@ public boolean getBoolean() { } @Override - public byte getByte() { - return Byte.parseByte(this.getString()); + public byte getByte() throws SQLException { + try { + return Byte.parseByte(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public short getShort() { - return Short.parseShort(this.getString()); + public short getShort() throws SQLException { + try { + return Short.parseShort(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public int getInt() { - return Integer.parseInt(this.getString()); + public int getInt() throws SQLException { + try { + return Integer.parseInt(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public long getLong() { - return Long.parseLong(this.getString()); + public long getLong() throws SQLException { + try { + return Long.parseLong(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public float getFloat() { - return Float.parseFloat(this.getString()); + public float getFloat() throws SQLException { + try { + return Float.parseFloat(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public double getDouble() { - return Double.parseDouble(this.getString()); + public double getDouble() throws SQLException { + try { + return Double.parseDouble(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public BigDecimal getBigDecimal() { - return new BigDecimal(this.getString()); + public BigDecimal getBigDecimal() throws SQLException { + try { + return new BigDecimal(this.getString()); + } catch (Exception e) { + throw new SQLException(e); + } } @Override - public BigDecimal getBigDecimal(int i) { - return BigDecimal.valueOf(this.getLong(), i); + public BigDecimal getBigDecimal(int i) throws SQLException { + try { + return BigDecimal.valueOf(this.getLong(), i); + } catch (Exception e) { + throw new SQLException(e); + } } @Override diff --git a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/utils/ExceptionTemplateThrower.java b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/utils/ExceptionTemplateThrower.java index 4156aed2e1c..7f4ab1e1651 100644 --- a/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/utils/ExceptionTemplateThrower.java +++ b/java/flight/flight-jdbc-driver/src/main/java/org/apache/arrow/driver/jdbc/utils/ExceptionTemplateThrower.java @@ -19,6 +19,8 @@ import static java.lang.String.format; +import java.sql.SQLException; + import org.apache.calcite.avatica.util.Cursor.Accessor; /** @@ -37,8 +39,8 @@ private ExceptionTemplateThrower() { * * @return the exception. */ - public static UnsupportedOperationException getOperationNotSupported(final Class type) { - return new UnsupportedOperationException( + public static SQLException getOperationNotSupported(final Class type) { + return new SQLException( format("Operation not supported for type: %s.", type.getName())); } } diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java index aab023da4b5..099b0122179 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/ArrowFlightJdbcAccessorTest.java @@ -52,7 +52,7 @@ public Class getObjectClass() { MockedArrowFlightJdbcAccessor accessor; @Test - public void testShouldGetObjectWithByteClassReturnGetByte() { + public void testShouldGetObjectWithByteClassReturnGetByte() throws SQLException { byte expected = Byte.MAX_VALUE; when(accessor.getByte()).thenReturn(expected); @@ -63,7 +63,7 @@ public void testShouldGetObjectWithByteClassReturnGetByte() { } @Test - public void testShouldGetObjectWithShortClassReturnGetShort() { + public void testShouldGetObjectWithShortClassReturnGetShort() throws SQLException { short expected = Short.MAX_VALUE; when(accessor.getShort()).thenReturn(expected); @@ -74,7 +74,7 @@ public void testShouldGetObjectWithShortClassReturnGetShort() { } @Test - public void testShouldGetObjectWithIntegerClassReturnGetInt() { + public void testShouldGetObjectWithIntegerClassReturnGetInt() throws SQLException { int expected = Integer.MAX_VALUE; when(accessor.getInt()).thenReturn(expected); @@ -85,7 +85,7 @@ public void testShouldGetObjectWithIntegerClassReturnGetInt() { } @Test - public void testShouldGetObjectWithLongClassReturnGetLong() { + public void testShouldGetObjectWithLongClassReturnGetLong() throws SQLException { long expected = Long.MAX_VALUE; when(accessor.getLong()).thenReturn(expected); @@ -96,7 +96,7 @@ public void testShouldGetObjectWithLongClassReturnGetLong() { } @Test - public void testShouldGetObjectWithFloatClassReturnGetFloat() { + public void testShouldGetObjectWithFloatClassReturnGetFloat() throws SQLException { float expected = Float.MAX_VALUE; when(accessor.getFloat()).thenReturn(expected); @@ -107,7 +107,7 @@ public void testShouldGetObjectWithFloatClassReturnGetFloat() { } @Test - public void testShouldGetObjectWithDoubleClassReturnGetDouble() { + public void testShouldGetObjectWithDoubleClassReturnGetDouble() throws SQLException { double expected = Double.MAX_VALUE; when(accessor.getDouble()).thenReturn(expected); @@ -118,7 +118,7 @@ public void testShouldGetObjectWithDoubleClassReturnGetDouble() { } @Test - public void testShouldGetObjectWithBooleanClassReturnGetBoolean() { + public void testShouldGetObjectWithBooleanClassReturnGetBoolean() throws SQLException { when(accessor.getBoolean()).thenReturn(true); when(accessor.getObject(Boolean.class)).thenCallRealMethod(); @@ -128,7 +128,7 @@ public void testShouldGetObjectWithBooleanClassReturnGetBoolean() { } @Test - public void testShouldGetObjectWithBigDecimalClassReturnGetBigDecimal() { + public void testShouldGetObjectWithBigDecimalClassReturnGetBigDecimal() throws SQLException { BigDecimal expected = BigDecimal.TEN; when(accessor.getBigDecimal()).thenReturn(expected); @@ -139,7 +139,7 @@ public void testShouldGetObjectWithBigDecimalClassReturnGetBigDecimal() { } @Test - public void testShouldGetObjectWithStringClassReturnGetString() { + public void testShouldGetObjectWithStringClassReturnGetString() throws SQLException { String expected = "STRING_VALUE"; when(accessor.getString()).thenReturn(expected); @@ -150,7 +150,7 @@ public void testShouldGetObjectWithStringClassReturnGetString() { } @Test - public void testShouldGetObjectWithByteArrayClassReturnGetBytes() { + public void testShouldGetObjectWithByteArrayClassReturnGetBytes() throws SQLException { byte[] expected = "STRING_VALUE".getBytes(StandardCharsets.UTF_8); when(accessor.getBytes()).thenReturn(expected); @@ -161,7 +161,7 @@ public void testShouldGetObjectWithByteArrayClassReturnGetBytes() { } @Test - public void testShouldGetObjectWithObjectClassReturnGetObject() { + public void testShouldGetObjectWithObjectClassReturnGetObject() throws SQLException { Object expected = new Object(); when(accessor.getObject()).thenReturn(expected); @@ -172,7 +172,7 @@ public void testShouldGetObjectWithObjectClassReturnGetObject() { } @Test - public void testShouldGetObjectWithAccessorsObjectClassReturnGetObject() { + public void testShouldGetObjectWithAccessorsObjectClassReturnGetObject() throws SQLException { Class objectClass = Long.class; when(accessor.getObject(objectClass)).thenCallRealMethod(); @@ -181,177 +181,177 @@ public void testShouldGetObjectWithAccessorsObjectClassReturnGetObject() { verify(accessor).getObject(objectClass); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBoolean() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBoolean() throws SQLException { when(accessor.getBoolean()).thenCallRealMethod(); accessor.getBoolean(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetByte() { + @Test(expected = SQLException.class) + public void testShouldFailToGetByte() throws SQLException { when(accessor.getByte()).thenCallRealMethod(); accessor.getByte(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetShort() { + @Test(expected = SQLException.class) + public void testShouldFailToGetShort() throws SQLException { when(accessor.getShort()).thenCallRealMethod(); accessor.getShort(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetInt() { + @Test(expected = SQLException.class) + public void testShouldFailToGetInt() throws SQLException { when(accessor.getInt()).thenCallRealMethod(); accessor.getInt(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetLong() { + @Test(expected = SQLException.class) + public void testShouldFailToGetLong() throws SQLException { when(accessor.getLong()).thenCallRealMethod(); accessor.getLong(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetFloat() { + @Test(expected = SQLException.class) + public void testShouldFailToGetFloat() throws SQLException { when(accessor.getFloat()).thenCallRealMethod(); accessor.getFloat(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetDouble() { + @Test(expected = SQLException.class) + public void testShouldFailToGetDouble() throws SQLException { when(accessor.getDouble()).thenCallRealMethod(); accessor.getDouble(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBigDecimal() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBigDecimal() throws SQLException { when(accessor.getBigDecimal()).thenCallRealMethod(); accessor.getBigDecimal(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBytes() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBytes() throws SQLException { when(accessor.getBytes()).thenCallRealMethod(); accessor.getBytes(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetAsciiStream() { + @Test(expected = SQLException.class) + public void testShouldFailToGetAsciiStream() throws SQLException { when(accessor.getAsciiStream()).thenCallRealMethod(); accessor.getAsciiStream(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetUnicodeStream() { + @Test(expected = SQLException.class) + public void testShouldFailToGetUnicodeStream() throws SQLException { when(accessor.getUnicodeStream()).thenCallRealMethod(); accessor.getUnicodeStream(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBinaryStream() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBinaryStream() throws SQLException { when(accessor.getBinaryStream()).thenCallRealMethod(); accessor.getBinaryStream(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetObject() { + @Test(expected = SQLException.class) + public void testShouldFailToGetObject() throws SQLException { when(accessor.getObject()).thenCallRealMethod(); accessor.getObject(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetObjectMap() { + @Test(expected = SQLException.class) + public void testShouldFailToGetObjectMap() throws SQLException { Map> map = new HashMap<>(); when(accessor.getObject(map)).thenCallRealMethod(); accessor.getObject(map); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetCharacterStream() { + @Test(expected = SQLException.class) + public void testShouldFailToGetCharacterStream() throws SQLException { when(accessor.getCharacterStream()).thenCallRealMethod(); accessor.getCharacterStream(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetRef() { + @Test(expected = SQLException.class) + public void testShouldFailToGetRef() throws SQLException { when(accessor.getRef()).thenCallRealMethod(); accessor.getRef(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBlob() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBlob() throws SQLException { when(accessor.getBlob()).thenCallRealMethod(); accessor.getBlob(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetClob() { + @Test(expected = SQLException.class) + public void testShouldFailToGetClob() throws SQLException { when(accessor.getClob()).thenCallRealMethod(); accessor.getClob(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetArray() { + @Test(expected = SQLException.class) + public void testShouldFailToGetArray() throws SQLException { when(accessor.getArray()).thenCallRealMethod(); accessor.getArray(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetStruct() { + @Test(expected = SQLException.class) + public void testShouldFailToGetStruct() throws SQLException { when(accessor.getStruct()).thenCallRealMethod(); accessor.getStruct(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetURL() { + @Test(expected = SQLException.class) + public void testShouldFailToGetURL() throws SQLException { when(accessor.getURL()).thenCallRealMethod(); accessor.getURL(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetNClob() { + @Test(expected = SQLException.class) + public void testShouldFailToGetNClob() throws SQLException { when(accessor.getNClob()).thenCallRealMethod(); accessor.getNClob(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetSQLXML() { + @Test(expected = SQLException.class) + public void testShouldFailToGetSQLXML() throws SQLException { when(accessor.getSQLXML()).thenCallRealMethod(); accessor.getSQLXML(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetNString() { + @Test(expected = SQLException.class) + public void testShouldFailToGetNString() throws SQLException { when(accessor.getNString()).thenCallRealMethod(); accessor.getNString(); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetNCharacterStream() { + @Test(expected = SQLException.class) + public void testShouldFailToGetNCharacterStream() throws SQLException { when(accessor.getNCharacterStream()).thenCallRealMethod(); accessor.getNCharacterStream(); } - @Test(expected = UnsupportedOperationException.class) + @Test(expected = SQLException.class) public void testShouldFailToGetDate() throws SQLException { when(accessor.getDate(null)).thenCallRealMethod(); accessor.getDate(null); } - @Test(expected = UnsupportedOperationException.class) + @Test(expected = SQLException.class) public void testShouldFailToGetTime() throws SQLException { when(accessor.getTime(null)).thenCallRealMethod(); accessor.getTime(null); } - @Test(expected = UnsupportedOperationException.class) + @Test(expected = SQLException.class) public void testShouldFailToGetTimestamp() throws SQLException { when(accessor.getTimestamp(null)).thenCallRealMethod(); accessor.getTimestamp(null); } - @Test(expected = UnsupportedOperationException.class) - public void testShouldFailToGetBigDecimalWithValue() { + @Test(expected = SQLException.class) + public void testShouldFailToGetBigDecimalWithValue() throws SQLException { when(accessor.getBigDecimal(0)).thenCallRealMethod(); accessor.getBigDecimal(0); } diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java index c6ed42ba9d6..2b53b27dc9e 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/AbstractArrowFlightJdbcUnionVectorAccessorTest.java @@ -39,33 +39,8 @@ @RunWith(MockitoJUnitRunner.class) public class AbstractArrowFlightJdbcUnionVectorAccessorTest { - private static class AbstractArrowFlightJdbcUnionVectorAccessorMock - extends AbstractArrowFlightJdbcUnionVectorAccessor { - protected AbstractArrowFlightJdbcUnionVectorAccessorMock() { - super(() -> 0, (boolean wasNull) -> { - }); - } - - @Override - protected ArrowFlightJdbcAccessor createAccessorForVector(ValueVector vector) { - return new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> { - }); - } - - @Override - protected byte getCurrentTypeId() { - return 0; - } - - @Override - protected ValueVector getVectorByTypeId(byte typeId) { - return new NullVector(); - } - } - @Mock ArrowFlightJdbcAccessor innerAccessor; - @Spy AbstractArrowFlightJdbcUnionVectorAccessorMock accessor; @@ -75,145 +50,145 @@ public void setup() { } @Test - public void testGetNCharacterStreamUsesSpecificAccessor() { + public void testGetNCharacterStreamUsesSpecificAccessor() throws SQLException { accessor.getNCharacterStream(); verify(innerAccessor).getNCharacterStream(); } @Test - public void testGetNStringUsesSpecificAccessor() { + public void testGetNStringUsesSpecificAccessor() throws SQLException { accessor.getNString(); verify(innerAccessor).getNString(); } @Test - public void testGetSQLXMLUsesSpecificAccessor() { + public void testGetSQLXMLUsesSpecificAccessor() throws SQLException { accessor.getSQLXML(); verify(innerAccessor).getSQLXML(); } @Test - public void testGetNClobUsesSpecificAccessor() { + public void testGetNClobUsesSpecificAccessor() throws SQLException { accessor.getNClob(); verify(innerAccessor).getNClob(); } @Test - public void testGetURLUsesSpecificAccessor() { + public void testGetURLUsesSpecificAccessor() throws SQLException { accessor.getURL(); verify(innerAccessor).getURL(); } @Test - public void testGetStructUsesSpecificAccessor() { + public void testGetStructUsesSpecificAccessor() throws SQLException { accessor.getStruct(); verify(innerAccessor).getStruct(); } @Test - public void testGetArrayUsesSpecificAccessor() { + public void testGetArrayUsesSpecificAccessor() throws SQLException { accessor.getArray(); verify(innerAccessor).getArray(); } @Test - public void testGetClobUsesSpecificAccessor() { + public void testGetClobUsesSpecificAccessor() throws SQLException { accessor.getClob(); verify(innerAccessor).getClob(); } @Test - public void testGetBlobUsesSpecificAccessor() { + public void testGetBlobUsesSpecificAccessor() throws SQLException { accessor.getBlob(); verify(innerAccessor).getBlob(); } @Test - public void testGetRefUsesSpecificAccessor() { + public void testGetRefUsesSpecificAccessor() throws SQLException { accessor.getRef(); verify(innerAccessor).getRef(); } @Test - public void testGetCharacterStreamUsesSpecificAccessor() { + public void testGetCharacterStreamUsesSpecificAccessor() throws SQLException { accessor.getCharacterStream(); verify(innerAccessor).getCharacterStream(); } @Test - public void testGetBinaryStreamUsesSpecificAccessor() { + public void testGetBinaryStreamUsesSpecificAccessor() throws SQLException { accessor.getBinaryStream(); verify(innerAccessor).getBinaryStream(); } @Test - public void testGetUnicodeStreamUsesSpecificAccessor() { + public void testGetUnicodeStreamUsesSpecificAccessor() throws SQLException { accessor.getUnicodeStream(); verify(innerAccessor).getUnicodeStream(); } @Test - public void testGetAsciiStreamUsesSpecificAccessor() { + public void testGetAsciiStreamUsesSpecificAccessor() throws SQLException { accessor.getAsciiStream(); verify(innerAccessor).getAsciiStream(); } @Test - public void testGetBytesUsesSpecificAccessor() { + public void testGetBytesUsesSpecificAccessor() throws SQLException { accessor.getBytes(); verify(innerAccessor).getBytes(); } @Test - public void testGetBigDecimalUsesSpecificAccessor() { + public void testGetBigDecimalUsesSpecificAccessor() throws SQLException { accessor.getBigDecimal(); verify(innerAccessor).getBigDecimal(); } @Test - public void testGetDoubleUsesSpecificAccessor() { + public void testGetDoubleUsesSpecificAccessor() throws SQLException { accessor.getDouble(); verify(innerAccessor).getDouble(); } @Test - public void testGetFloatUsesSpecificAccessor() { + public void testGetFloatUsesSpecificAccessor() throws SQLException { accessor.getFloat(); verify(innerAccessor).getFloat(); } @Test - public void testGetLongUsesSpecificAccessor() { + public void testGetLongUsesSpecificAccessor() throws SQLException { accessor.getLong(); verify(innerAccessor).getLong(); } @Test - public void testGetIntUsesSpecificAccessor() { + public void testGetIntUsesSpecificAccessor() throws SQLException { accessor.getInt(); verify(innerAccessor).getInt(); } @Test - public void testGetShortUsesSpecificAccessor() { + public void testGetShortUsesSpecificAccessor() throws SQLException { accessor.getShort(); verify(innerAccessor).getShort(); } @Test - public void testGetByteUsesSpecificAccessor() { + public void testGetByteUsesSpecificAccessor() throws SQLException { accessor.getByte(); verify(innerAccessor).getByte(); } @Test - public void testGetBooleanUsesSpecificAccessor() { + public void testGetBooleanUsesSpecificAccessor() throws SQLException { accessor.getBoolean(); verify(innerAccessor).getBoolean(); } @Test - public void testGetStringUsesSpecificAccessor() { + public void testGetStringUsesSpecificAccessor() throws SQLException { accessor.getString(); verify(innerAccessor).getString(); } @@ -225,7 +200,7 @@ public void testGetObjectClassUsesSpecificAccessor() { } @Test - public void testGetObjectWithClassUsesSpecificAccessor() { + public void testGetObjectWithClassUsesSpecificAccessor() throws SQLException { accessor.getObject(Object.class); verify(innerAccessor).getObject(Object.class); } @@ -252,15 +227,39 @@ public void testGetDateUsesSpecificAccessor() throws SQLException { } @Test - public void testGetObjectUsesSpecificAccessor() { + public void testGetObjectUsesSpecificAccessor() throws SQLException { Map> map = mock(Map.class); accessor.getObject(map); verify(innerAccessor).getObject(map); } @Test - public void testGetBigDecimalWithScaleUsesSpecificAccessor() { + public void testGetBigDecimalWithScaleUsesSpecificAccessor() throws SQLException { accessor.getBigDecimal(2); verify(innerAccessor).getBigDecimal(2); } + + private static class AbstractArrowFlightJdbcUnionVectorAccessorMock + extends AbstractArrowFlightJdbcUnionVectorAccessor { + protected AbstractArrowFlightJdbcUnionVectorAccessorMock() { + super(() -> 0, (boolean wasNull) -> { + }); + } + + @Override + protected ArrowFlightJdbcAccessor createAccessorForVector(ValueVector vector) { + return new ArrowFlightJdbcNullVectorAccessor((boolean wasNull) -> { + }); + } + + @Override + protected byte getCurrentTypeId() { + return 0; + } + + @Override + protected ValueVector getVectorByTypeId(byte typeId) { + return new NullVector(); + } + } } diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java index 07ce5ddb4a4..b3c85fc0ab1 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/complex/ArrowFlightJdbcStructVectorAccessorTest.java @@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.nullValue; +import java.sql.SQLException; import java.sql.Struct; import java.util.HashMap; import java.util.Map; @@ -146,7 +147,7 @@ public void testShouldGetStructReturnNull() throws Exception { } @Test - public void testShouldGetObjectWorkWithNestedComplexData() { + public void testShouldGetObjectWorkWithNestedComplexData() throws SQLException { try (StructVector rootVector = StructVector.empty("", rootAllocatorTestRule.getRootAllocator())) { StructVector structVector = rootVector.addOrGetStruct("struct"); diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java index fb7ea2abc94..f7a21a92ccb 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/numeric/ArrowFlightJdbcBitVectorAccessorTest.java @@ -21,7 +21,6 @@ import static org.hamcrest.CoreMatchers.is; import java.math.BigDecimal; -import java.util.function.Function; import org.apache.arrow.driver.jdbc.utils.AccessorTestUtils; import org.apache.arrow.driver.jdbc.utils.RootAllocatorTestRule; @@ -64,7 +63,7 @@ public void tearDown() { this.vectorWithNull.close(); } - private void iterate(final Function function, + private void iterate(final AccessorTestUtils.CheckedFunction function, final T result, final T resultIfFalse, final BitVector vector) throws Exception { accessorIterator.assertAccessorGetter(vector, function, diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java index 57ba9720037..d28c6c508e4 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/accessor/impl/text/ArrowFlightJdbcVarCharVectorAccessorTest.java @@ -118,7 +118,7 @@ public void testShouldGetByteThrowsExceptionForNonNumericValue() throws Exceptio Text value = new Text("Invalid value for byte."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getByte(); } @@ -127,7 +127,7 @@ public void testShouldGetByteThrowsExceptionForOutOfRangePositiveValue() throws Text value = new Text("128"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getByte(); } @@ -136,7 +136,7 @@ public void testShouldGetByteThrowsExceptionForOutOfRangeNegativeValue() throws Text value = new Text("-129"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getByte(); } @@ -167,7 +167,7 @@ public void testShouldGetShortThrowsExceptionForNonNumericValue() throws Excepti Text value = new Text("Invalid value for short."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getShort(); } @@ -176,7 +176,7 @@ public void testShouldGetShortThrowsExceptionForOutOfRangePositiveValue() throws Text value = new Text("32768"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getShort(); } @@ -185,7 +185,7 @@ public void testShouldGetShortThrowsExceptionForOutOfRangeNegativeValue() throws Text value = new Text("-32769"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getShort(); } @@ -216,7 +216,7 @@ public void testShouldGetIntThrowsExceptionForNonNumericValue() throws Exception Text value = new Text("Invalid value for int."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getInt(); } @@ -225,7 +225,7 @@ public void testShouldGetIntThrowsExceptionForOutOfRangePositiveValue() throws E Text value = new Text("2147483648"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getInt(); } @@ -234,7 +234,7 @@ public void testShouldGetIntThrowsExceptionForOutOfRangeNegativeValue() throws E Text value = new Text("-2147483649"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getInt(); } @@ -265,7 +265,7 @@ public void testShouldGetLongThrowsExceptionForNonNumericValue() throws Exceptio Text value = new Text("Invalid value for long."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getLong(); } @@ -274,7 +274,7 @@ public void testShouldGetLongThrowsExceptionForOutOfRangePositiveValue() throws Text value = new Text("9223372036854775808"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getLong(); } @@ -283,7 +283,7 @@ public void testShouldGetLongThrowsExceptionForOutOfRangeNegativeValue() throws Text value = new Text("-9223372036854775809"); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getLong(); } @@ -309,12 +309,21 @@ public void testShouldGetLongReturnValidNegativeLong() throws Exception { collector.checkThat(result, equalTo(-9223372036854775808L)); } + @Test + public void testShouldBigDecimalWithParametersThrowsExceptionForNonNumericValue() throws Exception { + Text value = new Text("Invalid value for BigDecimal."); + when(getter.get(0)).thenReturn(value); + + thrown.expect(SQLException.class); + accessor.getBigDecimal(1); + } + @Test public void testShouldGetBigDecimalThrowsExceptionForNonNumericValue() throws Exception { Text value = new Text("Invalid value for BigDecimal."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getBigDecimal(); } @@ -345,7 +354,7 @@ public void testShouldGetDoubleThrowsExceptionForNonNumericValue() throws Except Text value = new Text("Invalid value for double."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getDouble(); } @@ -409,7 +418,7 @@ public void testShouldGetFloatThrowsExceptionForNonNumericValue() throws Excepti Text value = new Text("Invalid value for float."); when(getter.get(0)).thenReturn(value); - thrown.expect(IllegalArgumentException.class); + thrown.expect(SQLException.class); accessor.getFloat(); } diff --git a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java index 4705390205d..03e42c69f40 100644 --- a/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java +++ b/java/flight/flight-jdbc-driver/src/test/java/org/apache/arrow/driver/jdbc/utils/AccessorTestUtils.java @@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.is; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; @@ -32,8 +33,13 @@ import org.junit.rules.ErrorCollector; public class AccessorTestUtils { + @FunctionalInterface + public interface CheckedFunction { + R apply(T t) throws SQLException; + } public static class Cursor { + int currentRow = 0; int limit; @@ -103,7 +109,7 @@ public List toList(ValueVector vector) throws Exception { return result; } - public void assertAccessorGetter(ValueVector vector, Function getter, + public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, MatcherGetter matcherGetter) throws Exception { iterate(vector, (accessor, currentRow) -> { @@ -115,19 +121,19 @@ public void assertAccessorGetter(ValueVector vector, Function getter, }); } - public void assertAccessorGetter(ValueVector vector, Function getter, + public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, Function> matcherGetter) throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcherGetter.apply(accessor)); } - public void assertAccessorGetter(ValueVector vector, Function getter, + public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, Supplier> matcherGetter) throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcherGetter.get()); } - public void assertAccessorGetter(ValueVector vector, Function getter, + public void assertAccessorGetter(ValueVector vector, CheckedFunction getter, Matcher matcher) throws Exception { assertAccessorGetter(vector, getter, (accessor, currentRow) -> matcher);