azkaban mysql参数_mysql + Azkaban:阅读“LongBlob”

本文介绍了如何在Azkaban中查询包含LongBlob类型数据的数据库记录。通过建立数据库连接,执行SQL查询,解压GZIP压缩的数据并转换为字符串,展示了具体的实现过程。
摘要由CSDN通过智能技术生成

所以在经过大量挖掘azkaban之后,我发现这就是人们应该如何在azkaban-Database中查询LongBlobs:

public String getErrorLog(){

String returnString = "";

try {

Connection conn = AzkabanClient.getPhoenixConnection(conf);

String s = " select exec_id, enc_type, log from execution_logs where exec_id = 3964 and name = 'http-time-series-hourly' ";

PreparedStatement pstmt = conn.prepareStatement(s);

ResultSet rs = pstmt.executeQuery();

while (rs.next()) {

int i = rs.getInt("exec_id");

ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

EncodingType encType = EncodingType.fromInteger(rs.getInt("enc_type"));

int debug = 0;

byte[] data = rs.getBytes("log");

try {

byte[] buffer = data;

ByteArrayOutputStream byteArrayOutputStream = null;

if (encType == EncodingType.GZIP) {

byteArrayOutputStream = GZIPUtils.unGzipBytesOutputStream(data);

}

returnString = new String(byteArrayOutputStream.toByteArray(), "UTF-8");

} catch (IOException e) {

throw new SQLException(e);

}

}

conn.close();

} catch (Exception e) {

LOGGER.error("Error =>" + e);

}

return returnString;

}其中:

GZIPUtils是:

public class GZIPUtils {

public static ByteArrayOutputStream unGzipBytesOutputStream(byte[] bytes) throws IOException {

ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);

GZIPInputStream gzipInputStream = new GZIPInputStream(byteInputStream);

ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();

IOUtils.copy(gzipInputStream, byteOutputStream);

return byteOutputStream;

}

}和EncodingType:

public static enum EncodingType {

PLAIN(1), GZIP(2);

private int numVal;

EncodingType(int numVal) {

this.numVal = numVal;

}

public int getNumVal() {

return numVal;

}

public static EncodingType fromInteger(int x) {

switch (x) {

case 1:

return PLAIN;

case 2:

return GZIP;

default:

return PLAIN;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值