大數(shù)據(jù)開發(fā)phoenix連接hbase流程詳解
一、安裝phoennix添加配置

1、將phoenix-server-hbase-2.4-5.1.2.jar拷貝至hbase的的lib下
cp phoenix-server-hbase-2.4-5.1.2.jar ../hbase/lib/
2、配置phoenix可以訪問hbase的系統(tǒng)表
(1)將以下配置添加至hbase-site.xml中
<property>
<name>phoenix.schema.isNamespaceMappingEnabled</name>
<value>true</value>
</property>
<property>
<name>phoenix.schema.mapSystemTablesToNamespace</name>
<value>true</value>
</property>(2)將hbase-stie.xml拷貝到phoenix/bin目錄下
cp ../hbase/conf/hbase-site.xml ../phoenix/bin/
二、啟動(dòng)phoenix服務(wù)
1、啟動(dòng)hbase
../hbase/bin/start-hbase.sh
2、啟動(dòng)phoenix
python3 ../phoenix/bin/sqlline.py server200:2181
server200:2181為zookeeper地址

三、phoenix常用語法
官網(wǎng)文檔 https://phoenix.apache.org/language/index.html
(1)創(chuàng)建表
create table test1(id varchar primary key,a varchar,b varchar);
id主鍵可視為hbase的rowkey
?
(2)插入數(shù)據(jù)
upsert into TEST1 values('202211160089','liuping','chenyingying');(3) 查詢數(shù)據(jù)
select * from TEST1;

(4)視圖/表映射
由于phoenix 無法直接訪問hbase創(chuàng)建的非系統(tǒng)表,可以通過視圖/表映射對(duì)非系統(tǒng)表進(jìn)行查詢,但視圖不可修改,表映射可讀可寫
在hbase上創(chuàng)建表名為eftb列族為fm1 、fm2的表
create 'reftb','fm1','fm2'

向表中添加數(shù)據(jù)
put 'reftb','010101','fm1:name','zhangsan' put 'reftb','010101','fm2:age','九千歲'
<1>視圖映射
create view "reftb"(id varchar primary key,"fm1"."name" varchar,"fm2"."age" varchar);
<2>表映射
create table "reftb"(id varchar primary key,"fm1"."name" varchar,"fm2"."age" varchar);
<3>查看數(shù)據(jù)


(5)添加修改數(shù)據(jù)(增改語法相同)
upsert into "reftb" values('010102','諸葛村夫','五十');
upsert into "reftb" values('010101','常山趙子龍','七十');(6)刪除數(shù)據(jù)
delete from "reftb" where ID='010101';
(7)創(chuàng)建schema(數(shù)據(jù)庫名,對(duì)用hbase是的namespace)
CREATE SCHEMA IF NOT EXISTS "my_schema";
四、java代碼集成phoenix
1、添加依賴
implementation 'org.apache.phoenix:phoenix-client-hbase-2.4:5.1.2'
2、編寫代碼
public class PhoenixJdbcUtils {
private final static Logger LOGGER = LoggerFactory.getLogger(PhoenixJdbcUtils.class);
private static Connection connection;
static {
Properties properties =new Properties();
PhoenixDriver instance = PhoenixDriver.INSTANCE;
try {
connection = instance.connect("jdbc:phoenix:server200:2181", properties);
///connection = DriverManager.getConnection("jdbc:phoenix:server200:2181", properties);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 插入數(shù)據(jù)
* @throws SQLException
*/
public static void testUpsertData() throws SQLException {
PreparedStatement psUpsert = connection.prepareStatement( " upsert into \"reftb\" values('168936','劉備','63')");
boolean addData = psUpsert.execute();
LOGGER.info("addData---------"+addData);
connection.commit();
}
/**
* 查詢數(shù)據(jù)
* @throws SQLException
*/
public static void testQueryData() throws SQLException {
PreparedStatement psQuery = connection.prepareStatement(" select * from \"reftb\" ");
ResultSet resultSet = psQuery.executeQuery();
while (resultSet.next()) {
LOGGER.info("id--{}",resultSet.getString(1));
LOGGER.info("name--{}",resultSet.getString(2));
LOGGER.info("age--{}",resultSet.getString(3));
}
}
public static void main(String[] args) {
try {
testQueryData();
testUpsertData();
} catch (Exception e) {
e.printStackTrace();
}
}
}到此這篇關(guān)于大數(shù)據(jù)開發(fā)phoenix連接hbase流程詳解的文章就介紹到這了,更多相關(guān)phoenix連接hbase內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
dbeaver批量導(dǎo)出數(shù)據(jù)到另一個(gè)數(shù)據(jù)庫的詳細(xì)圖文教程
DBeaver是一款數(shù)據(jù)庫管理軟件,小巧易用,最主要其官方版就可以滿足平常得任務(wù)需求,這篇文章主要給大家介紹了關(guān)于dbeaver批量導(dǎo)出數(shù)據(jù)到另一個(gè)數(shù)據(jù)庫的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
MyISAM與InnoDB索引實(shí)現(xiàn)對(duì)比詳解
這篇文章主要給大家介紹了關(guān)于MyISAM與InnoDB索引實(shí)現(xiàn)對(duì)比的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
Navicat Premium 15無限試用注冊(cè)表修改的方法詳解
這篇文章主要介紹了Navicat Premium 15無限試用注冊(cè)表修改的方法詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
使用sqlplus創(chuàng)建DDL和DML操作技巧
這篇文章主要介紹了使用sqlplus創(chuàng)建DDL和DML操作技巧,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2018-05-05
在ACCESS和SQL Server下Like 日期類型查詢區(qū)別
Like 和日期類型在ACCESS和SQL Server的區(qū)別,需要的朋友可以參考下。2009-10-10

