创建hbase表和全文索引

  其他常见问题
内容纲要

概要描述


本文介绍如何创建hbase表及全文索引。

详细说明


两种方法:

第一种,在hbase shell中创建hbase表和全文索引

0、配置hyperbase对search的依赖,配置服务,重启hyperbase
file
1、先把json串文件test.txt放到/tmp下
file
test.txt文件内容如下:

{
    "tableName": "dd",
    "base": {
        "families": [
            {
                "FAMILY": "oa",
                "DATA_BLOCK_ENCODING": "NONE",
                "BLOOMFILTER": "ROW",
                "REPLICATION_SCOPE": "0",
                "VERSIONS": "1",
                "COMPRESSION": "NONE",
                "MIN_VERSIONS": "0",
                "TTL": "2147483647",
                "KEEP_DELETED_CELLS": "false",
                "BLOCKSIZE": "65536",
                "IN_MEMORY": "false",
                "BLOCKCACHE": "true"
            }
        ],
        "THEMIS_ENABLE": false
    },
    "fulltextindex": {

        "tableName": "dd",
        "allowUpdate": true,
        "ttl": 0,
        "source": true,
        "all": false,
        "fields": [
            {
                "family": "oa",
                "qualifier": "ct",
                "attributes": {
                    "index": "analyzed",
                    "store": "true",
                    "type": "string",
                    "analyzer": "mmseg"
                }
            },
            {
                "family": "oa",
                "qualifier": "dt",
                "attributes": {
                                                        "index" : "not_analyzed",
                    "store": "true",
                    "type": "string"
                }
            },
            {
                "family": "oa",
                "qualifier": "key_a",
                "attributes": {
                    "index": "not_analyzed",
                    "store": "true",
                    "type": "string"
                }
            },
            {
                "family": "oa",
                "qualifier": "tt",
                "attributes": {
                    "index": "analyzed",
                    "store": "true",
                    "type": "string",
                    "analyzer": "mmseg"
                }
            },
            {
                "family": "oa",
                "qualifier": "us",
                "attributes": {
                    "index": "analyzed",
                    "store": "true",
                    "type": "string",
                    "analyzer": "mmseg"
                }
            }
        ],
        "settings": {
            "index.number_of_replicas": "1",
            "index.number_of_shards": "20"
        }
    },
    "globalindex": {
        "indexs": []
    },
    "lob": {
        "indexs": []
    },
    "localindex": {}
}

2、source tdh客户端内的init.sh文件:source TDH-client/init.sh
如何准备TDH客户端环境

3、输入hbase shell进入hbase shell编辑框
file

4、执行下面命令,创建名为表名为dd的hbase表,并为其创建全文索引:

alterUseJson 'dd' ,'/tmp/test.txt' , 'true'

file
5、list查看,可以看到表dd
file

6、在search上看,可以看到全文索引
file
file

第二种,inceptor中通过SQL创建hbase表,创建全文索引

0、配置inceptor对hyperbase的依赖,配置服务,重启inceptor
file

1、配置hyperbase对search的依赖,配置服务,重启hyperbase
file

2、source tdh客户端内的init.sh文件:source TDH-client/init.sh
如何准备TDH客户端环境

3、beeline连接inceptor:将下面的ip换成您的inceptor server的ip,-n 跟hive用户名,-p 跟hive的密码

beeline -u "jdbc:hive2://172.22.27.1:10000/default" -n hive -p 123456

file

4、建hbase表

create table testhbase(key1 string,bi bigint,dc decimal(10,2),ch varchar(10),ts timestamp,en string)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler';

file
5、给表创建全文索引

CREATE FULLTEXT INDEX ON testhbase(bi,ch,en) SHARD NUM 1;

6、查看索引信息

describe FORMATTED testhbase;

file
7、在search上查看索引信息
file

可能会遇到的问题:

1、在用第二种方法建表的时候,可能会遇到hive没有权限的报错:

Error: EXECUTION FAILED: Task DDL error HiveException: [Error 20604] Can not create table: org.apache.hadoop.hbase.security.AccessDeniedException: org.apache.hadoop.hbase.security.AccessDeniedException: Insufficient permissions (user=hive/tdh6-1@TDH, scope=default, params=[namespace=default,table=default:testhbase,family=f],action=ADMIN) (state=08S01,code=20604)

file

解决方法:
在guardian中给hive用户配置创建hbase表的权限:
登录guardian
file
权限中找到hyperbase
file
为hive添加权限
file

这篇文章对您有帮助吗?

平均评分 5 / 5. 次数: 1

尚无评价,您可以第一个评哦!

非常抱歉,这篇文章对您没有帮助.

烦请您告诉我们您的建议与意见,以便我们改进,谢谢您。