// open connection $socket = new TSocket(HBASE_HOST, HBASE_PORT); $transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($transport); $transport->open(); // create hbase client $client = new HbaseClient($protocol); // show all tables echo "Existing tables:\n"; $tables = $client->getTableNames(); foreach ($tables as $name) { echo " found: {$name}\n"; } // create a table with name 'tableName' echo "\nCreate table: tableName\n"; try { $columns = array(new ColumnDescriptor(array('name' => 'colFamily:', 'maxVersions' => 10))); $client->createTable("tableName", $columns); } catch (AlreadyExists $ae) { echo "WARN: {$ae->message}\n"; } // insert data to table echo "\nInsert data to table: tableName\n"; $mutations = array(new Mutation(array('column' => 'colFamily:Col', 'value' => 'value123'))); $client->mutateRow("tableName", "ID_1237846634624", $mutations); // get table data echo "\nData in table: tableName\n"; $rows = $client->getRow("tableName", "ID_1237846634624"); foreach ($rows as $row) { var_dump($row); }
echo "WARN: {$ae->message}\n"; } echo "column families in {$t}:\n"; $descriptors = $client->getColumnDescriptors($t); asort($descriptors); foreach ($descriptors as $col) { echo " column: {$col->name}, maxVer: {$col->maxVersions}\n"; } # # Test UTF-8 handling # $invalid = "foo-������"; $valid = "foo-生ビール"; # non-utf8 is fine for data $mutations = array(new Mutation(array('column' => 'entry:foo', 'value' => $invalid))); $client->mutateRow($t, "foo", $mutations); # try empty strings $mutations = array(new Mutation(array('column' => 'entry:', 'value' => ""))); $client->mutateRow($t, "", $mutations); # this row name is valid utf8 $mutations = array(new Mutation(array('column' => 'entry:foo', 'value' => $valid))); $client->mutateRow($t, $valid, $mutations); # non-utf8 is not allowed in row names try { $mutations = array(new Mutation(array('column' => 'entry:foo', 'value' => $invalid))); $client->mutateRow($t, $invalid, $mutations); throw new Exception("shouldn't get here!"); } catch (IOError $e) { echo "expected error: {$e->message}\n"; } # Run a scanner on the rows we just created