Exemplo n.º 1
0
 /**
  * Gets an iterator over a range of rows.
  *
  * @param string $keyStart fetch rows with a key >= this
  * @param string $keyFinish fetch rows with a key <= this
  * @param int $rowCount limit the number of rows returned to this amount
  * @param mixed[] $columns limit the columns or super columns fetched to this list
  * @param mixed $columnStart only fetch columns with name >= this
  * @param mixed $columnFinish only fetch columns with name <= this
  * @param bool $columnReversed fetch the columns in reverse order
  * @param int $columnCount limit the number of columns returned to this amount
  * @param mixed $superColumn return only columns in this super column
  * @param cassandra_ConsistencyLevel $readConsistencyLevel affects the guaranteed
  *        number of nodes that must respond before the operation returns
  * @param int $bufferSize When calling `get_range`, the intermediate results need
  *        to be buffered if we are fetching many rows, otherwise the Cassandra
  *        server will overallocate memory and fail.  This is the size of
  *        that buffer in number of rows.
  *
  * @return RangeColumnFamilyIterator
  */
 public function getRange($keyStart = "", $keyFinish = "", $rowCount = ColumnFamily::DEFAULT_ROW_COUNT, $columns = null, $columnStart = "", $columnFinish = "", $columnReversed = false, $columnCount = ColumnFamily::DEFAULT_COLUMN_COUNT, $superColumn = null, $readConsistencyLevel = null, $bufferSize = null)
 {
     if (empty($this->_columnFamily)) {
         $this->init();
     }
     return $this->_columnFamily->get_range($keyStart, $keyFinish, $rowCount, $columns, $columnStart, $columnFinish, $columnReversed, $columnCount, $superColumn, $readConsistencyLevel, $bufferSize);
 }
Exemplo n.º 2
0
 function findUser($user, $loggedinuser, $connection)
 {
     //        $sql = "select username, firstname, lastname, imagethumburl  from PERSON where username like '$user%'";
     //        $result = $connection->query($sql);
     $column_family = new ColumnFamily($connection, 'PERSON');
     $result = $column_family->get_range($key_start = $user, $key_finish = "", $column_count = 5);
     $rowsFound = false;
     $count = 0;
     ob_start();
     foreach ($result as $key => $row) {
         $rowsFound = true;
         if ($count % 2 == 0) {
             $class = "even";
         } else {
             $class = "odd";
         }
         $username = $row['username'];
         $userInFriendsList = $this->userInFriendsList($loggedinuser, $username, $connection);
         $invited = $this->ifInvited($loggedinuser, $username, $connection);
         $firstname = $row['firstname'];
         $lastname = $row['lastname'];
         $image = $row['imagethumburl'];
         require "../views/findUsersList.php";
         $count++;
     }
     unset($result);
     $users = ob_get_contents();
     ob_end_clean();
     if ($rowsFound == true) {
         return $users;
     } else {
         return '<em class="subliminal">No users match your query.</em>';
     }
 }
Exemplo n.º 3
0
 function getHomePageTagCloud($connection)
 {
     //        $cloudquery = "(SELECT st.tag as tag,st.refcount as count from SOCIALEVENTTAG as st where st.refcount>100 limit 50)  order by tag ASC";
     //      $cloudquery = "(SELECT st.tag as tag,st.refcount as count from SOCIALEVENTTAG as st order by st.refcount desc limit 50) order by tag asc";
     //       $cloudresult =$connection->query($cloudquery);
     $cloudquery = new ColumnFamily($connection, 'SOCIALEVENTTAG');
     $cloudresult = $cloudquery->get_range($key_start = "1", $key_finish = "50");
     $rowsFound = false;
     foreach ($cloudresult as $key1 => $row) {
         $rowsFound = true;
         $tags[$row['tag']] = $row['refcount'];
     }
     unset($cloudresult);
     if ($rowsFound) {
         // change these font sizes if you will
         $max_size = 250;
         // max font size in %
         $min_size = 100;
         // min font size in %
         // get the largest and smallest array values
         $max_count = max(array_values($tags));
         $min_count = min(array_values($tags));
         // find the range of values
         $spread = $max_count - $min_count;
         if (0 == $spread) {
             // we don't want to divide by zero
             $spread = 1;
         }
         // determine the font-size increment
         // this is the increase per tag count (times used)
         $step = ($max_size - $min_size) / $spread;
         // loop through our tag array
         foreach ($tags as $key => $value) {
             $size = $min_size + ($value - $min_count) * $step;
             // uncomment if you want sizes in whole %:
             $size = ceil($size);
             $homePageTagCloud = $homePageTagCloud . " " . '<a href="taggedEvents.php?tag=' . $key . '&count=' . $value . '" style="font-size:' . $size . '%" title="' . $value . ' events tagged with ' . $key . '" >' . $key . '</a> ';
         }
     }
     return $homePageTagCloud;
 }
     $nb_rows = $_GET['nb_rows'];
 }
 $vw_vars['nb_rows'] = $nb_rows;
 $describe_keyspace = $sys_manager->describe_keyspace($keyspace_name);
 $cf_def = null;
 foreach ($describe_keyspace->cf_defs as $cfdef) {
     if ($cfdef->name == $columnfamily_name) {
         $cf_def = $cfdef;
         break;
     }
 }
 $vw_row_vars['is_super_cf'] = $cf_def->column_type == 'Super';
 $vw_row_vars['is_counter_column'] = $column_family->cfdef->default_validation_class == 'org.apache.cassandra.db.marshal.CounterColumnType';
 $included_header = true;
 echo getHTML('header.php');
 $result = $column_family->get_range($offset_key, '', $nb_rows);
 $vw_vars['results'] = '';
 $nb_results = 0;
 foreach ($result as $key => $value) {
     $vw_row_vars['key'] = $key;
     $vw_row_vars['value'] = $value;
     $vw_row_vars['keyspace_name'] = $keyspace_name;
     $vw_row_vars['columnfamily_name'] = $columnfamily_name;
     $vw_row_vars['show_actions_link'] = true;
     $vw_vars['results'] .= getHTML('columnfamily_browse_data_row.php', $vw_row_vars);
     $nb_results++;
 }
 $vw_vars['show_begin_page_link'] = $offset_key != '';
 $vw_vars['show_prev_page_link'] = $offset_key != '' && count($_SESSION['browse_data_offset_key']) > 0;
 // We got the number of rows we asked for, display "Next Page" link
 if ($nb_results == $nb_rows) {
Exemplo n.º 5
0
 public function test_insert_get_range()
 {
     $cl = cassandra_ConsistencyLevel::ONE;
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 10);
     $keys = array();
     $columns = array('c' => 'v');
     foreach (range(100, 200) as $i) {
         $keys[] = 'key' . $i;
         $cf->insert('key' . $i, $columns);
     }
     # Keys at the end that we don't want
     foreach (range(201, 300) as $i) {
         $cf->insert('key' . $i, $columns);
     }
     # Buffer size = 10; rowcount is divisible by buffer size
     $count = 0;
     foreach ($cf->get_range() as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 100);
     # Buffer size larger than row count
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 1000);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 100) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 100);
     # Buffer size larger than row count, less than total number of rows
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 150);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 100) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 100);
     # Odd number for batch size
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 7);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 100) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 100);
     # Smallest buffer size available
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 2);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 100) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 100);
     # Put the remaining keys in our list
     foreach (range(201, 300) as $i) {
         $keys[] = 'key' . $i;
     }
     # Row count above total number of rows
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 2);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 10000) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 201);
     # Row count above total number of rows
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 7);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 10000) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 201);
     # Row count above total number of rows, buffer_size = total number of rows
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 200);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 10000) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 201);
     # Row count above total number of rows, buffer_size = total number of rows
     $cf = new ColumnFamily($this->client, 'Standard1', true, true, $read_consistency_level = $cl, $write_consistency_level = $cl, $buffer_size = 10000);
     $count = 0;
     foreach ($cf->get_range($key_start = '', $key_finish = '', $row_count = 10000) as $key => $cols) {
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
         $count++;
     }
     self::assertEqual($count, 201);
     $cf->truncate();
 }
