Impala是Cloudera提供的?款开源的针对HDFS和HBASE中的PB级别数据进?交互式实时查询(Impala 速度快),Impala是参照?歌的新三篇论?当中的Dremel实现?来,其中旧三篇论?分别是 (BigTable,GFS,MapReduce)分别对应我们即将学的HBase和已经学过的HDFS以及MapReduce。
Impala最?卖点和最?特点就是快速,Impala中?翻译是??羚?。
之前学习的Hive以及MR适合离线批处理,但是对交互式查询的场景?能为?(要求快速响应),所以为了 解决查询速度的问题,Cloudera公司依据Google的Dremel开发了Impala,Impala抛弃了MapReduce 使?了类似于传统的MPP数据库技术,??提?了查询的速度。
MPP (Massively Parallel Processing),就是?规模并?处理,在MPP集群中,每个节点资源都是独? 享有也就是有独?的磁盘和内存,每个节点通过?络互相连接,彼此协同计算,作为整体提供数据服 务。
查询过程
中间结果
交互查询
计算引擎
容错
查询速度
Impala优势总结
因为impala 不能自动感知 hive对元数据的更新操作。
如果是大表join ,impala使用hash join,使得hash 值一样的 id去往同一节点,这样不同节点可以并行执行join操作。
如果是小表,impala使用 广播 join。
group by 操作: impala 会对分组字段进行hash 分发,这样不同节点可以并行执行局部group by 操作,最终merge所有节点的结果。
impala的sql语法与hive基本一样,支持大部分的hive内置函数。
impala的命令行是impala-shell
关于impala的相关配置参考word 文档。
<dependencies> <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoopcommon --> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-common -- > <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-common</artifactId> <version>2.3.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-metastore --> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-metastore</artifactId> <version>2.3.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-service - -> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-service</artifactId> <version>2.3.7</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc --> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-jdbc</artifactId> <version>2.3.7</version> <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec --> <dependency> <groupId>org.apache.hive</groupId> <artifactId>hive-exec</artifactId> <version>2.3.7</version> </dependency> </dependencies>
package com.lagou.impala.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class ImpalaTest { public static void main(String[] args) throws Exception { //定义连接impala的驱动和连接url String driver = "org.apache.hive.jdbc.HiveDriver"; String driverUrl = "jdbc:hive2://linux122:21050/default;auth=noSasl"; //查询的sql语句 String querySql = "select * from t1"; //获取连接 Class.forName(driver); //通过Drivermanager获取连接 final Connection connection = DriverManager.getConnection(driverUrl); final PreparedStatement ps = connection.prepareStatement(querySql); //执?查询 final ResultSet resultSet = ps.executeQuery(); //解析返回结果 //获取到每条数据的列数 final int columnCount = resultSet.getMetaData().getColumnCount(); //遍历结果集 while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { final String string = resultSet.getString(i); System.out.print(string + "\t"); } System.out.println(); } //关闭资源 ps.close(); connection.close(); } }
原文:https://www.cnblogs.com/wanghzh/p/15202706.html