This topic describes how to use Phoenix to query data.
Prerequisites
The runtime environment for Phoenix is prepared. For more information about how to prepare the environment, see Prepare an environment.
Quick start
- Execute the following statement to create a table named us_population:
CREATE TABLE IF NOT EXISTS us_population ( state CHAR(2) NOT NULL, city VARCHAR NOT NULL, population BIGINT CONSTRAINT my_pk PRIMARY KEY (state, city));
- Execute the following statements to write data:
UPSERT INTO us_population VALUES('NY','New York',8143197); UPSERT INTO us_population VALUES('CA','Los Angeles',3844829); UPSERT INTO us_population VALUES('IL','Chicago',2842518); UPSERT INTO us_population VALUES('TX','Houston',2016582); UPSERT INTO us_population VALUES('PA','Philadelphia',1463281); UPSERT INTO us_population VALUES('AZ','Phoenix',1461575); UPSERT INTO us_population VALUES('TX','San Antonio',1256509); UPSERT INTO us_population VALUES('CA','San Diego',1255540); UPSERT INTO us_population VALUES('TX','Dallas',1213825); UPSERT INTO us_population VALUES('CA','San Jose',912332);
- Run an SQL query.
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;
- Verify the result.
Use the API to connect to Phoenix JDBC
- Phoenix 5.x SDK maven dependency
<dependency> <groupId>com.aliyun.phoenix</groupId> <artifactId>ali-phoenix-queryserver-client</artifactId> <version>5.2.1-HBase-2.x</version> </dependency>
- Phoenix 4.x SDK maven dependency
<dependency> <groupId>com.aliyun.phoenix</groupId> <artifactId>ali-phoenix-core</artifactId> <version>${See release notes for the latest version in FAQ}</version> </dependency>
References
For code examples, see Examples.