参考phoenix 官网quickStart
http://phoenix.apache.org/Phoenix-in-15-minutes-or-less.html
1. 创建us_population.sql,定义phoenix表
主键是state 与 city
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));
2. 创建csv文件用于存放带插入数据
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
3. 通过phoenix-psql.py执行sql脚本并且向phoenix中插入数据
./psql.py <your_zookeeper_quorum> us_population.sql us_population.csv [ec2-user@hmaster bin]$ ./psql.py 10.180.137.44,10.180.137.46,10.180.137.47 us_population.sql us_population.csv -bash: ./psql.py: No such file or directory [ec2-user@hmaster bin]$ [ec2-user@hmaster bin]$ [ec2-user@hmaster bin]$ [ec2-user@hmaster bin]$ ./phoenix-psql.py 10.180.137.44,10.180.137.46,10.180.137.47 us_population.sql us_population.csv 16/11/30 18:52:17 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 16/11/30 18:52:28 WARN impl.MetricsConfig: Cannot locate configuration: tried hadoop-metrics2-phoenix.properties,hadoop-metrics2.properties no rows upserted Time: 0.994 sec(s) csv columns from database. CSV Upsert complete. 10 rows upserted Time: 0.237 sec(s)
4. 通过C:phoenixsquirrel-sql-3.5.3查看表phoenix中的数据
5. 查看phoenix表映射在hbase中的存储
rowkey是phoenix的主键state 与 city
hbase(main):013:0> describe "US_POPULATION" Table US_POPULATION is ENABLED US_POPULATION, {TABLE_ATTRIBUTES => {coprocessor$1 => '|org.apache.phoenix.coprocessor.ScanRegionObserver|80530636 6|', coprocessor$2 => '|org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver|805306366|', coprocessor$3 => '|org.apache.phoenix.coprocessor.GroupedAggregateRegionObserver|805306366|', coprocessor$4 => '|org.apache.pho enix.coprocessor.ServerCachingEndpointImpl|805306366|', coprocessor$5 => '|org.apache.phoenix.hbase.index.Indexer| 805306366|org.apache.hadoop.hbase.index.codec.class=org.apache.phoenix.index.PhoenixIndexCodec,index.builder=org.a pache.phoenix.index.PhoenixIndexBuilder', coprocessor$6 => '|org.apache.hadoop.hbase.regionserver.LocalIndexSplitt er|805306366|'} COLUMN FAMILIES DESCRIPTION {NAME => '0', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLO CK_ENCODING => 'FAST_DIFF', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BL OCKSIZE => '65536', REPLICATION_SCOPE => '0'} 1 row(s) in 0.0700 seconds hbase(main):009:0* scan "US_POPULATION" ROW COLUMN+CELL AZPhoenix column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x16MG AZPhoenix column=0:_0, timestamp=1480503157237, value= CALos Angeles column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00:xAAxDD CALos Angeles column=0:_0, timestamp=1480503157237, value= CASan Diego column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x13(t CASan Diego column=0:_0, timestamp=1480503157237, value= CASan Jose column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x0DxEBxCC CASan Jose column=0:_0, timestamp=1480503157237, value= ILChicago column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00+_x96 ILChicago column=0:_0, timestamp=1480503157237, value= NYNew York column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00|A] NYNew York column=0:_0, timestamp=1480503157237, value= PAPhiladelphia column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x16SxF1 PAPhiladelphia column=0:_0, timestamp=1480503157237, value= TXDallas column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x12x85x81 TXDallas column=0:_0, timestamp=1480503157237, value= TXHouston column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x1ExC5F TXHouston column=0:_0, timestamp=1480503157237, value= TXSan Antonio column=0:POPULATION, timestamp=1480503157237, value=x80x00x00x00x00x13,= TXSan Antonio column=0:_0, timestamp=1480503157237, value= 10 row(s) in 0.6030 seconds