Skip to content

Commit

Permalink
fix cli list + "assume CF keys as uuid."
Browse files Browse the repository at this point in the history
patch by jbellis

git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.7@1035418 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed Nov 15, 2010
1 parent f203537 commit 8ef5d50
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 59 deletions.
150 changes: 98 additions & 52 deletions conf/cassandra.yaml
Expand Up @@ -272,7 +272,7 @@ index_interval: 128
# unusual circumstances you will have one Keyspace per application.
#
# Keyspace required parameters:
# - name: name of the keyspace; "system" is
# - name: name of the keyspace; "system" and "definitions" are
# reserved for Cassandra Internals.
# - replica_placement_strategy: the class that determines how replicas
# are distributed among nodes. Contains both the class as well as
Expand Down Expand Up @@ -363,55 +363,101 @@ index_interval: 128
# before the memtable is flushed. If undefined, throughput / 64 * 0.3
# will be used.
#
# NOTE: this keyspace definition is for demonstration purposes only.
# Cassandra will not load these definitions during startup. See
# http://wiki.apache.org/cassandra/FAQ#no_keyspaces for an explanation.
keyspaces:
- name: Keyspace1
replica_placement_strategy: org.apache.cassandra.locator.SimpleStrategy
replication_factor: 1
column_families:
- name: Standard1
compare_with: BytesType
keys_cached: 10000
rows_cached: 1000
row_cache_save_period_in_seconds: 0
key_cache_save_period_in_seconds: 3600
memtable_flush_after_mins: 59
memtable_throughput_in_mb: 255
memtable_operations_in_millions: 0.29

- name: Standard2
compare_with: UTF8Type
read_repair_chance: 0.1
keys_cached: 100
gc_grace_seconds: 0
min_compaction_threshold: 5
max_compaction_threshold: 31

- name: StandardByUUID1
compare_with: TimeUUIDType

- name: Super1
column_type: Super
compare_with: BytesType
compare_subcolumns_with: BytesType

- name: Super2
column_type: Super
compare_subcolumns_with: UTF8Type
rows_cached: 10000
keys_cached: 50
comment: 'A column family with supercolumns, whose column and subcolumn names are UTF8 strings'

- name: Super3
column_type: Super
compare_with: LongType
comment: 'A column family with supercolumns, whose column names are Longs (8 bytes)'

- name: Indexed1
default_validation_class: LongType
column_metadata:
- name: birthdate
validator_class: LongType
index_type: KEYS
- column_families:
- column_metadata:
- !!org.apache.cassandra.config.RawColumnDefinition
name: password
validator_class: org.apache.cassandra.db.marshal.UTF8Type
column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.UTF8Type
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: User
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
- column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.LongType
default_validation_class: org.apache.cassandra.db.marshal.LexicalUUIDType
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: Userline
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
- column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.UTF8Type
default_validation_class: org.apache.cassandra.db.marshal.UTF8Type
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: Followers
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
- column_metadata:
- !!org.apache.cassandra.config.RawColumnDefinition
name: body
validator_class: org.apache.cassandra.db.marshal.UTF8Type
- !!org.apache.cassandra.config.RawColumnDefinition
name: username
validator_class: org.apache.cassandra.db.marshal.UTF8Type
column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.UTF8Type
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: Tweet
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
- column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.UTF8Type
default_validation_class: org.apache.cassandra.db.marshal.UTF8Type
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: Friends
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
- column_type: Standard
comment: ''
compare_with: org.apache.cassandra.db.marshal.LongType
default_validation_class: org.apache.cassandra.db.marshal.LexicalUUIDType
gc_grace_seconds: 864000
key_cache_save_period_in_seconds: 3600
keys_cached: 200000.0
max_compaction_threshold: 32
memtable_flush_after_mins: 60
min_compaction_threshold: 4
name: Timeline
read_repair_chance: 1.0
row_cache_save_period_in_seconds: 0
rows_cached: 0.0
name: Twissjava
replica_placement_strategy: org.apache.cassandra.locator.SimpleStrategy
replication_factor: 1
19 changes: 13 additions & 6 deletions src/java/org/apache/cassandra/cli/CliClient.java
Expand Up @@ -904,8 +904,8 @@ private void executeList(Tree statement)
// extract column family
String columnFamily = statement.getChild(0).getText();

String startKey = "";
String endKey = "";
String rawStartKey = "";
String rawEndKey = "";
int limitCount = Integer.MAX_VALUE; // will reset to default later if it's not specified

// optional arguments: key range and limit
Expand All @@ -916,9 +916,9 @@ private void executeList(Tree statement)
{
if (child.getChildCount() > 0)
{
startKey = CliUtils.unescapeSQLString(child.getChild(0).getText());
rawStartKey = CliUtils.unescapeSQLString(child.getChild(0).getText());
if (child.getChildCount() > 1)
endKey = CliUtils.unescapeSQLString(child.getChild(1).getText());
rawEndKey = CliUtils.unescapeSQLString(child.getChild(1).getText());
}
}
else
Expand Down Expand Up @@ -955,8 +955,9 @@ private void executeList(Tree statement)
// set the key range
KeyRange range = new KeyRange(limitCount);
AbstractType keyComparator = this.cfKeysComparators.get(columnFamily);
range.setStart_key(getBytesAccordingToType(startKey, keyComparator))
.setEnd_key(getBytesAccordingToType(endKey, keyComparator));
ByteBuffer startKey = rawStartKey.isEmpty() ? FBUtilities.EMPTY_BYTE_BUFFER : getBytesAccordingToType(rawStartKey, keyComparator);
ByteBuffer endKey = rawEndKey.isEmpty() ? FBUtilities.EMPTY_BYTE_BUFFER : getBytesAccordingToType(rawEndKey, keyComparator);
range.setStart_key(startKey).setEnd_key(endKey);

ColumnParent columnParent = new ColumnParent(columnFamily);
List<KeySlice> keySlices = thriftClient.get_range_slices(columnParent, predicate, range, ConsistencyLevel.ONE);
Expand Down Expand Up @@ -1424,6 +1425,12 @@ private IndexType getIndexTypeFromString(String indexTypeAsString)
*/
private ByteBuffer getBytesAccordingToType(String object, AbstractType comparator)
{
// TODO there is tension here between using this function to generate default values,
// and using it to parse input. For instance, normally we want to convert empty string
// to empty byte array for any type -- all types special case empty byte[] to mean
// "minimum value" -- but we also want timeuuid() to create a valid uuid for us.
// For now, this function takes the create-valid-values approach, and we leave
// other use cases to special case "" -> byte[0] before calling this.
if (comparator instanceof LongType)
{
long longType;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org/apache/cassandra/cli/CliTest.java
Expand Up @@ -125,7 +125,7 @@ public void testCli() throws IOException, TTransportException, ConfigurationExce
CliMain.processStatement(statement);
String result = outStream.toString();
// System.out.println("Result:\n" + result);
assertEquals("", errStream.toString());
assertEquals(errStream.toString() + " processing " + statement, "", errStream.toString());
if (statement.startsWith("drop ") || statement.startsWith("create ") || statement.startsWith("update "))
{
assertTrue(result.matches("(.{8})-(.{4})-(.{4})-(.{4})-(.{12})\n"));
Expand Down

0 comments on commit 8ef5d50

Please sign in to comment.