2020년 11월 25일 수요일

Hive [7] - Hive to Phoenix Table


[ 사전셋팅 (Prerequisites) ]

phoenix-version-hive.jar 파일을 찾고, 

해당 하이브 설정파일에 value를 추가하여 하이브 맵리듀스 잡이 jar파일 사용하게 한다.

1) hive-env.sh : HIVE_AUX_JARS_PATH=<path to jar>

2) hive-site.xml

<property>

    <name>hive.aux.jars.path</name>

    <value>file://<path></value>

</property>




[ 테이블 생성 ]

jar파일에 있는 storage Handler는 internal과 external 하이브테이블 생성을 지원한다.


1) Create Internal Table

Hive에서 테이블생성시 Phoenix에도 자동으로 테이블 생성되며, Hive나 Hue에서 데이터 조회와 같은 쿼리가 가능하다.

Internal Phoenix테이블은 Hive테이블 lifecycle을 따른다. 즉 Hive테이블에서 데이터 또는 테이블이 삭제되면 Phoenix테이블 또한 동일하게 영향을 받는다.

create table phoenix_table (
	  s1 string,
	  i1 int,
	  f1 float,
	  d1 double
	)
	STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'
	TBLPROPERTIES (
	  "phoenix.table.name" = "phoenix_table",
	  "phoenix.zookeeper.quorum" = "localhost",
	  "phoenix.zookeeper.znode.parent" = "/hbase",
	  "phoenix.zookeeper.client.port" = "2181",
	  "phoenix.rowkeys" = "s1, i1",
	  "phoenix.column.mapping" = "s1:s1, i1:i1, f1:f1, d1:d1",
	  "phoenix.table.options" = "SALT_BUCKETS=10, DATA_BLOCK_ENCODING='DIFF'"
	);



2) Create External Table

Hive에서 테이블생성시 Phoenix에 맵핑되는 테이블이 없으면 생성이 불가능하다. 테이블과 데이터를 따로 metadata로 매니징하기에 Hive나 Hue에서 데이터 조회 등의 쿼리를 실행 할 수 없다. 

External Phoenix테이블은 Hive테이블에 큰 영향을 받지않는다. Hive테이블에서 데이터 또는 테이블이 삭제되어도 Phoenix테이블 또한 동일하게 영향을 받는다.

create external table ext_table (
  i1 int,
  s1 string,
  f1 float,
  d1 decimal
)
STORED BY 'org.apache.phoenix.hive.PhoenixStorageHandler'
TBLPROPERTIES (
  "phoenix.table.name" = "ext_table",
  "phoenix.zookeeper.quorum" = "localhost",
  "phoenix.zookeeper.znode.parent" = "/hbase",
  "phoenix.zookeeper.client.port" = "2181",
  "phoenix.rowkeys" = "i1",
  "phoenix.column.mapping" = "i1:i1, s1:s1, f1:f1, d1:d1"
);



[ 생성 Properties ]

  1. phoenix.table.name
    • Specifies the Phoenix table name
    • Default: the same as the Hive table
  2. phoenix.zookeeper.quorum
    • Specifies the ZooKeeper quorum for HBase
    • Default: localhost
  3. phoenix.zookeeper.znode.parent
    • Specifies the ZooKeeper parent node for HBase
    • Default: /hbase
  4. phoenix.zookeeper.client.port
    • Specifies the ZooKeeper port
    • Default: 2181
  5. phoenix.rowkeys
    • The list of columns to be the primary key in a Phoenix table
    • Required
  6. phoenix.column.mapping
    • Mappings between column names for Hive and Phoenix. See Limitations for details.



[ Meta데이터위치 ]

Zookeeper znode를 확인하면 /hbase/archive/data 에 hive와 연동된 phoenix메타데이터가 담긴다. 

/hbase/data에 테이블이 정의되어 있더라도 해당 파일을 지우면 phoenix에서 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 에러를 띄우며 트래킹할 수 없다는 메세지를 보낸다.




참조 : https://phoenix.apache.org/hive_storage_handler.html



 

댓글 없음:

댓글 쓰기