| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | $key_space = 'png'; |
|---|
| 4 | $column_family = 'png'; |
|---|
| 5 | $column_family_date = 'date'; |
|---|
| 6 | |
|---|
| 7 | require_once 'Cassandra.php'; |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | // list of seed servers to randomly connect to |
|---|
| 11 | // all the parameters are optional and default to given values |
|---|
| 12 | $servers = array( |
|---|
| 13 | array( |
|---|
| 14 | 'host' => '127.0.0.1', |
|---|
| 15 | 'port' => 9160, |
|---|
| 16 | 'use-framed-transport' => true, |
|---|
| 17 | 'send-timeout-ms' => 1000, |
|---|
| 18 | 'receive-timeout-ms' => 1000 |
|---|
| 19 | ) |
|---|
| 20 | ); |
|---|
| 21 | |
|---|
| 22 | $cassandra = Cassandra::createInstance($servers); |
|---|
| 23 | |
|---|
| 24 | try { |
|---|
| 25 | $cassandra->dropKeyspace($key_space); |
|---|
| 26 | } catch (Exception $e) {} |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | $cassandra->createKeyspace($key_space); |
|---|
| 30 | $cassandra->useKeyspace($key_space); |
|---|
| 31 | $cassandra->setMaxCallRetries(5); |
|---|
| 32 | |
|---|
| 33 | $cassandra->createStandardColumnFamily( |
|---|
| 34 | $key_space, // keyspace name |
|---|
| 35 | $column_family, // the column-family name |
|---|
| 36 | array( // list of columns with metadata |
|---|
| 37 | array( |
|---|
| 38 | 'name' => 'name', |
|---|
| 39 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 40 | 'index-type' => Cassandra::INDEX_KEYS, // create secondary index |
|---|
| 41 | 'index-name' => 'NameIdx' |
|---|
| 42 | ), |
|---|
| 43 | array( |
|---|
| 44 | 'name' => 'content', |
|---|
| 45 | 'type' => Cassandra::TYPE_BYTES, |
|---|
| 46 | ), |
|---|
| 47 | array( |
|---|
| 48 | 'name' => 'type', |
|---|
| 49 | 'type' => Cassandra::TYPE_UTF8, |
|---|
| 50 | ), |
|---|
| 51 | array( |
|---|
| 52 | 'name' => 'date', |
|---|
| 53 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 54 | 'index-type' => Cassandra::INDEX_KEYS, |
|---|
| 55 | 'index-name' => 'DateIdx' |
|---|
| 56 | ), |
|---|
| 57 | array( |
|---|
| 58 | 'name' => 'hour', |
|---|
| 59 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 60 | 'index-type' => Cassandra::INDEX_KEYS, |
|---|
| 61 | 'index-name' => 'HourIdx' |
|---|
| 62 | ) |
|---|
| 63 | ) |
|---|
| 64 | // actually accepts more parameters with reasonable defaults |
|---|
| 65 | ); |
|---|
| 66 | |
|---|
| 67 | $cassandra->createStandardColumnFamily( |
|---|
| 68 | $key_space, // keyspace name |
|---|
| 69 | $column_family_date, // the column-family name |
|---|
| 70 | array( // list of columns with metadata |
|---|
| 71 | array( |
|---|
| 72 | 'name' => 'date', |
|---|
| 73 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 74 | 'index-type' => Cassandra::INDEX_KEYS, // create secondary index |
|---|
| 75 | 'index-name' => 'DateIdx' |
|---|
| 76 | ), |
|---|
| 77 | array( |
|---|
| 78 | 'name' => '00', |
|---|
| 79 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 80 | ), |
|---|
| 81 | array( |
|---|
| 82 | 'name' => '01', |
|---|
| 83 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 84 | ), |
|---|
| 85 | array( |
|---|
| 86 | 'name' => '02', |
|---|
| 87 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 88 | ), |
|---|
| 89 | array( |
|---|
| 90 | 'name' => '03', |
|---|
| 91 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 92 | ), |
|---|
| 93 | array( |
|---|
| 94 | 'name' => '04', |
|---|
| 95 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 96 | ), |
|---|
| 97 | array( |
|---|
| 98 | 'name' => '05', |
|---|
| 99 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 100 | ), |
|---|
| 101 | array( |
|---|
| 102 | 'name' => '06', |
|---|
| 103 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 104 | ), |
|---|
| 105 | array( |
|---|
| 106 | 'name' => '07', |
|---|
| 107 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 108 | ), |
|---|
| 109 | array( |
|---|
| 110 | 'name' => '08', |
|---|
| 111 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 112 | ), |
|---|
| 113 | array( |
|---|
| 114 | 'name' => '09', |
|---|
| 115 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 116 | ), |
|---|
| 117 | array( |
|---|
| 118 | 'name' => '10', |
|---|
| 119 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 120 | ), |
|---|
| 121 | array( |
|---|
| 122 | 'name' => '11', |
|---|
| 123 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 124 | ), |
|---|
| 125 | array( |
|---|
| 126 | 'name' => '12', |
|---|
| 127 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 128 | ), |
|---|
| 129 | array( |
|---|
| 130 | 'name' => '13', |
|---|
| 131 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 132 | ), |
|---|
| 133 | array( |
|---|
| 134 | 'name' => '14', |
|---|
| 135 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 136 | ), |
|---|
| 137 | array( |
|---|
| 138 | 'name' => '15', |
|---|
| 139 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 140 | ), |
|---|
| 141 | array( |
|---|
| 142 | 'name' => '16', |
|---|
| 143 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 144 | ), |
|---|
| 145 | array( |
|---|
| 146 | 'name' => '17', |
|---|
| 147 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 148 | ), |
|---|
| 149 | array( |
|---|
| 150 | 'name' => '18', |
|---|
| 151 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 152 | ), |
|---|
| 153 | array( |
|---|
| 154 | 'name' => '19', |
|---|
| 155 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 156 | ), |
|---|
| 157 | array( |
|---|
| 158 | 'name' => '20', |
|---|
| 159 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 160 | ), |
|---|
| 161 | array( |
|---|
| 162 | 'name' => '21', |
|---|
| 163 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 164 | ), |
|---|
| 165 | array( |
|---|
| 166 | 'name' => '22', |
|---|
| 167 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 168 | ), |
|---|
| 169 | array( |
|---|
| 170 | 'name' => '23', |
|---|
| 171 | 'type' => Cassandra::TYPE_INTEGER, |
|---|
| 172 | ) |
|---|
| 173 | ) |
|---|
| 174 | // actually accepts more parameters with reasonable defaults |
|---|
| 175 | ); |
|---|
| 176 | |
|---|
| 177 | $schema = $cassandra->getKeyspaceSchema($key_space); |
|---|
| 178 | echo 'Schema: <pre>'.print_r($schema, true).'</pre><hr/>'; |
|---|
| 179 | |
|---|
| 180 | function extend($hour_i){ |
|---|
| 181 | if ($hour_i < 11) return ("0".$hour_i); |
|---|
| 182 | else return $hour_i; |
|---|
| 183 | } |
|---|
| 184 | ?> |
|---|