楼主: 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
31#
 楼主| 发表于 2013-6-28 21:51 | 只看该作者
HADOOP STREAMING MAPREDUCE

In order to run this example, Hadoop needs to be installed and HDFS and the MapReduce framework needs to be up and running.  Hypertable builds against Cloudera's CDH3 distribution of hadoop.  See CDH3 Installation for instructions on how to get Hadoop up and running.

In this example, we'll be running a Hadoop Streaming MapReduce job that uses a Bash script as the mapper and a Bash script as the reducer.  Like the example in the previous section, the programs operate on a table called wikipedia that has been loaded with a Wikipedia dump.

Setup

First, exit the Hypertable command line interpreter and download the Wikipedia dump, for example:
  1. $ wget http://cdn.hypertable.com/pub/wikipedia.tsv.gz
复制代码

使用道具 举报

回复
论坛徽章:
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
32#
 楼主| 发表于 2013-6-28 21:52 | 只看该作者
Next, jump back into the Hypertable command line interpreter and create the wikipedia table by executing the HQL commands show below.
  1. CREATE NAMESPACE test;
  2. USE test;
  3. DROP TABLE IF EXISTS wikipedia;
  4. CREATE TABLE wikipedia (
  5.        title,
  6.        id,
  7.        username,
  8.        article,
  9.        word
  10. );
复制代码

使用道具 举报

回复
论坛徽章:
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
33#
 楼主| 发表于 2013-6-28 21:52 | 只看该作者
Now load the compressed Wikipedia dump file directly into the wikipedia table by issuing the following HQL commands:
  1. hypertable> LOAD DATA INFILE "wikipedia.tsv.gz" INTO TABLE wikipedia;

  2. Loading 638,058,135 bytes of input data...

  3. 0%   10   20   30   40   50   60   70   80   90   100%
  4. |----|----|----|----|----|----|----|----|----|----|
  5. ***************************************************
  6. Load complete.

  7.   Elapsed time:  78.28 s
  8. Avg value size:  1709.59 bytes
  9.   Avg key size:  24.39 bytes
  10.     Throughput:  25226728.63 bytes/s (8151017.58 bytes/s)
  11.    Total cells:  1138847
  12.     Throughput:  14548.46 cells/s
  13.        Resends:  8328
复制代码
The mapper script (tokenize-article.sh) and the reducer script (reduce-word-counts.sh) are show below.

使用道具 举报

回复
论坛徽章:
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
34#
 楼主| 发表于 2013-6-28 21:53 | 只看该作者
Example

The following script, tokenize-article.sh, will be used as the mapper script.
  1. #!/usr/bin/env bash

  2. IFS="   "
  3. read name column article

  4. while [ $? == 0 ] ; do

  5.   if [ "$column" == "article" ] ; then

  6.     # Strip punctuation
  7.     stripped_article=`echo $article | awk 'BEGIN { FS="\t" } { print $NF }' | tr "\!\"#\[        DISCUZ_CODE_3        ]'()*+,-./:;<=>?@[\\\\]^_\{|}~" " " | tr -s " "` ;

  8.     # Split article into words
  9.     echo $stripped_article | awk -v name="$name" 'BEGIN { article=name; FS=" "; } { for (i=1; i<=NF; i++) printf "%s\tword:%s\t1\n", article, $i; }' ;

  10.   fi

  11.   # Read another line
  12.   read name column article

  13. done
  14. exit 0
复制代码

使用道具 举报

回复
论坛徽章:
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
35#
 楼主| 发表于 2013-6-28 21:53 | 只看该作者
The following script, reduce-word-counts.sh, will be used as the reducer script.
  1. #!/usr/bin/env bash

  2. last_article=
  3. last_word=
  4. let total=0

  5. IFS="   "
  6. read article word count

  7. while [ $? == 0 ] ; do
  8.     if [ "$article" == "$last_article" ] && [ "$word" == "$last_word" ] ; then
  9.         let total=$count+total
  10.     else
  11.         if [ "$last_word" != "" ]; then
  12.             echo "$last_article $last_word      $total"
  13.         fi
  14.         let total=$count
  15.         last_word=$word
  16.         last_article=$article
  17.     fi
  18.     read article word count
  19. done

  20. if [ $total -gt 0 ] ; then
  21.     echo "$last_article $last_word      $total"
  22. fi
  23. exit 0
复制代码

使用道具 举报

回复
论坛徽章:
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
36#
 楼主| 发表于 2013-6-29 01:39 | 只看该作者
