1、建表

执行建表语句
$ ./psql.py localhost:2181 ../examples/stock_symbol.sql 其中../examples/stock_symbol.sql是建表的sql语句 CREATE TABLE IF NOT EXISTS WEB_STAT (
HOST CHAR(2) NOT NULL,
DOMAIN VARCHAR NOT NULL,
FEATURE VARCHAR NOT NULL,
DATE DATE NOT NULL,
USAGE.CORE BIGINT,--usage指定列族名
USAGE.DB BIGINT,--usage指定列族名
STATS.ACTIVE_VISITOR INTEGER
CONSTRAINT PK PRIMARY KEY (HOST, DOMAIN, FEATURE, DATE)--指定主键
);

2、导入数据

命令:./psql.py -t WEB_STAT localhost:2181 ../examples/web_stat.csv

PS:其中 -t 后面是表名, ../examples/web_stat.csv 是csv数据(注意数据的分隔符需要是逗号)。

3、查询数据

  首先使用sqlline查看(截图为部分列的数据),查询表名不区分大小写。

  查询1、查询全部记录

    语句:select * from web_stat;

  查询2、查询记录总条数

    语句:select count(1) from web_stat;

  查询3、查询结果分组排序

    语句:select domain,count(1) as num from web_stat group by domain order by num desc;

  查询4、求平均值

    语句:select avg(core) from web_stat;

  查询5、多字段分组,排序,别名。

    语句:select domain,count(1) as num,avg(core) as core,avg(db) as db from web_stat group by domain order by num desc;

  查询6、查询日期类型字段

    语句:select host,domain,date from web_stat where TO_CHAR(date)='2013-01-15 07:09:01.000';

  查询7、字符串,日期类型转换

    语句:select TO_DATE('20131125','yyyyMMdd') from web_stat;

    Ps:输入的日期字符串会被转换为hbase表date的日期类型。

  总结:Phoenix还支持了很多函数和sql语法,在这里不再一一列举。更多请参考Phoenix支持部分

4、Phoenix基本shell命令

  PS:以下,可能有部分命令在Phoenix更高版本中已失效,改为其他命令代替,请注意。 

0: jdbc:phoenix:localhost> help
!all Execute the specified SQL against all the current connections
!autocommit Set autocommit mode on or off
!batch Start or execute a batch of statements
!brief Set verbose mode off
!call Execute a callable statement
!close Close the current connection to the database
!closeall Close all current open connections
!columns List all the columns for the specified table
!commit Commit the current transaction (if autocommit is off)
!connect Open a new connection to the database.
!dbinfo Give metadata information about the database
!describe Describe a table
!dropall Drop all tables in the current database
!exportedkeys List all the exported keys for the specified table
!go Select the current connection
!help Print a summary of command usage
!history Display the command history
!importedkeys List all the imported keys for the specified table
!indexes List all the indexes for the specified table
!isolation Set the transaction isolation for this connection
!list List the current connections
!manual Display the SQLLine manual
!metadata Obtain metadata information
!nativesql Show the native SQL for the specified statement
!outputformat Set the output format for displaying results
(table,vertical,csv,tsv,xmlattrs,xmlelements)
!primarykeys List all the primary keys for the specified table
!procedures List all the procedures
!properties Connect to the database specified in the properties file(s)
!quit Exits the program 此命令在Phoenix4.3版本已改为!exit
!reconnect Reconnect to the database
!record Record all output to the specified file
!rehash Fetch table and column names for command completion
!rollback Roll back the current transaction (if autocommit is off)
!run Run a script from the specified file
!save Save the current variabes and aliases
!scan Scan for installed JDBC drivers
!script Start saving a script to a file
!set Set a sqlline variable

