| 1 | = HQL Tutorial = |
| 2 | == Tutorial from Google == |
| 3 | * HQL Tutorial: [http://code.google.com/p/hypertable/wiki/HQLTutorial Google] |
| 4 | == Our Test == |
| 5 | * Test from local drvie |
| 6 | * CPU: Intel(R) Pentium(R) D CPU 3.40GHz * 2 |
| 7 | * Hard Disk: SCSI 150G * 1 |
| 8 | * Partition: /dev/sda1 mount on / |
| 9 | * Instruction |
| 10 | * Run Hypertable |
| 11 | {{{ |
| 12 | sunny@hsihdp:~/hypertable/0.9.0.5$ bin/hypertable |
| 13 | |
| 14 | Welcome to the hypertable command interpreter. |
| 15 | For information about Hypertable, visit http://www.hypertable.org/ |
| 16 | |
| 17 | Type 'help' for a list of commands, or 'help shell' for a |
| 18 | list of shell meta commands. |
| 19 | }}} |
| 20 | * Help Command |
| 21 | {{{ |
| 22 | hypertable> help |
| 23 | |
| 24 | CREATE TABLE ....... Creates a table |
| 25 | DELETE ............. Deletes all or part of a row from a table |
| 26 | DESCRIBE TABLE ..... Displays a table's schema |
| 27 | DROP TABLE ......... Removes a table |
| 28 | INSERT ............. Inserts data into a table |
| 29 | LOAD DATA INFILE ... Loads data from a tab delimited input file into a table |
| 30 | SELECT ............. Selects (and display) cells from a table |
| 31 | SHOW CREATE TABLE .. Displays CREATE TABLE command used to create table |
| 32 | SHOW TABLES ........ Displays the list of tables |
| 33 | |
| 34 | Statements must be terminated with ';' to execute. For more information on |
| 35 | a specific statement, type 'help <statement>', where <statement> is one from |
| 36 | the preceeding list. |
| 37 | }}} |
| 38 | * Show "Pages" Table Schema |
| 39 | {{{ |
| 40 | hypertable> show create table Pages; |
| 41 | |
| 42 | CREATE TABLE Pages ( |
| 43 | 'refer-url', |
| 44 | 'http-code', |
| 45 | timestamp, |
| 46 | rowkey, |
| 47 | ACCESS GROUP default ( 'refer-url', 'http-code', timestamp, rowkey ) |
| 48 | ) |
| 49 | }}} |
| 50 | * Drop "Pages" Table |
| 51 | {{{ |
| 52 | hypertable> drop table Pages; |
| 53 | hypertable> show create table Pages; |
| 54 | |
| 55 | 1205915835 ERROR hypertable : (/home/sunny/git/hypertable/src/cc/Hypertable/Lib/MasterClient.cc:114) Master 'get schema' error, tableName=Pages : HYPERSPACE bad pathname : Unable to open Hyperspace table file '/hypertable/tables/Pages' (HYPERSPACE bad pathname) |
| 56 | Error: Problem fetching schema for table 'Pages' from master - HYPERSPACE bad pathname |
| 57 | }}} |
| 58 | * Create "Pages" Table |
| 59 | {{{ |
| 60 | hypertable> create table Pages (date, "refer-url", "http-code"); |
| 61 | }}} |
| 62 | * Show "Pages" Table Schema |
| 63 | {{{ |
| 64 | hypertable> show create table Pages; |
| 65 | |
| 66 | CREATE TABLE Pages ( |
| 67 | 'refer-url', |
| 68 | 'http-code', |
| 69 | date, |
| 70 | ACCESS GROUP default ( 'refer-url', 'http-code', date ) |
| 71 | ) |
| 72 | |
| 73 | hypertable> describe table Pages; |
| 74 | |
| 75 | <Schema generation="1"> |
| 76 | <AccessGroup name="default"> |
| 77 | <ColumnFamily id="1"> |
| 78 | <Name>refer-url</Name> |
| 79 | </ColumnFamily> |
| 80 | <ColumnFamily id="2"> |
| 81 | <Name>http-code</Name> |
| 82 | </ColumnFamily> |
| 83 | <ColumnFamily id="3"> |
| 84 | <Name>date</Name> |
| 85 | </ColumnFamily> |
| 86 | </AccessGroup> |
| 87 | </Schema> |
| 88 | }}} |
| 89 | * Load Sample Data into "Pages" Table |
| 90 | {{{ |
| 91 | hypertable> load data infile ROW_KEY_COLUMN=rowkey "examples/hql_tutorial/access.tsv" into table Pages; |
| 92 | |
| 93 | Loading 10,872,957 bytes of input data... |
| 94 | |
| 95 | 0% 10 20 30 40 50 60 70 80 90 100% |
| 96 | |----|----|----|----|----|----|----|----|----|----| |
| 97 | *************************************************** |
| 98 | Load complete. |
| 99 | |
| 100 | Elapsed time: 4.29 s |
| 101 | Avg value size: 18.68 bytes |
| 102 | Avg key size: 48.70 bytes |
| 103 | Throughput: 2534861.65 bytes/s |
| 104 | Total inserts: 300000 |
| 105 | Throughput: 69940.36 inserts/s |
| 106 | Resends: 0 |
| 107 | }}} |
| 108 | * Load Sample Data into File |
| 109 | {{{ |
| 110 | hypertable> load data infile ROW_KEY_COLUMN=rowkey "examples/hql_tutorial/access.tsv" into file "test.tsv"; |
| 111 | |
| 112 | Loading 10,872,957 bytes of input data... |
| 113 | |
| 114 | 0% 10 20 30 40 50 60 70 80 90 100% |
| 115 | |----|----|----|----|----|----|----|----|----|----| |
| 116 | *************************************************** |
| 117 | Load complete. |
| 118 | |
| 119 | Elapsed time: 0.56 s |
| 120 | Avg value size: 18.68 bytes |
| 121 | Avg key size: 48.70 bytes |
| 122 | Throughput: 19275729.29 bytes/s |
| 123 | Total inserts: 300000 |
| 124 | Throughput: 531844.17 inserts/s |
| 125 | }}} |
| 126 | * Show top 10 lines of "test.tsv" File |
| 127 | {{{ |
| 128 | sunny@hsihdp:~/hypertable/0.9.0.5$ head -10 test.tsv |
| 129 | |
| 130 | rowkey columnkey value |
| 131 | events.mercurynews.com/venues date 2008-01-25 15:19:32 |
| 132 | events.mercurynews.com/venues refer-url events.mercurynews.com/search |
| 133 | events.mercurynews.com/venues http-code 200 |
| 134 | www.zvents.com/events/auto_complete_for_artist_name date 2008-01-25 15:19:32 |
| 135 | www.zvents.com/events/auto_complete_for_artist_name refer-url www.zvents.com/indio-ca/events/show/81296496-coachella |
| 136 | www.zvents.com/events/auto_complete_for_artist_name http-code 200 |
| 137 | calendar.denverpost.com/search date 2008-01-25 15:19:32 |
| 138 | calendar.denverpost.com/search refer-url calendar.denverpost.com/search |
| 139 | calendar.denverpost.com/search http-code 200 |
| 140 | }}} |
| 141 | * HQL Command: SELECT |
| 142 | {{{ |
| 143 | hypertable> select 'http-code' from Pages where ROW='events.getoutaz.com/scottsdale-az/venues/show/455885-scorch-bar'; |
| 144 | |
| 145 | events.getoutaz.com/scottsdale-az/venues/show/455885-scorch-bar http-code 200 |
| 146 | events.getoutaz.com/scottsdale-az/venues/show/455885-scorch-bar http-code 200 |
| 147 | events.getoutaz.com/scottsdale-az/venues/show/455885-scorch-bar http-code 200 |
| 148 | events.getoutaz.com/scottsdale-az/venues/show/455885-scorch-bar http-code 200 |
| 149 | }}} |
| 150 | * HQL Command: SELECT & Show Timestamps |
| 151 | {{{ |
| 152 | hypertable> select "http-code" from Pages where ROW = "www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin" |
| 153 | DISPLAY_TIMESTAMPS; |
| 154 | |
| 155 | 2008-03-19 08:38:53.546882123 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 156 | 2008-03-19 08:38:53.546882120 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 157 | 2008-03-19 08:38:52.898828170 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 158 | 2008-03-19 08:38:51.670966231 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 159 | 2008-03-19 08:38:51.670966230 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 160 | 2008-03-19 08:38:51.430784186 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 161 | }}} |
| 162 | * HQL Command: SELECT with Timestamps filter |
| 163 | {{{ |
| 164 | hypertable> select "http-code" from Pages where ROW = "www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin" && TIMESTAMP > '2008-02-02 15:53:00' && TIMESTAMP <= '2008-02-02 15:53:02' DISPLAY_TIMESTAMPS; |
| 165 | |
| 166 | 2008-03-19 08:38:53.546882123 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 167 | 2008-03-19 08:38:53.546882120 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 168 | 2008-03-19 08:38:52.898828170 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 169 | 2008-03-19 08:38:51.670966231 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 170 | 2008-03-19 08:38:51.670966230 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 171 | 2008-03-19 08:38:51.430784186 www.zvents.com/san-francisco-ca/events/show/80283482-steve-martin http-code 200 |
| 172 | }}} |