final File query = File.createTempFile("hive", ".q");
try (PrintWriter pw = new PrintWriter(query, "UTF-8")) {
pw.println("select count(*) from counters where dateint=20120430 and hour=10;");
}
final Set<FileAttachment> attachments = new HashSet<>();
final FileAttachment attachment = new FileAttachment();
attachment.setName("hive.q");
FileInputStream fin = null;
ByteArrayOutputStream bos = null;
try {
fin = new FileInputStream(query);
bos = new ByteArrayOutputStream();
final byte[] buf = new byte[4096];
int read;
while ((read = fin.read(buf)) != -1) {
bos.write(buf, 0, read);
}
attachment.setData(bos.toByteArray());
} finally {
if (fin != null) {
fin.close();
}
if (bos != null) {