楼主: jieforest

Hypertable HQL指南

[复制链接]
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
41#
 楼主| 发表于 2013-6-30 13:36 | 只看该作者
Row Intervals

To restrict the MapReduce to a specific row interval of the input table, a row range can be specified with the hypertable.mapreduce.input.scan_spec.row_interval Hadoop configuration property. The row interval predicate is specified using the same format as the timestamp predicate in the WHERE clause of the SELECT statement, as illustrated in the following examples:

ROW < foo
ROW >= bar
bar <= ROW <= 'foo;'

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
42#
 楼主| 发表于 2013-6-30 13:36 | 只看该作者
The following example illustrates how a row interval is passed into a Hadoop Streaming MapReduce program.
  1. $ hadoop jar /usr/lib/hadoop-0.20/contrib/streaming/hadoop-streaming-0.20.2-cdh3u*.jar \
  2. -libjars /opt/hypertable/current/lib/java/hypertable-*.jar,/opt/hypertable/current/lib/java/libthrift-*.jar \
  3. -Dhypertable.mapreduce.namespace=test \
  4. -Dhypertable.mapreduce.input.table=wikipedia \
  5. -Dhypertable.mapreduce.output.table=wikipedia2 \
  6. -Dhypertable.mapreduce.input.scan_spec.columns="id,title" \
  7. -Dhypertable.mapreduce.input.scan_spec.row_interval="Dog <= ROW <= Kitchen" \
  8. -mapper /bin/cat -reducer /bin/cat \
  9. -inputformat org.hypertable.hadoop.mapred.TextTableInputFormat \
  10. -outputformat org.hypertable.hadoop.mapred.TextTableOutputFormat \
  11. -input wikipedia -output wikipedia2
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
43#
 楼主| 发表于 2013-6-30 13:37 | 只看该作者
Options

A subset of the WHERE clause options of the HQL SELECT statement can be specified by supplying the options with the hypertable.mapreduce.input.scan_spec.options Hadoop configuration property. The following options are supported:

MAX_VERSIONS
CELL_LIMIT
KEYS_ONLY

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
44#
 楼主| 发表于 2013-6-30 13:37 | 只看该作者
The following example illustrates how to pass options to a Hadoop Streaming MapReduce program.
  1. $ hadoop jar /usr/lib/hadoop-0.20/contrib/streaming/hadoop-streaming-0.20.2-cdh3u*.jar \
  2. -libjars /opt/hypertable/current/lib/java/hypertable-*.jar,/opt/hypertable/current/lib/java/libthrift-*.jar \
  3. -Dhypertable.mapreduce.namespace=test \
  4. -Dhypertable.mapreduce.input.table=wikipedia \
  5. -Dhypertable.mapreduce.output.table=wikipedia2 \
  6. -Dhypertable.mapreduce.input.scan_spec.options="MAX_VERSIONS 1 KEYS_ONLY CELL_LIMIT 2" \
  7. -mapper /bin/cat -reducer /bin/cat \
  8. -inputformat org.hypertable.hadoop.mapred.TextTableInputFormat \
  9. -outputformat org.hypertable.hadoop.mapred.TextTableOutputFormat \
  10. -input wikipedia -output wikipedia2
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
45#
 楼主| 发表于 2013-6-30 13:39 | 只看该作者
REGULAR EXPRESSION FILTERING

Hypertable supports filtering of data using regular expression matching on the rowkey, column qualifiers and value. Hypertable uses RE2 for regular expression matching, the complete supported syntax can be found in the RE2 Syntax document.

Example

In this example we'll use a DMOZ dataset which contains title, description and a bunch of topic tags for a set of URLs. The domain components of the URL have been reversed so that URLs from the same domain sort together. In the schema, the rowkey is a URL and the title, description and topic are column families. Heres a small sample from the dataset:
  1. com.awn.www     Title   Animation World Network com.awn.www     Description     Provides information resources to the international animation community. Features include searchable database archives, monthly magazine, web animation guide, the Animation Village, discussion forums and other useful resources.
  2. com.awn.www     Topic:Arts     
  3. com.awn.www     Topic:Animation
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
46#
 楼主| 发表于 2013-7-1 09:41 | 只看该作者
Exit the hypertable shell and download the dataset, which is in the .tsv.gz format which can be directly loaded into Hypertable without unzipping:
  1. hypertable> quit

  2. $ wget http://cdn.hypertable.com/pub/dmoz.tsv.gz
