Impala-查询 + 函数


一、查询

  1. 基本的语法跟hive的查询语句大体一样
  2. Impala不支持DISTRIBUTE BY(分区排序), SORT BY(每个MR内部排序),CLUSTER BY(cluster by除了具有distribute by的功能外还兼具sort by的功能。但是排序只能是倒序排序,不能指定排序规则为ASC或者DESC)。
  3. Impala中不支持分桶表
  4. Impala不支持COLLECT_SET(col)和explode(col)函数
  5. Impala支持开窗函数

              [bigdata12:21000] > select name,orderdate,cost,sum(cost) over(partition by month(orderdate)) from business;

二、函数

自定义函数

1.创建一个Maven工程Hive

2.导入依赖

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->

<dependency>

<groupId>org.apache.hive</groupId>

<artifactId>hive-exec</artifactId>

<version>1.2.1</version>

</dependency>

</dependencies>

3.创建一个类-大写转小写:

package com.itstar.hive; import org.apache.hadoop.hive.ql.exec.UDF; public class Lower extends UDF { public String evaluate (final String s) { if (s == null) { return null; } return s.toLowerCase(); } }

4.打成jar包上传到服务器/opt/module/jars/

5. 将jar包上传到hdfs的指定目录

hadoop fs -put hive-1.0-SNAPSHOT.jar /

6. 创建函数

[bigdata12:21000] > create function mylower(string) returns string location '/hive-1.0-SNAPSHOT.jar' symbol='hive.UDF_Lower';

7. 使用自定义函数

[bigdata12:21000] > select id,mylower(name) from student;

8.通过show functions查看自定义的函数

[bigdata12:21000] > show functions;

Query: show functions

+-------------+-----------------+-------------+---------------+

| return type | signature       | binary type | is persistent |

+-------------+-----------------+-------------+---------------+

| STRING      | mylower(STRING) | JAVA        | false         |

+-------------+-----------------+-------------+---------------+


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM