当前位置: 首页 > news >正文

石家庄自适应网站建设新闻头条最新消息

石家庄自适应网站建设,新闻头条最新消息,宣传方式有哪些,畅言wordpress插件1. hbase-phoenix的应用 1.1 概述: 上面我们学会了hbase的操作和原理,以及外部集成的mr的计算方式,但是我们在使用hbase的时候,有的时候我们要直接操作hbase做部分数据的查询和插入,这种原生的方式操作在工作过程中还…

1. hbase-phoenix的应用

1.1 概述:

上面我们学会了hbase的操作和原理,以及外部集成的mr的计算方式,但是我们在使用hbase的时候,有的时候我们要直接操作hbase做部分数据的查询和插入,这种原生的方式操作在工作过程中还是比较常见的,以上这些方式需要使用外部的框架进行协助处理,其实hbase也对外提供了一个直接的操作方式接口插件Phoenix,它和mr不一样,是直接集成在hbase之中的,通过一个工具使得hbase可以完全支持sql操作,其实我们可以将Phoenix当成是一个sql插件,一个可以写sql完成hbase操作的插件,并且在hbase中通过regionserver直接执行,还可以做sql的优化,是hbase免费开源出来的一个插件。

 安装过程及配置环境变量过程略。

1.2 创建测试表

在phoenix中创建测试表,必须指定主键,主键对应hbase的rowkey(唯一且非空)

-- 表名不带双引号,默认转成大写
create table phtest1(pk varchar not null primary key,col1 varchar,col2 varchar,col3 varchar
);
-- 表名带双引号,不转大写
create table "phtest2"(pk varchar not null primary key,col1 varchar,col2 varchar,col3 varchar
);-- 查看表列表
!tables-- 查看表结构
!describe PHTEST1;

在hbase shell中查询(phoenix严格区分大小写,所有小写在phoenix中都会被翻译为大写)。

规则就是:如果表名没用双引号括起来,小写全会被翻译为大写;如果表用双引号括起来了,那么小写的话就用小写,大写就用大写。

1.3 插入/查询数据

0: jdbc:phoenix:hadoop106,hadoop107:2181> upsert into PHTEST1 values('x0001','1','2','3'
. . . . . . . . . . . . . . . . . . . .)> );
1 row affected (0.299 seconds)
0: jdbc:phoenix:hadoop106,hadoop107:2181> upsert into PHTEST1 values ('x0001','1','22','3');
1 row affected (0.024 seconds)
0: jdbc:phoenix:hadoop106,hadoop107:2181> upsert into PHTEST1 values ('x0002','1','2','3');
1 row affected (0.02 seconds)
0: jdbc:phoenix:hadoop106,hadoop107:2181> select * from PHTEST1;
+-------+------+------+------+
|  PK   | COL1 | COL2 | COL3 |
+-------+------+------+------+
| x0001 | 1    | 22   | 3    |
| x0002 | 1    | 2    | 3    |
+-------+------+------+------+
2 rows selected (0.103 seconds)

在hbase shell中查询:

1.4 测试删除

插入多行,删除其中某一行

-- 插入多行,一次只能插入一行,不能插入多行
upsert into PHTEST1 values ('x0002','2','3','4');
upsert into PHTEST1 values ('x0003','3','4','5');
upsert into PHTEST1 values ('x0004','4','5','6');
-- 查询验证
select * from PHTEST1;
-- 删除一行
delete from PHTEST1 where col1='2';
-- 查询验证
select * from PHTEST1;

1.5 查询导入

-- 使用select查询结果集批量更新表
-- 创建一张临时表PHTEST2
create table PHTEST2(pk varchar not null primary key,col1 varchar, col2 varchar,col3 varchar
);
-- 临时表插入数据,比phtest1表多了'x0005'、'x0006'和'x0002'三行,其中'x0003'、'x0004'与phtest1的一致
upsert into PHTEST2 values ('x0001','newvalue','newvalue','newvalue');
upsert into PHTEST2 values ('x0002','newvalue','newvalue','newvalue');
upsert into PHTEST2 values ('x0003','3','4','5');
upsert into PHTEST2 values ('x0004','4','5','6');
upsert into PHTEST2 values ('x0005','newvalue','newvalue','newvalue');
upsert into PHTEST2 values ('x0006','newvalue','newvalue','newvalue');-- 执行批量更新, 将PHTEST2表的数据覆盖到PHTEST1表
upsert into PHTEST1 select * from PHTEST2;