HBase 5、Phoenix使用的更多相关文章

  1. Unable to connect to HBase using Phoenix JDBC Driver

    Feb 01, 2017; 5:21pm Unable to connect to HBase using Phoenix JDBC Driver 9 posts Hi All,   I am try ...

  2. Ubuntu16.04下伪分布式环境搭建之hadoop、jdk、Hbase、phoenix的安装与配置

    一.准备工作 安装包链接: https://pan.baidu.com/s/1i6oNmOd 密码: i6nc 环境准备 修改hostname: $ sudo vi /etc/hostname why ...

  3. Hbase(一)了解Hbase与Phoenix

    前言 HBase是一个分布式的.面向列的开源数据库,该技术来源于 Fay Chang 所撰写的Google论文“Bigtable:一个结构化数据的分布式存储系统”.就像Bigtable利用了Googl ...

  4. Hadoop zookeeper hbase spark phoenix (HA)搭建过程

    环境介绍: 系统:centos7 软件包: apache-phoenix-4.14.0-HBase-1.4-bin.tar.gz  下载链接:http://mirror.bit.edu.cn/apac ...

  5. cdh版hbase构建Phoenix 遇到的坑

    Phoenix 构建cdh版hbase遇到的坑 1. 安装phoenix 下载:在github上下载对应版本https://github.com/apache/phoenix 解压:略 编译: 修改根 ...

  6. Phoneix(三)HBase集成Phoenix创建二级索引

    一.Hbase集成Phoneix 1.下载 在官网http://www.apache.org/dyn/closer.lua/phoenix/中选择提供的镜像站点中下载与安装的HBase版本对应的版本. ...

  7. Phoneix(二)HBase集成Phoenix安装

    一.软件下载 1.访问:http://phoenix.apache.org/ 2.点击: 3.进入以下内容:点击 4.跳转到 5.跳转到 6.点击安装包,进入 点击进行下载: 二.安装 phoneni ...

  8. Hbase与Phoenix整合

    目录 一.简介 二.安装 三.Phoenix Shell操作 SCHEMA操作 1.创建schema 2.使用schema 3.删除schema 表操作 1.显示所有表 2.创建表 3.表数据的增删改 ...

  9. Phoenix实现用SQL查询HBase

    博客已转移,请借一步说话,http://www.weixuehao.com/archives/111 HBase,一个NoSQL数据库,可存储大量非关系型数据. HBase,可以用HBase shel ...

  10. Phoenix - Hbase与SQL

    Phoenix - Hbase与SQL 2016-10-23 杜亦舒 Phoenix是什么 简单来说,Phoenix 是一个可以让我们通过SQL的方式操作HBase数据库的框架. HBase是一个No ...

随机推荐

  1. Linux usb子系统(一):子系统架构

    一.USB协议基础知识   前序:USB概念概述 USB1.0版本速度1.5Mbps(低速USB) USB1.1版本速度12Mbps(全速USB)  USB2.0版本速度480Mbps(高速USB). ...

  2. A星算法

    没有采用二叉堆算法优化, 学习了几天终于搞除了一个demo, 这个列子如果点击按钮生成的方块大小不正确,可以先设置下预设调成相应的大小 只能上下左右走   using UnityEngine; usi ...

  3. deciaml(十进制浮点运算)

    # -*- coding: utf-8 -*- # ==================== #File: python #Author: python #Date: 2014 #========== ...

  4. Android硬件抽象层(HAL)概要介绍和学习计划

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6567257 Android的硬件抽象层,简单来 ...

  5. Git 笔记二-Git安装与初始配置

    git 笔记二-Git安装与初始配置 Git的安装 由于我日常生活和工作基本上都是在Windows上,因此此处只说windows上的安装.Windows上的安装和其他程序一样,只需要到http://g ...

  6. MySQL学习笔记:MySQL: ERROR 1064(42000)

    ERROR 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL s ...

  7. Makefile 工程管理

    Makefile 工程管理 Makefile 规则 --变量 在Makefile中,用户除了可以自己定义变量外,还可以使用存在系统已经定义好的默认变量 $^:代表所有的依赖文件 $@:代表目标 $&l ...

  8. ASP.NET内核几大对象、ASP.NET核心知识(7)--转载

    本文的学习流程是这样安排的. 一个简单的GDI小案例 1.说明 如果你想思考如何生成验证码,那么您第一个要解决的问题,一定是.NET动态生成图片问题. //GDI:.Net程序中进行绘图的一些类. 2 ...

  9. angular的数据双向绑定秘密

    Angular用户都想知道数据绑定是怎么实现的.你可能会看到各种各样的词汇:$watch,$apply,$digest,dirty-checking... 它们是什么?它们是如何工作的呢?这里我想回答 ...

  10. python os模块文件相关

    使用前 import os导入模块   os模块: os.sep     可以取代操作系统特定的路径分割符 os.linesep  字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...