Exemplo n.º 6
0
    // Ensure our user name comes in first, if already attending.
    $sql = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
    $index_exp_event = CassandraUtil::create_index_expression('socialeventid', $se);
    $index_exp_uname = CassandraUtil::create_index_expression('username', $username);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp_event, $index_exp_uname));
    $rows = $sql->get_indexed_slices($index_clause, $columns = array('socialeventid'));
    foreach ($rows as $key => $columns) {
        $index_exp_p = CassandraUtil::create_index_expression('socialeventid', $columns['socialeventid']);
        $index_clause_p = CassandraUtil::create_index_clause(array($index_exp_p));
        $listqueryresult = $sql->get_range($index_clause_p, $row_count = 20, $column_count = 20);
    }
} else {
    $listquery = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
    $index_exp_event = CassandraUtil::create_index_expression('socialeventid', $se);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp_event));
    $listqueryresult = $listquery->get_range($index_clause, $row_count = 20, $column_count = 20);
}
foreach ($listqueryresult as $key => $column) {
    $tmp_uname = $column['username'];
    if (!isset($_SESSION["uname"]) && $tmp_uname == $username) {
        $unattend = true;
        // show unattend button if user is already registered.
    }
    $attendeeList = $attendeeList . " " . '<a href="users.php?username='******'">' . $tmp_uname . '</a><br />';
}
unset($listqueryresult);
if (isset($_POST['commentsratingsubmit'])) {
    $insertSql = new ColumnFamily($conn, 'COMMENTS_RATING');
    $commentid = exec("python /usr/pysnowflakeclient/pysnowflakeclient/__init__.py");
    $insertSql->insert($commentid, array('commentid' => $commentid, 'username' => $username, 'socialeventid' => $se, 'comments' => $comments, 'ratings' => $rating, 'created_at' => time()));
} else {
$date_start = strtotime($_GET["date_start"]);
$date_stop = strtotime($_GET["date_stop"]);
$date_step = $_GET["date_step"];
$metric = $_GET["metric"];
$dates = get_date_span($date_start, $date_stop, $date_step);
$dates = array_reverse($dates);
$current = get_current($date_step);
try {
  $sys = new ColumnFamily(cassandra_connect("fo"), "systems");
  $agg = new ColumnFamily(cassandra_connect("metrics"), "agg");
  $sys->read_consistency_level = cassandra_ConsistencyLevel::ONE;
  $agg->read_consistency_level = cassandra_ConsistencyLevel::ONE;
  if($_GET["load"] == "all") {
    $systems = array();
    $r = $sys->get_range("", "", $row_count=200, $columns=array("status"));
    foreach($r as $system => $info) $systems[] = $system;
  } else {
    $systems = explode(",", $_GET["load"]);
  }
  $keys = array();
  $totals = array();
  foreach($systems as $system) {
    $totals[$system] = array();
    $keys["$system-$metric-$date_step"] = $system;
  }
  $result = $agg->multiget(array_keys($keys), $dates);
  foreach($result as $key => $xfer) {
    $system = $keys[$key];
    foreach($dates as $date) {
      $totals[$system][$date] = array_key_exists($date, $xfer) ? $xfer[$date] : "";