Permalink
Browse files

Merge pull request #29 from kovalenko/master

Add UUID time based (version 1) support
  • Loading branch information...
2 parents d6d63a6 + 528ee18 commit 9b775f9282450535986fafb7c914f7a1d469c380 @sebgiroux committed Mar 2, 2013
@@ -12,6 +12,7 @@
use phpcassa\Connection\ConnectionPool;
use phpcassa\ColumnFamily;
use phpcassa\SuperColumnFamily;
+ use phpcassa\UUID;
use cassandra\IndexType;
$included_header = false;
@@ -527,11 +528,18 @@
$cf_def = ColumnFamilyHelper::getCFInKeyspace($keyspace_name,$columnfamily_name);
$is_super_cf = $cf_def->column_type == 'Super';
+ switch ($cf_def->comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ $autopack_names = false;
+ break;
+ default:
+ $autopack_names = true;
+ }
if ($is_super_cf) {
- $column_family = new SuperColumnFamily($pool, $columnfamily_name);
+ $column_family = new SuperColumnFamily($pool, $columnfamily_name, $autopack_names);
}
else {
- $column_family = new ColumnFamily($pool, $columnfamily_name);
+ $column_family = new ColumnFamily($pool, $columnfamily_name, $autopack_names);
}
$no_column = 1;
@@ -548,6 +556,12 @@
while (isset($_POST['column_name_'.$no_scf.'_'.$no_column]) && isset($_POST['column_value_'.$no_scf.'_'.$no_column])) {
$column_name = $_POST['column_name_'.$no_scf.'_'.$no_column];
+ switch ($cf_def->comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ $uuid = UUID::import($column_name);
+ $column_name = $uuid->bytes;
+ break;
+ }
$column_value = $_POST['column_value_'.$no_scf.'_'.$no_column];
if ($_POST['column_name_'.$no_scf.'_'.$no_column] != '' && $_POST['column_value_'.$no_scf.'_'.$no_column] != '') {
@@ -714,7 +728,7 @@
else {
$column_family = new ColumnFamily($pool, $columnfamily_name);
}
-
+
// Increment counter
if (isset($_GET['increment'])) {
$row_key = $_GET['row_key'];
@@ -793,6 +807,7 @@
$vw_row_vars['keyspace_name'] = $keyspace_name;
$vw_row_vars['columnfamily_name'] = $columnfamily_name;
+ $vw_row_vars['comparator_type'] = $cf_def->comparator_type;
$vw_row_vars['show_actions_link'] = true;
@@ -868,6 +883,7 @@
$is_super_cf = $cf_def->column_type == 'Super';
$vw_vars['is_super_cf'] = $cf_def->column_type == 'Super';
+ $vw_vars['comparator_type'] = $cf_def->comparator_type;
$vw_vars['key'] = $key;
$vw_vars['super_key'] = $super_key;
@@ -96,6 +96,25 @@ public static function displayCFRow($row_key,$keyspace_name,$columnfamily_name,$
return getHTML('columnfamily_row.php',$vw_vars);
}
}
+ public static function displayCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$row,$scf_key = null,$is_counter_column = false) {
+ $vw_vars['scf_key'] = $scf_key;
+ $uuid_row = array();
+ foreach ($row as $c=>&$v) {
+ $uuid_row[(string)unserialize($c)] = $v;
+ } unset($row, $v);
+ $vw_vars['row'] = $uuid_row;
+ $vw_vars['keyspace_name'] = $keyspace_name;
+ $vw_vars['columnfamily_name'] = $columnfamily_name;
+ $vw_vars['row_key'] = $row_key;
+
+ // If it's a column family of counter
+ if ($is_counter_column) {
+ return getHTML('columnfamily_row_counter.php',$vw_vars);
+ }
+ else {
+ return getHTML('columnfamily_row.php',$vw_vars);
+ }
+ }
/*
Display a row out of a super column family
@@ -115,6 +134,15 @@ public static function displaySCFRow($row_key,$keyspace_name,$columnfamily_name,
return $output;
}
+ public static function displaySCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$row,$is_counter_column = false) {
+ $output = '';
+
+ foreach ($row as $key => $value) {
+ $output .= ColumnFamilyHelper::displayCFTimeUUIDTypeRow($row_key,$keyspace_name,$columnfamily_name,$value,$key,$is_counter_column);
+ }
+
+ return $output;
+ }
/*
Used by usort() method. Assists in sorts column families by name
@@ -49,7 +49,7 @@
else:
?>
-<ul id="keyspaces" class="well">
+<ul id="keyspaces" class="well"><li>
<h3>Keyspaces and Column Families</h3>
<a href="keyspace_action.php?action=create" class="btn btn-large btn-primary" style="color: #fff; text-decoration: none;">Create New Keyspace</a>
@@ -60,42 +60,43 @@
<?php
$nb_ks = count($keyspaces_name);
for ($i = 0; $i < $nb_ks; $i++):
- if ($i/2 == intval($i/2) and $i == $nb_ks-1):
- $beg = '<tr>';
- $beg .= '<td colspan="2">';
+ $beg = $end = '';
+ if (!($i&1) and $i == $nb_ks-1):
+ $beg .= '</tr><tr><td colspan="2"><ul>';
- $end = '</td>';
- $end .= '</tr>';
- elseif ($i/2 == intval($i/2)):
- $beg = '<td>';
+ $end .= '</ul></td></tr>';
+ elseif (!($i&1)):
+ if ($i) $beg .= '</tr>';
+ $beg .= '<tr><td><ul>';
- $end = '</td>';
+ $end .= '</ul></td>';
else:
- $beg = '<td>';
+ $beg .= '<td><ul>';
- $end = '</td>';
- $end .= '</tr>';
+ $end .= '</ul></td>';
endif;
echo $beg;
$keyspace_name = $keyspaces_name[$i];
echo '<li><a href="describe_keyspace.php?keyspace_name='.$keyspace_name.'">'.$keyspace_name.'</a>';
- echo '<ul>';
- $nb_cf = count($keyspaces_details[$i]['columnfamilies_name']);
+ $nb_cf = count($keyspaces_details[$i]['columnfamilies_name']);
+ if ($nb_cf):
+ echo '<ul>';
for ($j = 0; $j < $nb_cf; $j++):
$columnfamily_name = $keyspaces_details[$i]['columnfamilies_name'][$j];
echo '<li><a href="describe_columnfamily.php?keyspace_name='.$keyspace_name.'&amp;columnfamily_name='.$columnfamily_name.'">'.$columnfamily_name.'</a></li>';
endfor;
- echo '</ul>';
+ echo '</ul>';
+ endif;
echo '</li>';
echo $end;
endfor;
?>
</table>
-</ul>
+</li></ul>
<?php
endif;
@@ -105,4 +106,4 @@
<ul>
<li><a href="jmx.php">See Stats</a></li>
-</ul>
+</ul>
@@ -2,11 +2,21 @@
<td><?php echo htmlentities($key,ENT_COMPAT,'UTF-8'); ?></td>
<td>
<?php
- if ($is_super_cf):
- echo ColumnFamilyHelper::displaySCFRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
- else:
- echo ColumnFamilyHelper::displayCFRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
- endif;
+ switch ($comparator_type) {
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType':
+ if ($is_super_cf):
+ echo ColumnFamilyHelper::displaySCFTimeUUIDTypeRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
+ else:
+ echo ColumnFamilyHelper::displayCFTimeUUIDTypeRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
+ endif;
+ break;
+ default:
+ if ($is_super_cf):
+ echo ColumnFamilyHelper::displaySCFRow($key,$keyspace_name,$columnfamily_name,$value,$is_counter_column);
+ else:
+ echo ColumnFamilyHelper::displayCFRow($key,$keyspace_name,$columnfamily_name,$value,null,$is_counter_column);
+ endif;
+ }
?>
</td>
<?php if ($show_actions_link): ?>
@@ -59,20 +59,37 @@ function addSuperColumnWithColumn() {
<?php endif; ?>
<?php
if ($mode == 'edit'):
- if ($is_super_cf):
- foreach ($output as $super_key => $data):
- echo 'addSuperColumn(', json_encode($super_key), ');';
-
- foreach ($data as $name => $value):
- echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
- endforeach;
- endforeach;
- else:
- echo 'num_super_columns++;';
- foreach ($output as $name => $value):
- echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
- endforeach;
- endif;
+ switch ($comparator_type):
+ case 'org.apache.cassandra.db.marshal.TimeUUIDType' :
+ if ($is_super_cf):
+ foreach ($output as $super_key => $data):
+ echo 'addSuperColumn(', json_encode($super_key), ');';
+ foreach ($data as $name => $value):
+ echo 'addColumn(', json_encode((string)unserialize($name)), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endforeach;
+ else:
+ echo 'num_super_columns++;';
+ foreach ($output as $name => $value):
+ echo 'addColumn(', json_encode((string)unserialize($name)), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endif;
+ break;
+ default:
+ if ($is_super_cf):
+ foreach ($output as $super_key => $data):
+ echo 'addSuperColumn(', json_encode($super_key), ');';
+ foreach ($data as $name => $value):
+ echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endforeach;
+ else:
+ echo 'num_super_columns++;';
+ foreach ($output as $name => $value):
+ echo 'addColumn(', json_encode($name), ',', json_encode($value), ',num_super_columns);';
+ endforeach;
+ endif;
+ endswitch;
endif;
?>
});
View
@@ -1,4 +1,3 @@
- <div id="footer">Copyright &copy; All Rights Reserved - Sébastien Giroux - 2011</div>
- </div>
+ <div id="footer">Copyright &copy; All Rights Reserved - Sébastien Giroux - 2011</div>
</body>
</html>

0 comments on commit 9b775f9

Please sign in to comment.