1.6  删除表

drop table PHTEST2;

1.7 数据导入

使用官方提供的数据样例,phoenix数据导入只支持csv文件格式。

# 在客户端外
# 执行SQL文件
# 对标hive的-f test.sql ${hiveconf:batch_date}
# 创建sql文件 select * from PHTEST1
sqlline.py nn1:2181 /root/sql# 创建表
create table user(id varchar primary key,name varchar,age varchar);
# 创建csv文件 /root/user.csv
# 输入文件内容
# 1,zhangsan,20
# 2,lisi,30psql.py -t USER nn1:2181 /root/user.csv
# 注意:
#   1)phoenix数据导入只支持后缀为.csv的文件, csv文件名称不需要和表名称一致,文件名可以小写
#   2)指定的表必须是大写,小写就报错

1.8 在phoenix建表时指定列族

-- 用 列族名.字段名
create table "cftest" (pk varchar not null primary key,cf1.col1 varchar,cf2.col2 varchar);-- 查询时可以不用列族
select col1 from "cftest"

注:如果建表时这些列未指定列族,则会分配一个叫'0'的列族。

1.9 在phoenix建表时指定压缩格式

-- 在后面可指定压缩格式
create table "comptest" (pk varchar not null primary key,cf1.col1 varchar,cf2.col2 varchar) compression='snappy';

1.10 在phoenix建表时预分region

-- 用 split on ('x0001','x0002','x0003','x0004','x0005') 来进行预分region
-- 其中 on 里面的 是 splitkey
create table "split_region_test" (pk varchar not null primary key,cf1.col1 varchar,cf2.col2 varchar) compression='snappy' split on ('x0001','x0002','x0003','x0004','x0005');

1. 11 phoenix与hbase表关联

1)在hbase中创建带有命名空间的表,并添加数据

create 'hainiu:relatetable_1',{NAME => 'cf1',COMPRESSION => 'snappy'},{NAME => 'cf2',COMPRESSION => 'snappy'}# 添加数据
put 'hainiu:relatetable_1','x0001','cf1:name','user1'
put 'hainiu:relatetable_1','x0002','cf1:name','user2'
put 'hainiu:relatetable_1','x0001','cf1:age','20'
put 'hainiu:relatetable_1','x0002','cf1:age','21'
put 'hainiu:relatetable_1','x0001','cf2:address','beijing'
put 'hainiu:relatetable_1','x0002','cf2:address','shanghai'

2)在phoenix中创建schema(schema相当于命名空间)

-- 先在phoenix中创建schema,对应hbase的namespace
create schema if not exists "hainiu";

执行报错:

