protected function _alter_column($keyspace, $column_family, $column, $data_type = self::KEEP, $index_type = self::KEEP, $index_name = self::KEEP) { $this->client->set_keyspace($keyspace); $cfdef = $this->get_cfdef($keyspace, $column_family); if ($cfdef->column_type == 'Super') { $col_name_type = DataType::get_type_for($cfdef->subcomparator_type); } else { $col_name_type = DataType::get_type_for($cfdef->comparator_type); } $packed_name = $col_name_type->pack($column); $col_def = null; $col_meta = $cfdef->column_metadata; for ($i = 0; $i < count($col_meta); $i++) { $temp_col_def = $col_meta[$i]; if ($temp_col_def->name === $packed_name) { $col_def = $temp_col_def; unset($col_meta[$i]); break; } } if ($col_def === null) { $col_def = new ColumnDef(); $col_def->name = $packed_name; } if ($data_type !== self::KEEP) { $col_def->validation_class = self::qualify_class_name($data_type); } if ($index_type !== self::KEEP) { $col_def->index_type = $index_type; } if ($index_name !== self::KEEP) { $col_def->index_name = $index_name; } $col_meta[] = $col_def; $cfdef->column_metadata = $col_meta; $this->client->system_update_column_family($cfdef); $this->wait_for_agreement(); }
/** * @param bool $pack_keys whether or not keys are automatically packed/unpacked * * Available since Cassandra 0.8.0. */ public function set_autopack_keys($pack_keys) { if ($pack_keys) { $this->autopack_keys = true; if (property_exists('\\cassandra\\CfDef', "key_validation_class")) { $this->key_type = DataType::get_type_for($this->cfdef->key_validation_class); } else { $this->key_type = new BytesType(); } } else { $this->autopack_keys = false; } }
$paren_index = strpos($typestr, '('); $end = strlen($typestr) - $paren_index; return substr($typestr, $paren_index + 1, $end - 2); } protected static function get_inner_types($typestr) { $inner = self::get_inner_type($typestr); $inner_typestrs = explode(',', $inner); $inner_types = array(); foreach ($inner_typestrs as $inner_type) { $inner_types[] = self::get_type_for(trim($inner_type)); } return $inner_types; } public static function get_type_for($typestr) { if (strpos($typestr, 'CompositeType') !== false) { return new CompositeType(self::get_inner_types($typestr)); } else { if (strpos($typestr, 'ReversedType') !== false) { return self::get_type_for(self::get_inner_type($typestr)); } else { $type_name = self::extract_type_name($typestr); $type_class = self::$class_map[$type_name]; return new $type_class(); } } } } DataType::init();