当前位置: 首页 > 知识库问答 >
问题:

mysql+Azkaban:阅读“longblob”

钱承允
2023-03-14
select exec_id, CONVERT(log USING latin1)from execution_logs
try {
    Connection conn = AzkabanClient.getPhoenixConnection(conf);
    String s = " select exec_id,  log from execution_logs ";
    PreparedStatement pstmt = conn.prepareStatement(s);
    ResultSet rs = pstmt.executeQuery();
    String logString="";
    while(rs.next()){
        int i = rs.getInt("exec_id");
        InputStream inputStream = rs.getBinaryStream("log");
        java.io.BufferedReader in = new BufferedReader(new java.io.InputStreamReader(inputStream));
        String str;
        while ((str = in.readLine()) != null) {
            logString += str;
        }
        inputStream.close();
    }
    conn.close();
}catch(Exception e){
    LOGGER.error("Error =>" + e);
}
logString = "‹Å\]Ç•}^ÿ>°]ÕÕÝUzY‰”Uà8Žììbg¦¥..."

我尝试这样修改查询:

“选择exec_id,从execution_logs中转换(log using latin1)”

但还是同样的问题。

共有1个答案

魏俊茂
2023-03-14

因此,在深入研究了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;
}
}
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;
        }
    }
}
 类似资料:
  • Azkaban是个简单的批处理调度器,用来构建和运行Hadoop作业或其他脱机过程。 特性: 兼容所有版本的 Hadoop 基于 Web 的易用 UI 简单的 Web 和 HTTP 工作流上传 项目工作空间 工作流调度 模块化和插件化 支持认证和授权 可跟踪用户行为 失败和成功时的邮件提醒 SLA 警告和自动终止 失败作业的重试

  • 我有以下类,它从/到包裹读取和写入对象数组: 在上面的代码中,我在读取< code>readParcelableArray时得到一个< code>ClassCastException: 错误/AndroidRuntime(5880):原因:Java . lang . classcastexception:[land roid . OS . parcelable; 上面的代码有什么错误?在编写对象数

  • 在问题[1]中,我了解到如果您想在Android下使用NFC标签,则不必采用NDEF格式。我想在Win 8.1 in. Net下执行此操作。我的情况是这样的: 我有一个RFID卡Mifare Classic 1K,其中存储了一个ID。(由制造商记录)该ID由我们的考勤系统通过通常的RFID读取器(例如Gigatek的PROMAG MFR120)读取。我们不在卡上写任何东西,我们只需要读取ID。但是

  • 一、Azkaban 介绍 1.1 背景 一个完整的大数据分析系统,必然由很多任务单元 (如数据收集、数据清洗、数据存储、数据分析等) 组成,所有的任务单元及其之间的依赖关系组成了复杂的工作流。复杂的工作流管理涉及到很多问题: 如何定时调度某个任务? 如何在某个任务执行完成后再去执行另一个任务? 如何在任务失败时候发出预警? ...... 面对这些问题,工作流调度系统应运而生。Azkaban 就是其

  • 我是新来的,我正在学习使用方法等等,我在方法中有我的代码,但在代码中有一个控制台。ReadLine();这是我不想要的。基本上,我需要做的是一个包含10个方法的大作业,作为输入,你必须调用哪个方法,然后调用实际的输入,但是当我的方法中有一个readline时,我必须给出3个,而不是2个。如果有人知道如何帮助noob,我的代码如下 基本上是int.parse(consolereadline);我需要

  • About July的新书《编程之法:面试和算法心得》纸质版在本github上的基础上做了极大彻底的改进、优化,无论是完整度、还是最新度、或质量上,都远非博客、github所能相比。换言之,新书《编程之法》的质量远高于博客、github。 此外,散落在网上其他任何地方的“编程之法”电子材料均是盗版自本github,更无质量可言。所以,July只唯一推荐《编程之法》纸质版。 《编程之法》纸质版已于2