diff --git a/src/main/java/org/polypheny/jdbc/multimodel/PolyStatement.java b/src/main/java/org/polypheny/jdbc/multimodel/PolyStatement.java index acb6f6f..2e2236c 100644 --- a/src/main/java/org/polypheny/jdbc/multimodel/PolyStatement.java +++ b/src/main/java/org/polypheny/jdbc/multimodel/PolyStatement.java @@ -123,6 +123,7 @@ public List execute( String namespaceName, String languageName, List parameters = new ArrayList<>( 2 ); parameters.add( TypedValue.fromInteger( 1 ) ); parameters.add( TypedValue.fromBytes( expected ) ); Result result = polyStatement.executePrepared( parameters ); result.unwrap( ScalarResult.class ); - //RelationalResult result = polyStatement.execute( "public", "sql", QUERY ).unwrap( RelationalResult.class ); - //byte[] received = result.iterator().next().get( "data" ).asBytes(); + RelationalResult result2 = polyStatement.execute( "public", "sql", QUERY ).unwrap( RelationalResult.class ); + InputStream bis = result2.iterator().next().get( "data" ).asBlob().getBinaryStream(); + byte[] received = collectStream( bis ); - //Assertions.assertEquals( expected, received ); - Assertions.assertTrue(true); - } catch ( SQLException e ) { + Assertions.assertArrayEquals( expected, received ); + } catch ( SQLException | IOException e ) { throw new RuntimeException( e ); } } + private byte[] collectStream( InputStream inputStream ) throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int frameLength; + byte[] frame = new byte[300 * 1024 * 1024]; + while ( (frameLength = inputStream.read( frame, 0, frame.length )) != -1 ) { + buffer.write( frame, 0, frameLength ); + } + buffer.flush(); + return buffer.toByteArray(); + } + + private static byte[] createTestData() { final int TOTAL_BYTES = 300 * 1024 * 1024; final int SIZE = 4;