复制代码
Jump back into the hypertable shell and create the dmoz table as follows:
  1. /opt/hypertable/current/bin/ht shell

  2. hypertable> USE "/";
  3. hypertable> CREATE TABLE dmoz(Description, Title, Topic, ACCESS GROUP topic(Topic));
  4. hypertable> LOAD DATA INFILE "dmoz.tsv.gz" INTO TABLE dmoz;

  5. Loading 412,265,627 bytes of input data...

  6. 0%   10   20   30   40   50   60   70   80   90   100%
  7. |----|----|----|----|----|----|----|----|----|----|
  8. ***************************************************
  9. Load complete.

  10.   Elapsed time:  242.26 s
  11. Avg value size:  15.09 bytes
  12.   Avg key size:  24.76 bytes
  13.     Throughput:  6511233.28 bytes/s (1701740.27 bytes/s)
  14.    Total cells:  39589037
  15.     Throughput:  163414.69 cells/s
  16.        Resends:  144786
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
47#
 楼主| 发表于 2013-7-1 09:42 | 只看该作者
In the following queries we limit the number of rows returned to 2 for brevity. Suppose you want a subset of the URLs from the domain inria.fr where the first component of the domain doesn't start with the letter 'a', you could run:
  1. hypertable> SELECT Title FROM dmoz WHERE ROW REGEXP "fr\.inria\.[^a]" LIMIT 2 REVS=1 KEYS_ONLY;

  2. fr.inria.caml
  3. fr.inria.caml/pub/docs/oreilly-book
复制代码
To look at all topics which start with write (case insensitive):
  1. hypertable> SELECT Topic:/(?i)^write/ FROM dmoz LIMIT 2;

  2. 13.141.244.204/writ_den Topic:Writers_Resources
  3. ac.sms.www/clubpage.asp?club=CL001003004000301311       Topic:Writers_Resources
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
48#
 楼主| 发表于 2013-7-1 09:42 | 只看该作者
The next example shows how to query for data where the description contains the word game followed by either foosball or halo:
  1. hypertable> SELECT CELLS Description FROM dmoz WHERE VALUE REGEXP "(?i:game.*(foosball|halo)\s)" LIMIT 2 REVS=1;

  2. com.armchairempire.www/Previews/PCGames/planetside.htm  Description     Preview by Mr. Nash. "So, on the one side the game is sounding pretty snazzy, on the other it sounds sort of like Halo at its core."
  3. com.digitaldestroyers.www       Description     Video game fans in Spartanburg, South Carolina who like to get together and compete for bragging rights. Also compete with other Halo / Xbox fan clubs.
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
49#
 楼主| 发表于 2013-7-1 09:43 | 只看该作者
ATOMIC COUNTERS

Column families can optionally act as atomic counters by supplying the COUNTER option in the column specification of the CREATE TABLE command. Counter columns are accessed using the same methods as other columns. However, to modify the counter, the value must be formatted specially, as described in the following table.
  1. Value        Format Description
  2. ['+'] n         Increment the counter by n
  3. '-' n         Decrement the counter by n
  4. '=' n         Reset the counter to n
复制代码
Example

In this example we create a table of counters called counts that contains a single column family url that acts as an atomic counter for urls. By convention, the row key is the URL with the domain name reversed (so that URLs from the same domain sort next to each other) and the column qualifier is the hour in which the "hit" occurred. The table is created with the following HQL:
  1. hypertable> use "/";
  2. hypertable> create table counts ( url COUNTER );
复制代码

使用道具 举报

回复
论坛徽章:
277
马上加薪
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11版主9段
日期:2012-11-25 02:21:03ITPUB年度最佳版主
日期:2014-02-19 10:05:27现任管理团队成员
日期:2011-05-07 01:45:08
50#
 楼主| 发表于 2013-7-1 09:43 | 只看该作者
Let's say we've accumulated url "hit" occurrences in the following .tsv file:
  1. #row    column  value
  2. org.hypertable.www/     url:2010-10-26_09       +1
  3. org.hypertable.www/     url:2010-10-26_09       +1
  4. org.hypertable.www/download.html        url:2010-10-26_09       +1
  5. org.hypertable.www/documentation.html   url:2010-10-26_09       +1
  6. org.hypertable.www/download.html        url:2010-10-26_09       +1
  7. org.hypertable.www/about.html   url:2010-10-26_09       +1
  8. org.hypertable.www/     url:2010-10-26_09       +1
  9. org.hypertable.www/     url:2010-10-26_10       +1
  10. org.hypertable.www/about.html   url:2010-10-26_10       +1
  11. org.hypertable.www/     url:2010-10-26_10       +1
  12. org.hypertable.www/download.html        url:2010-10-26_10       +1
  13. org.hypertable.www/download.html        url:2010-10-26_10       +1
  14. org.hypertable.www/documentation.html   url:2010-10-26_10       +1
  15. org.hypertable.www/     url:2010-10-26_10       +1
复制代码

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表