美文网首页
phoenix与hbase表的映射

phoenix与hbase表的映射

作者: codingbug | 来源:发表于2020-06-30 22:19 被阅读0次

    1. hbase 建表

    # ./hbase shell
    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.1-2/phoenix/phoenix-5.0.0.3.1.5.1-2-server.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.1-2/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.1-2/hbase/lib/client-facing-thirdparty/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
    HBase Shell
    Use "help" to get list of supported commands.
    Use "exit" to quit this interactive shell.
    For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
    Version 2.1.6.3.1.5.1-2, rUnknown, Thu May  7 11:28:49 CST 2020
    Took 0.0105 seconds
    
    hbase(main):039:0> list
    TABLE                                                                                                                                                                                                        
    SYSTEM.CATALOG                                                                                                                                                                                               
    SYSTEM.FUNCTION                                                                                                                                                                                              
    SYSTEM.LOG                                                                                                                                                                                                   
    SYSTEM.MUTEX                                                                                                                                                                                                 
    SYSTEM.SEQUENCE                                                                                                                                                                                              
    SYSTEM.STATS                                                                                                                                                                                                 
    6 row(s)
    Took 0.0130 seconds                                                                                                                                                                                          
    => ["SYSTEM.CATALOG", "SYSTEM.FUNCTION", "SYSTEM.LOG", "SYSTEM.MUTEX", "SYSTEM.SEQUENCE", "SYSTEM.STATS"]
    
    hbase(main):001:0> create "student","info"
    Created table student
    Took 2.7546 seconds                                                                                                                                                                                          
    => Hbase::Table - student
    hbase(main):042:0> put 'student','r1','info:name','zhangSan'
    Took 1.4861 seconds                                                                                                                                                                                          
    hbase(main):043:0> put 'student','r1','info:sex','man'
    Took 0.0072 seconds  
    

    2. phoenix建表

    # ./sqlline.py host1:2181
    Setting property: [incremental, false]
    Setting property: [isolation, TRANSACTION_READ_COMMITTED]
    issuing: !connect jdbc:phoenix:host1:2181 none none org.apache.phoenix.jdbc.PhoenixDriver
    Connecting to jdbc:phoenix:host1:2181
    SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.1-2/phoenix/phoenix-5.0.0.3.1.5.1-2-client.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.1-2/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    20/06/23 16:21:05 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    Connected to: Phoenix (version 5.0)
    Driver: PhoenixEmbeddedDriver (version 5.0)
    Autocommit status: true
    Transaction isolation: TRANSACTION_READ_COMMITTED
    Building list of tables and columns for tab-completion (set fastconnect to true to skip)...
    136/136 (100%) Done
    Done
    sqlline version 1.2.0
    0: jdbc:phoenix:host1:2181> !tables
    
    image-20200623161510016.png
    0: jdbc:phoenix:host1:2181> create table if not exists "student"("ROW" varchar primary key,"info"."name" varchar,"info"."sex" varchar);
    0: jdbc:phoenix:host1:2181> select * from "student";
    +------+-----------+------+
    | ROW  |   name    | sex  |
    +------+-----------+------+
    | r1   | zhangSan  | man  |
    +------+-----------+------+
    1 row selected (0.057 seconds)
    

    phoenix建表注意事项:

    语法比较严格create table if not exists "table_name"("ROW" varchar primary key,"列簇"."列名" varchar,"列簇"."列名" varchar,...)

    table_name需要加引号,查询的时候也要加引号才能查出来

    hbase表中的rowkey映射为了phoenix表中的"ROW","ROW"要加引号

    phoenix中的其它列名必须为"列簇"."列名"的形式,与hbase 表中的列簇及列名要对应

    注意引号,创建表的时候加了引号,查询时不加引号会报如下错误:

    0: jdbc:phoenix:host1:2181> select * from student;
    Error: ERROR 1012 (42M03): Table undefined. tableName=STUDENT (state=42M03,code=1012)
    org.apache.phoenix.schema.TableNotFoundException: ERROR 1012 (42M03): Table undefined. tableName=STUDENT
        at org.apache.phoenix.compile.FromCompiler$BaseColumnResolver.createTableRef(FromCompiler.java:577)
        at org.apache.phoenix.compile.FromCompiler$SingleTableColumnResolver.<init>(FromCompiler.java:391)
        at org.apache.phoenix.compile.FromCompiler.getResolverForQuery(FromCompiler.java:228)
        at org.apache.phoenix.compile.FromCompiler.getResolverForQuery(FromCompiler.java:206)
        at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:482)
        at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableSelectStatement.compilePlan(PhoenixStatement.java:456)
        at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:302)
        at org.apache.phoenix.jdbc.PhoenixStatement$1.call(PhoenixStatement.java:291)
        at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
        at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:290)
        at org.apache.phoenix.jdbc.PhoenixStatement.executeQuery(PhoenixStatement.java:283)
        at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1830)
        at sqlline.Commands.execute(Commands.java:822)
        at sqlline.Commands.sql(Commands.java:732)
        at sqlline.SqlLine.dispatch(SqlLine.java:813)
        at sqlline.SqlLine.begin(SqlLine.java:686)
        at sqlline.SqlLine.start(SqlLine.java:398)
        at sqlline.SqlLine.main(SqlLine.java:291)
    

    相关文章

      网友评论

          本文标题:phoenix与hbase表的映射

          本文链接:https://www.haomeiwen.com/subject/libfqktx.html