To populate the word column of the wikipedia table by tokenizing the article column using the above mapper and reduce script, issue the following command:
  1. hypertable> quit

  2. $ hadoop jar /usr/lib/hadoop-0.20/contrib/streaming/hadoop-streaming-0.20.2-cdh3u*.jar \
  3. -libjars /opt/hypertable/current/lib/java/hypertable-*.jar,/opt/hypertable/current/lib/java/libthrift-*.jar \
  4. -Dhypertable.mapreduce.namespace=test \
  5. -Dhypertable.mapreduce.input.table=wikipedia \
  6. -Dhypertable.mapreduce.output.table=wikipedia \
  7. -mapper /home/doug/tokenize-article.sh \
  8. -combiner /home/doug/reduce-word-counts.sh \
  9. -reducer /home/doug/reduce-word-counts.sh \
  10. -file /home/doug/tokenize-article.sh \
  11. -file /home/doug/reduce-word-counts.sh \
  12. -inputformat org.hypertable.hadoop.mapred.TextTableInputFormat \
  13. -outputformat org.hypertable.hadoop.mapred.TextTableOutputFormat \
  14. -input wikipedia -output wikipedia
复制代码

使用道具 举报

回复
论坛徽章:
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
37#
 楼主| 发表于 2013-6-29 01:39 | 只看该作者
Input/Output Configuration Properties

The following table lists the job configuration properties that are used to specify, among other things, the input table, output table, and scan specification. These properties can be supplied to a streaming MapReduce job with -Dproperty=value arguments.
  1. Input/Output Configuration Properties
  2. Property         Description         Example Value
  3. hypertable.mapreduce.namespace         Namespace for both input and output table        /test
  4. hypertable.mapreduce.input.namespace         Namespace for input table        /test/intput
  5. hypertable.mapreduce.input.table         Input table name        wikipedia
  6. hypertable.mapreduce.input.scan_spec.columns         Comma separated list of input columns        id,title
  7. hypertable.mapreduce.input.scan_spec.options         Input WHERE clause options. These options (i.e. LIMIT, OFFSET) are evaluated for each single job        MAX_VERSIONS 1 KEYS_ONLY
  8. hypertable.mapreduce.input.scan_spec.row_interval         Input row interval        Dog <= ROW < Kitchen
  9. hypertable.mapreduce.input.scan_spec.timestamp_interval         Timestamp filter        TIMESTAMP >= 2011-11-21
  10. hypertable.mapreduce.input.include_timestamps         Emit integer timestamp as the
  11. 1st field (nanoseconds since epoch)        true
  12. hypertable.mapreduce.output.namespace         Namespace containing output table        /test/output
  13. hypertable.mapreduce.output.table         Output table name        wikipedia
  14. hypertable.mapreduce.output.mutator_flags         flags parameter passed to mutator constructor (1 = NO_LOG_SYNC)        1
  15. hypertable.mapreduce.thriftbroker.framesize         sets the ThriftClient framesize (in bytes); the default is 16 MB         20971520
复制代码

使用道具 举报

回复
论坛徽章:
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
38#
 楼主| 发表于 2013-6-29 01:40 | 只看该作者
Column Selection

To run a MapReduce job over a subset of columns from the input table, specify a comma separated list of columns in the hypertable.mapreduce.input.scan_spec.columns Hadoop configuration property.  For example,
  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.input.scan_spec.columns="id,title" \
  6. -mapper /bin/cat -reducer /bin/cat \
  7. -inputformat org.hypertable.hadoop.mapred.TextTableInputFormat \
  8. -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
39#
 楼主| 发表于 2013-6-29 01:40 | 只看该作者
Timestamps

To filter the input table with a timestamp predicate, specify the timestamp predicate in the hypertable.mapreduce.input.scan_spec.timestamp_interval Hadoop configuration property. The timestamp 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:

TIMESTAMP < 2010-08-03 12:30:00
TIMESTAMP >= 2010-08-03 12:30:00
2010-08-01 <= TIMESTAMP <= 2010-08-09

使用道具 举报

回复
论坛徽章:
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
40#
 楼主| 发表于 2013-6-29 01:40 | 只看该作者
To preserve the timestamps from the input table, set the hypertable.mapreduce.input.include_timestamps Hadoop configuration property to true. This will cause the TextTableInputFormat class to produce an additional field (field 0) that represents the timestamp as nanoseconds since the epoch. The following example illustrates how to pass a timestamp predicate 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.timestamp_interval="2010-08-01 <= TIMESTAMP <= 2010-08-09" \
  8. -Dhypertable.mapreduce.input.include_timestamps=true \
  9. -mapper /bin/cat -reducer /bin/cat \
  10. -inputformat org.hypertable.hadoop.mapred.TextTableInputFormat \
  11. -outputformat org.hypertable.hadoop.mapred.TextTableOutputFormat \
  12. -input wikipedia -output wikipedia2
复制代码

使用道具 举报

回复

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

本版积分规则 发表回复

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