Coder Social home page Coder Social logo

hive-udf's Introduction

hive_udf

UDF, GenericUDF, UDTF, UDAF #Create a table Create a table named employee:

CREATE TABLE employee(
	name			STRING,
	salary			FLOAT,
	subordinates	ARRAY<STRING>,
	deductions		MAP<STRING, FLOAT>,
	address			STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\001'
COLLECTION ITEMS TERMINATED BY '\002'
MAP KEYS TERMINATED BY '\003'
LINES TERMINATED BY '\n'

Load the data that is in data directory.

hadoop fs -put employee.txt /hive
LOAD DATA INPATH '/hive/employees.txt'
OVERWRITE INTO TABLE employee

#Compile and package Compile and package the source codes by maven.First of all, enter the project's root directory, then execute the follow commands in shell:

$ mvn clean
$ mvn clean compile
$ mvn clean package

#Run the examples If we successfully installed Hadoop and Hive before, we are able to run the examples now. Firstly, we should add the jar into CLASSPATH:

hive> ADD jar /root/experiment/hive/hive-0.0.1-SNAPSHOT.jar;

Secondly, create the temporary functions:

hive> CREATE TEMPORARY FUNCTION hello 
    > AS 'edu.wzm.hive.HelloUDF';
hive> CREATE TEMPORARY FUNCTION contains 
    > AS 'edu.wzm.hive.ComplexUDFExample';
hive> CREATE TEMPORARY FUNCTION collect 
    > AS 'edu.wzm.hive.udaf.GenericUDAFCollect';
hive> CREATE TEMPORARY FUNCTION explode_name 
    > AS 'edu.wzm.hive.udtf.ExplodeNameUDTF';

finally, test the example:

hive> SELECT hell(name)
    > FROM employee;
hive> SELECT contains(subordinates, subordinates[0]), subordinates
    > FROM employee;
hive> SELECT collect(name)
    > FROM employee;
hive> SELECT salary, concat_ws(',', collect(name))
    > FROM employee;    
hive> SELECT explode_name(name)
    > FROM employee;

hive-udf's People

Contributors

gatsbynewton avatar

Watchers

rice avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.