Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Phoenix in 15 minutes or less

jtaylor-sfdc edited this page Mar 13, 2013 · 25 revisions

What is this new Phoenix thing I've been hearing about?
Phoenix is an open source SQL skin for HBase. You use the standard JDBC APIs to create tables, insert data, and query your HBase data instead of using the regular HBase client APIs.

Doesn't putting an extra layer between my application and HBase just slow things down?
Actually, no. Phoenix achieves as good or likely better performance than if you hand-coded it yourself (not to mention with a heck of a lot less code) by:

  • compiling your SQL queries to native HBase scans
  • determining the optimal start and stop for your scan key
  • orchestrating the parallel execution of your scans
  • bringing the computation to the data by
    • pushing the predicates in your where clause to a server-side filter
    • executing aggregate queries through server-side hooks (called co-processors)

Blah, blah, blah - I just want to get started!
Ok, great! Just follow our install instructions:

  • download and expand our installation tar
  • copy the phoenix jar into the HBase lib directory of every region server
  • restart the region servers
  • add the phoenix client jar to the classpath of your HBase client
  • download and setup SQuirrel as your SQL client so you can issue adhoc SQL against your HBase cluster

I don't want to download and setup anything else!
Ok, fair enough - you can create your own SQL scripts and execute them using our command line tool instead. Let's walk through an example now. In the bin directory of your install location:

  • Create us_population.sql file
CREATE TABLE IF NOT EXISTS us_population (
      state CHAR(2),
      city VARCHAR NOT NULL,
      population BIGINT
      CONSTRAINT my_pk PRIMARY KEY (state, city));
  • Create us_population.csv file
NY,New York,8143197
CA,Los Angeles,3844829
IL,Chicago,2842518
TX,Houston,2016582
PA,Philadelphia,1463281
AZ,Phoenix,1461575
TX,San Antonio,1256509
CA,San Diego,1255540
TX,Dallas,1213825
CA,San Jose,912332
  • Create us_population_queries.sql file
SELECT state as "State",count(city) as "City Count",sum(population) as "Population Sum"
FROM us_population
GROUP BY state
ORDER BY sum(population) DESC
  • Execute the following command from a command terminal
psql.sh <your_zookeeper_quorum> us_population.sql us_population.csv us_population_queries.sql

Congratulations! You've just created your first Phoenix table, inserted data into it, and executed an aggregate query over it with a few lines of code in 15 minutes or less!

Why is it called Phoenix anyway? Did some other project crash and burn and this is the next generation?
I'm sorry, but we're out of time and space, so we'll have to answer that next time!

Thanks for your time,
James Taylor
http://phoenix-hbase.blogspot.com/
@JamesPlusPlus

Clone this wiki locally