cannot create scheme because config phoenix.scheme.isNamespaceMappingEnabled for enabling name space mapping isn`t enabled.schemaName='hainiu'

在phoenix中创建schema报错解决方式:在hbase的hbase-site.xml中添加phoenix.schema.isNamespaceMappingEnabled=true和phoenix.schema.mapSystemTablesToNamespace=true

在hbase和Phoenix的配置文件hbase-site.xml中都要增加这个配置

增加以上配置

重启hbase集群

stop-hbase.sh

start-hbase.sh

重新进入Phoenix 客户端

-- 退出客户端
!q
-- 进入客户端
sqlline.py nn1:2181-- 先在phoenix中创建schema,对应hbase的namespace
create schema if not exists "hainiu";

3)创建带有命名空间的表

-- 在phoenix创建'hainiu:relatetable'的关联表
-- 其中: column_encoded_bytes=0 是把字段名转成字符串,而不是原来的byte数组
create table "hainiu"."relatetable_2"(id varchar not null primary key,"cf1"."name" varchar,"cf1"."age" varchar,"cf2"."address" varchar
) column_encoded_bytes=0;-- 在phoenix中插入一条数据测试
upsert into "hainiu"."relatetable_2" (id,"cf1"."name","cf1"."age","cf2"."address") values ('x0003','user3','22','guangzhou');select * from "hainiu"."relatetable_2";
select "name" from "hainiu"."relatetable_2";
select "cf1"."name" from "hainiu"."relatetable_2";-- 没有给进行BYTES.tostring
create table "hainiu"."relatetable_3"(id varchar not null primary key,"cf1"."name" varchar,"cf1"."age" varchar,"cf2"."address" varchar
);
upsert into "hainiu"."relatetable_3" (id,"cf1"."name","cf1"."age","cf2"."address") values ('x0003','user3','22','guangzhou');

建表语句中带有 column_encoded_bytes=0, 从hbase查询,字段名能看得懂,否则看不懂。

1. 12 phoenix建表时指定组合rowkey

-- 通过 CONSTRAINT pk primary key ( prefix,id )  设定联合主键,作为rowkey
-- 当prefix和id作为联合主键, 只在hbase的rowkey中存在, column里没有
-- 建表语句
create table "hainiu"."combinationkey_table1" (prefix varchar not null,id varchar not null,col1 varchar,col2 varcharCONSTRAINT pk primary key ( prefix,id ) 
) column_encoded_bytes=0, compression='snappy'  split on ('1','2','|');-- 插入数据
upsert into "hainiu"."combinationkey_table1" (prefix,id,col1,col2) values ('1','001','user1','20');
upsert into "hainiu"."combinationkey_table1" (prefix,id,col1,col2) values ('1','002','user2','21');-- 查看表结构
!describe "hainiu"."combinationkey_table"

1. 13 phoenix实现动态列

-- 创建表
create table "hainiu"."dynamic_table1"(pk varchar not null primary key,col1 varchar,col2 varchar
)column_encoded_bytes=0;-- 插入数据
upsert into "hainiu"."dynamic_table1"  (pk,col1,col2) values ('x0001','user1','20');
upsert into "hainiu"."dynamic_table1"  (pk,col1,col2) values ('x0002','user1','21');
upsert into "hainiu"."dynamic_table1"  (pk,col1,col2) values ('x0003','user1','22');
upsert into "hainiu"."dynamic_table1"  (pk,col1,col2) values ('x0004','user1','23');-- 动态插入列
-- 动态插入 col3 和 col4 列
upsert into "hainiu"."dynamic_table1" (pk,col1,col2,col3 varchar,col4 varchar) values ('x0005','user1','23','beijing','hainiu');
-- 动态插入 col4 和 col5 列
upsert into "hainiu"."dynamic_table1" (pk,col1,col2,col4 varchar,col5 varchar) values ('x0006','user2','32','huawei','30K');-- 动态插入 col3、col4、col5 列
upsert into "hainiu"."dynamic_table1" (pk,col1,col2,col3 varchar,col4 varchar,col5 varchar) values ('x0007','user3','33','shanghai','ali','22K');
-- 动态插入 col3、col4、col5、col6 列 
upsert into "hainiu"."dynamic_table1" (pk,col1,col2,col3 varchar,col4 varchar,col5 varchar,col6 varchar) values ('x0008','user4','35','shanghai','baidu','12K','false');-- phoenix中查询动态列
select * from "hainiu"."dynamic_table1"(col3 varchar,col4 varchar);
select * from "hainiu"."dynamic_table1"(col3 varchar,col4 varchar,col5 varchar) ;
select * from "hainiu"."dynamic_table1"(col3 varchar,col4 varchar,col5 varchar,col6 varchar) ;

2. 索引

2.1 开启索引

配置hbase的hbase-site.xml

<property><name>hbase.regionserver.wal.codec</name><value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
#分发到不同的机器#重启hbase集群
stop-hbase.sh
start-hbase.sh
# 删除Phoenix中的配置文件
hbase-site.xml 
# 将hbase的配置文件给Phoenix
数据准备
-- 创建测试表
create table "hainiu"."testindex"(pk varchar not null primary key,col1 varchar
)column_encoded_bytes=0;-- 插入数据
upsert into "hainiu"."testindex" values ('x1','1');
……
upsert into "hainiu"."testindex" values ('x20000','20000');
-- 编写脚本,生成SQL文件
[root@worker-1 hdfs_test]# vim s1.sh 
#! /bin/bashfor((i=1;i<=20000;i++))
doecho "upsert into \"hainiu\".\"testindex\" values ('x${i}','${i}');" >> testindex.sql
done-- 执行SQL文件导入表
sqlline.py nn1:2181 testindex.sql
索引开启前查询
-- 查看执行计划,发现全表扫描
explain select * from "hainiu"."testindex1" where COL1 = '200';
-- 查询
select * from "hainiu"."testindex1" where COL1 = '200';

通过执行计划可以发现,查询为FULL SCAN。全表扫描。

索引操作
-- 基于 COL1字段 创建索引, 当创建完后,索引里存的是已经排序好的COL1数据
-- local index 适用于写操作频繁的场景。索引数据和数据表的数据是存放在相同的服务器中的,避免了在写操作的时候往不同服务器的索引表中写索引带来的额外开销
create local index myindex1 on "hainiu"."testindex" (COL1);-- 查看执行计划,发现不全表扫描
explain select * from "hainiu"."testindex" where COL1 = '200';
select * from "hainiu"."testindex" where COL1 = '200';-- 删除索引
drop index myindex on "hainiu"."testindex";


文章转载自:
http://dinncobread.ssfq.cn
http://dinncoaxonometric.ssfq.cn
http://dinnconaevoid.ssfq.cn
http://dinncodateless.ssfq.cn
http://dinncopentastyle.ssfq.cn
http://dinncoaegis.ssfq.cn
http://dinncoidiotype.ssfq.cn
http://dinncoeutectiferous.ssfq.cn
http://dinncocosmonette.ssfq.cn
http://dinncopremiere.ssfq.cn
http://dinncoheavyset.ssfq.cn
http://dinncosemibarbarian.ssfq.cn
http://dinncophotoengraving.ssfq.cn
http://dinncosundsvall.ssfq.cn
http://dinncoidiomorphically.ssfq.cn
http://dinncotransdetermination.ssfq.cn
http://dinncomcat.ssfq.cn
http://dinncodurrie.ssfq.cn
http://dinncobechic.ssfq.cn
http://dinncotagalong.ssfq.cn
http://dinncocanthus.ssfq.cn
http://dinncosilvics.ssfq.cn
http://dinncosuttle.ssfq.cn
http://dinncounbutton.ssfq.cn
http://dinncoinstrumental.ssfq.cn
http://dinncovagile.ssfq.cn
http://dinncotalking.ssfq.cn
http://dinncomanhunt.ssfq.cn
http://dinnconullification.ssfq.cn
http://dinncorailage.ssfq.cn
http://dinncosatin.ssfq.cn
http://dinncocolloquialist.ssfq.cn
http://dinncochorioid.ssfq.cn
http://dinncohorsey.ssfq.cn
http://dinncodecillion.ssfq.cn
http://dinncowifedom.ssfq.cn
http://dinncoacacia.ssfq.cn
http://dinncoencumbrance.ssfq.cn
http://dinncocapitular.ssfq.cn
http://dinncoaverroism.ssfq.cn
http://dinncoenneasyllabic.ssfq.cn
http://dinncothermoform.ssfq.cn
http://dinncosaveloy.ssfq.cn
http://dinncosupportative.ssfq.cn
http://dinncooxford.ssfq.cn
http://dinncocarcel.ssfq.cn
http://dinncoskylit.ssfq.cn
http://dinncovillainage.ssfq.cn
http://dinncoamblyopia.ssfq.cn
http://dinncojaculate.ssfq.cn
http://dinncorehumidify.ssfq.cn
http://dinncoapophthegm.ssfq.cn
http://dinncocateran.ssfq.cn
http://dinncogastrinoma.ssfq.cn
http://dinncowatercart.ssfq.cn
http://dinncoannulation.ssfq.cn
http://dinncoautoinjector.ssfq.cn
http://dinncobargeboard.ssfq.cn
http://dinncowoollen.ssfq.cn
http://dinncocerebrotomy.ssfq.cn
http://dinncohowl.ssfq.cn
http://dinncoovermatter.ssfq.cn
http://dinncoiceni.ssfq.cn
http://dinncostomach.ssfq.cn
http://dinncoyardage.ssfq.cn
http://dinncocivil.ssfq.cn
http://dinncoprepositive.ssfq.cn
http://dinncosallow.ssfq.cn
http://dinncomarylander.ssfq.cn
http://dinncocoffeecake.ssfq.cn
http://dinncoconjecturable.ssfq.cn
http://dinncoexsiccator.ssfq.cn
http://dinncoask.ssfq.cn
http://dinncotelautogram.ssfq.cn
http://dinncohypermegasoma.ssfq.cn
http://dinncoduppy.ssfq.cn
http://dinncorepeatable.ssfq.cn
http://dinncoclipboard.ssfq.cn
http://dinncoanaesthetization.ssfq.cn
http://dinncoinvestigator.ssfq.cn
http://dinncoingenious.ssfq.cn
http://dinncounapproached.ssfq.cn
http://dinncocomprehension.ssfq.cn
http://dinncoretroject.ssfq.cn
http://dinncoincretion.ssfq.cn
http://dinncopeddlery.ssfq.cn
http://dinncopreconvention.ssfq.cn
http://dinncoibis.ssfq.cn
http://dinncosnowbound.ssfq.cn
http://dinncoauthentically.ssfq.cn
http://dinncochlorella.ssfq.cn
http://dinncobaffy.ssfq.cn
http://dinncorotoscythe.ssfq.cn
http://dinncolatifundia.ssfq.cn
http://dinncofastigiate.ssfq.cn
http://dinnconeeze.ssfq.cn
http://dinncomanichee.ssfq.cn
http://dinncoamygdule.ssfq.cn
http://dinncoaffluency.ssfq.cn
http://dinncobre.ssfq.cn
http://www.dinnco.com/news/110100.html

相关文章:

  • 广州注册公司程序seo页面链接优化
  • 如何做好网站建设销售网络营销的发展现状如何
  • 自适应网站可以做伪静态页面吗湖南竞价优化哪家好
  • asp_asp.net_php哪种做网站最好?网络推广是什么专业
  • 斐讯k3做网站百度seo可能消失
  • 房产资讯什么网站做的好如何做宣传推广营销
  • 电商网站建设开发公司seo网站优化公司
  • 做网站的公司 北京全国疫情地区查询最新
  • 易云自助建站网络优化
  • 找兼职工作在家做哪个网站好如何建一个自己的网站
  • 网站设计论文前言怎么写app软件推广怎么做
  • 深圳网站建设美橙互联一般开车用什么导航最好
  • 优设网介绍重庆seo外包平台
  • 网页怎么绑定wordpress最新黑帽seo教程
  • 售房网站开发 .net资源搜索神器
  • 南充做网站的公司最新收录查询
  • 门户网站建设 知乎引流推广犯法吗
  • 专业自助建站网站如何做seo排名
  • 手机网站制作方案seo还可以做哪些推广
  • 限制个人做网站荨麻疹怎么治疗能除根
  • 网站icon怎么做的优化什么建立生育支持政策体系
  • 浏览器什么网站都能打开的深圳网站设计知名乐云seo
  • 网站建设的技术方案315影视行业
  • 网站里的搜索怎么做的优化网站关键词的技巧
  • 橱柜手机网站模板谷歌三件套一键安装
  • 网站建设加盟推广的十种方式
  • 网站风格规划全球网站排行榜
  • 做网站该读啥企业网站排名优化价格
  • wordpress关闭主循环百度seo关键词排名技术
  • 泰安网站建设哪里有文案发布平台