Python 如何理解ApacheImpala的zlib压缩查询配置文件

Python 如何理解ApacheImpala的zlib压缩查询配置文件,python,hadoop,cloudera,impala,impyla,Python,Hadoop,Cloudera,Impala,Impyla,Impala当前将查询配置文件日志保存在/var/log/Impala/profiles,每行的格式为 <Epoch-Timestamp> <QueryID> <zlib-compressed-data> 上面的Python实用程序提供了以下输出,其中包含一些有意义的信息,但并不完整 b'\x19<\x18,Query (id=c94ef1f2e35015a2:feb1867165d545a7)\x15\x04\x19,\x18\x11Inactive

Impala当前将查询配置文件日志保存在/var/log/Impala/profiles,每行的格式为

<Epoch-Timestamp> <QueryID> <zlib-compressed-data>
上面的Python实用程序提供了以下输出,其中包含一些有意义的信息,但并不完整

b'\x19<\x18,Query (id=c94ef1f2e35015a2:feb1867165d545a7)\x15\x04\x19,\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x00\x19\x08\x1b\x00\x00\x18\x07Summary\x15\x00\x19,\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x11\x88\x0eConnected User\x04root\x0bCoordinator\x19quickstart.cloudera:22000\x08DDL Type\x0cCREATE_TABLE\nDefault Db\x0bexperiments\x0eDelegated User\x00\x08End Time\x1d2020-04-17 03:10:56.764883000\x0eImpala VersionWimpalad version 2.5.0-cdh5.7.0 RELEASE (build ad3f5adabedf56fe6bd9eea39147c067cc552703)\x0fNetwork Address\x0f127.0.0.1:33152\x1bQuery Options (non default)\x00\x0bQuery State\x08FINISHED\x0cQuery Status\x02OK\nQuery Type\x03DDL\nSession ID!9540492d44759bbf:90f082030ba231ae\x0cSession Type\x07BEESWAX\rSql Statement\x17create table t1 (x int)\nStart Time\x1d2020-04-17 03:10:56.417452000\x04User\x04root\x19\xf8\x11\nSession ID\x0cSession Type\nStart Time\x08End Time\nQuery Type\x0bQuery State\x0cQuery Status\x0eImpala Version\x04User\x0eConnected User\x0eDelegated User\x0fNetwork Address\nDefault Db\rSql Statement\x0bCoordinator\x1bQuery Options (non default)\x08DDL Type\x1b\x00\x19,\x18\x00\x19\x06\x19\x08\x00\x18\x0eQuery Timeline\x19V\x00\xec\x93\xe0U\x98\x9c\xc5\xc8\x02\xae\xda\xcd\xca\x02\xae\xda\xcd\xca\x02\x19X\x0fStart execution\x11Planning finished\x10Request finished\x11First row fetched\x10Unregister query\x00\x00\x18\x0cImpalaServer\x15\x00\x19\\\x18\x12CatalogOpExecTimer\x15\n\x16\xc4\xd1\xba\xe8\x01\x00\x18\x14ClientFetchWaitTimer\x15\n\x16\x96\xbe\x88\x02\x00\x18\x11InactiveTotalTime\x15\n\x16\x00\x00\x18\x17RowMaterializationTimer\x15\n\x16\x00\x00\x18\tTotalTime\x15\n\x16\x00\x00\x16\x01\x11\x1b\x00\x19\x08\x1b\x01\x8a\x008\x12CatalogOpExecTimer\x14ClientFetchWaitTimer\x17RowMaterializationTimer\x00\x00'


b'\x19Upd.编辑以包含源代码和一些注释

我猜这就是您正在寻找的脚本(取自Impala Git):

基本上,它做的事情和你在代码片段中做的一样,但它也会在之后破译特定于节俭的编码。“thrift”代表Apache thrift本身的库(Apache thrift和中的更多信息),RuntimeProfile是Impala的结构定义(您可以在中查看),其中包含节点和脚本执行摘要:

    // A flattened tree of runtime profiles, obtained by an
    // pre-order traversal
    struct TRuntimeProfileTree {
      1: required list<TRuntimeProfileNode> nodes
      2: optional ExecStats.TExecSummary exec_summary
    }
“base”表示将返回给您的树及其所有节点和子节点。因此,从现在开始有两种选择:

  • 浏览黑斑羚代码;似乎所有必要的定义都存储在Git的这一部分中;复制他们的逻辑是可能的
  • 从“protocol_factory.getProtocol(transport)”中编写定制的“反序列化”和调试输出,以定义“base”树(同样:在Impala源代码中查找必要的节点可能更容易一些)

  • 这可能会帮助其他人遇到这个问题。ApacheImpala存储库中有一个解析运行时概要文件日志的示例脚本,这是一个开始构建您自己的工具的好地方。它被绑定到Impala开发环境中——具体来说,它需要编译thrift定义并从中生成Python,这需要一个工作的开发环境。在撰写本文时,您可以通过签出Impala并设置部分环境来实现这一点:

    git clone https://github.com/apache/impala.git
    cd impala
    . bin/impala-config.sh
    ./bin/bootstrap_toolchain.py
    ./buildall.sh -cmake_only -noclean
    make thrift-deps
    ./bin/parse-thrift-profile.py ./impala_profile_log_1.1-1594189561854
    

    只是一个指针:Impala源代码在git上,并尝试遵循压缩逻辑。但是,通过REST从运行查询的impalad/coordinator获得您想要的任何细节不是更容易吗?https://:25000/query_profile?query_id=@mazaneicha,而rest很简单,但API端口已被阻止,因此只能选择解析文件。请将脚本代码直接发布到您的answer@Vladimir-yurev,感谢您的建议,存储库使用了“RuntimeProfile”库,不知何故我无法找到或构建它。当我努力找出如何获得“RuntimeProfile”时。如果你熟悉这个项目,你的帮助将是非常可观的。编辑原稿;希望能有帮助。
        // A flattened tree of runtime profiles, obtained by an
        // pre-order traversal
        struct TRuntimeProfileTree {
          1: required list<TRuntimeProfileNode> nodes
          2: optional ExecStats.TExecSummary exec_summary
        }
    
        def deserialize(base,
                buf,
                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
          transport = TTransport.TMemoryBuffer(buf)
          protocol = protocol_factory.getProtocol(transport)
          base.read(protocol)
          return base
    
    git clone https://github.com/apache/impala.git
    cd impala
    . bin/impala-config.sh
    ./bin/bootstrap_toolchain.py
    ./buildall.sh -cmake_only -noclean
    make thrift-deps
    ./bin/parse-thrift-profile.py ./impala_profile_log_1.1-1594189561854