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