Wednesday, August 11, 2010

Blob Streaming (PBMS) support in drizzle jdbc

I just pushed up initial support for PBMS, blob streaming for drizzle jdbc. It is not yet a complete solution for blob streaming, but you can use setBinaryStream and getBinaryStream to stream data to/from Drizzle and MySQL.

To use it, grab a snapshot from hudson (the reason the tests fail is that i have not had time to rewrite INFORMATION_SCHEMA queries to support the new I_S in Drizzle). Then follow this example to get started, important stuff is in bold

Connection connection = 
// inserting a blob:
Statement stmt = connection.createStatement();
stmt.execute("create table bstreaming1 (id int not null primary key auto_increment, test longblob)");
PreparedStatement ps = connection.prepareStatement("insert into bstreaming1 values (null, ?)");
// fake an inputstream with data:
ByteArrayInputStream bais = new ByteArrayInputStream("HEJHEJHEJ".getBytes());
ps.setBinaryStream(1, bais);
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select * from bstreaming1");
assertEquals(, true);
byte[] b = new byte[100];
int l = rs.getBinaryStream("test").read(b);
assertEquals("HEJHEJHEJ",new String(b,0,l));

To get PBMS support in drizzle you need to have a fairly recent build, and start the daemon with --plugin_add=pbms. InnoDB tables are streaming enabled, which means that any LONGBLOB column will be streamed.

Note that in the current version you will get the blob reference and not a String representation of the blob if you do a getString on the column for example, this will change when I get time to do it.

I have not yet tested against MySQL, if you have a PBMS enabled MySQL server, please let me know if it works!


Jobin said...

Great Job!.
Happy to see the huge development happening around Drizzle making it a powerful / adaptable Database.

Thanks you for this post.

Paul McCullagh said...

Hi Marcus,

Excellent work! I implemented something similar for PBMS in the MySQL JDBC driver a couple of years ago.

But the implementation died because it was never accepted into the official release.

The fact that Drizzle does not have these barriers is much appreciated!