Author: jbellis
Date: Thu Aug 12 18:29:46 2010
New Revision: 984901
URL: http://svn.apache.org/viewvc?rev=984901&view=rev
Log:
describe_keyspace includes CfDef information. patch by Jon Hermes; reviewed by
jbellis for CASSANDRA-1363
Modified:
cassandra/trunk/interface/cassandra.thrift
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java
cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
cassandra/trunk/test/system/test_thrift_server.py
cassandra/trunk/test/unit/org/apache/cassandra/hadoop/ColumnFamilyOutputFormatTest.java
Modified: cassandra/trunk/interface/cassandra.thrift
URL:
http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.thrift?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.thrift (original)
+++ cassandra/trunk/interface/cassandra.thrift Thu Aug 12 18:29:46 2010
@@ -46,7 +46,7 @@ namespace rb CassandraThrift
# for every edit that doesn't result in a change to major/minor.
#
# See the Semantic Versioning Specification (SemVer) http://semver.org.
-const string VERSION = "10.0.0"
+const string VERSION = "11.0.0"
#
@@ -501,7 +501,7 @@ service Cassandra {
throws (1: InvalidRequestException ire),
/** list the defined keyspaces in this cluster */
- set<string> describe_keyspaces(),
+ list<KsDef> describe_keyspaces(),
/** get the cluster name */
string describe_cluster_name(),
@@ -524,8 +524,8 @@ service Cassandra {
string describe_partitioner(),
/** describe specified keyspace */
- map<string, map<string, string>> describe_keyspace(1:required string
keyspace)
- throws (1:NotFoundException nfe),
+ KsDef describe_keyspace(1:required string keyspace)
+ throws (1:NotFoundException nfe),
/** experimental API for hadoop/parallel query support.
may change violently and without warning.
Modified:
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
---
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
(original)
+++
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
Thu Aug 12 18:29:46 2010
@@ -182,7 +182,7 @@ public class Cassandra {
/**
* list the defined keyspaces in this cluster
*/
- public Set<String> describe_keyspaces() throws TException;
+ public List<KsDef> describe_keyspaces() throws TException;
/**
* get the cluster name
@@ -218,7 +218,7 @@ public class Cassandra {
*
* @param keyspace
*/
- public Map<String,Map<String,String>> describe_keyspace(String keyspace)
throws NotFoundException, TException;
+ public KsDef describe_keyspace(String keyspace) throws NotFoundException,
TException;
/**
* experimental API for hadoop/parallel query support.
@@ -1003,7 +1003,7 @@ public class Cassandra {
throw new TApplicationException(TApplicationException.MISSING_RESULT,
"check_schema_agreement failed: unknown result");
}
- public Set<String> describe_keyspaces() throws TException
+ public List<KsDef> describe_keyspaces() throws TException
{
send_describe_keyspaces();
return recv_describe_keyspaces();
@@ -1018,7 +1018,7 @@ public class Cassandra {
oprot_.getTransport().flush();
}
- public Set<String> recv_describe_keyspaces() throws TException
+ public List<KsDef> recv_describe_keyspaces() throws TException
{
TMessage msg = iprot_.readMessageBegin();
if (msg.type == TMessageType.EXCEPTION) {
@@ -1182,7 +1182,7 @@ public class Cassandra {
throw new TApplicationException(TApplicationException.MISSING_RESULT,
"describe_partitioner failed: unknown result");
}
- public Map<String,Map<String,String>> describe_keyspace(String keyspace)
throws NotFoundException, TException
+ public KsDef describe_keyspace(String keyspace) throws NotFoundException,
TException
{
send_describe_keyspace(keyspace);
return recv_describe_keyspace();
@@ -1198,7 +1198,7 @@ public class Cassandra {
oprot_.getTransport().flush();
}
- public Map<String,Map<String,String>> recv_describe_keyspace() throws
NotFoundException, TException
+ public KsDef recv_describe_keyspace() throws NotFoundException, TException
{
TMessage msg = iprot_.readMessageBegin();
if (msg.type == TMessageType.EXCEPTION) {
@@ -2048,7 +2048,7 @@ public class Cassandra {
prot.writeMessageEnd();
}
- public Set<String> getResult() throws TException {
+ public List<KsDef> getResult() throws TException {
if (getState() != State.RESPONSE_READ) {
throw new IllegalStateException("Method call not finished!");
}
@@ -2194,7 +2194,7 @@ public class Cassandra {
prot.writeMessageEnd();
}
- public Map<String,Map<String,String>> getResult() throws
NotFoundException, TException {
+ public KsDef getResult() throws NotFoundException, TException {
if (getState() != State.RESPONSE_READ) {
throw new IllegalStateException("Method call not finished!");
}
@@ -17618,9 +17618,9 @@ public class Cassandra {
public static class describe_keyspaces_result implements
TBase<describe_keyspaces_result, describe_keyspaces_result._Fields>,
java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new
TStruct("describe_keyspaces_result");
- private static final TField SUCCESS_FIELD_DESC = new TField("success",
TType.SET, (short)0);
+ private static final TField SUCCESS_FIELD_DESC = new TField("success",
TType.LIST, (short)0);
- public Set<String> success;
+ public List<KsDef> success;
/** The set of fields this struct contains, along with convenience methods
for finding and manipulating them. */
public enum _Fields implements TFieldIdEnum {
@@ -17686,8 +17686,8 @@ public class Cassandra {
static {
Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields,
FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success",
TFieldRequirementType.DEFAULT,
- new SetMetaData(TType.SET,
- new FieldValueMetaData(TType.STRING))));
+ new ListMetaData(TType.LIST,
+ new StructMetaData(TType.STRUCT, KsDef.class))));
metaDataMap = Collections.unmodifiableMap(tmpMap);
FieldMetaData.addStructMetaDataMap(describe_keyspaces_result.class,
metaDataMap);
}
@@ -17696,7 +17696,7 @@ public class Cassandra {
}
public describe_keyspaces_result(
- Set<String> success)
+ List<KsDef> success)
{
this();
this.success = success;
@@ -17707,9 +17707,9 @@ public class Cassandra {
*/
public describe_keyspaces_result(describe_keyspaces_result other) {
if (other.isSetSuccess()) {
- Set<String> __this__success = new HashSet<String>();
- for (String other_element : other.success) {
- __this__success.add(other_element);
+ List<KsDef> __this__success = new ArrayList<KsDef>();
+ for (KsDef other_element : other.success) {
+ __this__success.add(new KsDef(other_element));
}
this.success = __this__success;
}
@@ -17728,22 +17728,22 @@ public class Cassandra {
return (this.success == null) ? 0 : this.success.size();
}
- public java.util.Iterator<String> getSuccessIterator() {
+ public java.util.Iterator<KsDef> getSuccessIterator() {
return (this.success == null) ? null : this.success.iterator();
}
- public void addToSuccess(String elem) {
+ public void addToSuccess(KsDef elem) {
if (this.success == null) {
- this.success = new HashSet<String>();
+ this.success = new ArrayList<KsDef>();
}
this.success.add(elem);
}
- public Set<String> getSuccess() {
+ public List<KsDef> getSuccess() {
return this.success;
}
- public describe_keyspaces_result setSuccess(Set<String> success) {
+ public describe_keyspaces_result setSuccess(List<KsDef> success) {
this.success = success;
return this;
}
@@ -17769,7 +17769,7 @@ public class Cassandra {
if (value == null) {
unsetSuccess();
} else {
- setSuccess((Set<String>)value);
+ setSuccess((List<KsDef>)value);
}
break;
@@ -17867,17 +17867,18 @@ public class Cassandra {
}
switch (field.id) {
case 0: // SUCCESS
- if (field.type == TType.SET) {
+ if (field.type == TType.LIST) {
{
- TSet _set95 = iprot.readSetBegin();
- this.success = new HashSet<String>(2*_set95.size);
- for (int _i96 = 0; _i96 < _set95.size; ++_i96)
+ TList _list95 = iprot.readListBegin();
+ this.success = new ArrayList<KsDef>(_list95.size);
+ for (int _i96 = 0; _i96 < _list95.size; ++_i96)
{
- String _elem97;
- _elem97 = iprot.readString();
+ KsDef _elem97;
+ _elem97 = new KsDef();
+ _elem97.read(iprot);
this.success.add(_elem97);
}
- iprot.readSetEnd();
+ iprot.readListEnd();
}
} else {
TProtocolUtil.skip(iprot, field.type);
@@ -17900,12 +17901,12 @@ public class Cassandra {
if (this.isSetSuccess()) {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
{
- oprot.writeSetBegin(new TSet(TType.STRING, this.success.size()));
- for (String _iter98 : this.success)
+ oprot.writeListBegin(new TList(TType.STRUCT, this.success.size()));
+ for (KsDef _iter98 : this.success)
{
- oprot.writeString(_iter98);
+ _iter98.write(oprot);
}
- oprot.writeSetEnd();
+ oprot.writeListEnd();
}
oprot.writeFieldEnd();
}
@@ -20342,10 +20343,10 @@ public class Cassandra {
public static class describe_keyspace_result implements
TBase<describe_keyspace_result, describe_keyspace_result._Fields>,
java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new
TStruct("describe_keyspace_result");
- private static final TField SUCCESS_FIELD_DESC = new TField("success",
TType.MAP, (short)0);
+ private static final TField SUCCESS_FIELD_DESC = new TField("success",
TType.STRUCT, (short)0);
private static final TField NFE_FIELD_DESC = new TField("nfe",
TType.STRUCT, (short)1);
- public Map<String,Map<String,String>> success;
+ public KsDef success;
public NotFoundException nfe;
/** The set of fields this struct contains, along with convenience methods
for finding and manipulating them. */
@@ -20415,11 +20416,7 @@ public class Cassandra {
static {
Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields,
FieldMetaData>(_Fields.class);
tmpMap.put(_Fields.SUCCESS, new FieldMetaData("success",
TFieldRequirementType.DEFAULT,
- new MapMetaData(TType.MAP,
- new FieldValueMetaData(TType.STRING),
- new MapMetaData(TType.MAP,
- new FieldValueMetaData(TType.STRING),
- new FieldValueMetaData(TType.STRING)))));
+ new StructMetaData(TType.STRUCT, KsDef.class)));
tmpMap.put(_Fields.NFE, new FieldMetaData("nfe",
TFieldRequirementType.DEFAULT,
new FieldValueMetaData(TType.STRUCT)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
@@ -20430,7 +20427,7 @@ public class Cassandra {
}
public describe_keyspace_result(
- Map<String,Map<String,String>> success,
+ KsDef success,
NotFoundException nfe)
{
this();
@@ -20443,30 +20440,7 @@ public class Cassandra {
*/
public describe_keyspace_result(describe_keyspace_result other) {
if (other.isSetSuccess()) {
- Map<String,Map<String,String>> __this__success = new
HashMap<String,Map<String,String>>();
- for (Map.Entry<String, Map<String,String>> other_element :
other.success.entrySet()) {
-
- String other_element_key = other_element.getKey();
- Map<String,String> other_element_value = other_element.getValue();
-
- String __this__success_copy_key = other_element_key;
-
- Map<String,String> __this__success_copy_value = new
HashMap<String,String>();
- for (Map.Entry<String, String> other_element_value_element :
other_element_value.entrySet()) {
-
- String other_element_value_element_key =
other_element_value_element.getKey();
- String other_element_value_element_value =
other_element_value_element.getValue();
-
- String __this__success_copy_value_copy_key =
other_element_value_element_key;
-
- String __this__success_copy_value_copy_value =
other_element_value_element_value;
-
-
__this__success_copy_value.put(__this__success_copy_value_copy_key,
__this__success_copy_value_copy_value);
- }
-
- __this__success.put(__this__success_copy_key,
__this__success_copy_value);
- }
- this.success = __this__success;
+ this.success = new KsDef(other.success);
}
if (other.isSetNfe()) {
this.nfe = new NotFoundException(other.nfe);
@@ -20482,22 +20456,11 @@ public class Cassandra {
return new describe_keyspace_result(this);
}
- public int getSuccessSize() {
- return (this.success == null) ? 0 : this.success.size();
- }
-
- public void putToSuccess(String key, Map<String,String> val) {
- if (this.success == null) {
- this.success = new HashMap<String,Map<String,String>>();
- }
- this.success.put(key, val);
- }
-
- public Map<String,Map<String,String>> getSuccess() {
+ public KsDef getSuccess() {
return this.success;
}
- public describe_keyspace_result setSuccess(Map<String,Map<String,String>>
success) {
+ public describe_keyspace_result setSuccess(KsDef success) {
this.success = success;
return this;
}
@@ -20547,7 +20510,7 @@ public class Cassandra {
if (value == null) {
unsetSuccess();
} else {
- setSuccess((Map<String,Map<String,String>>)value);
+ setSuccess((KsDef)value);
}
break;
@@ -20676,32 +20639,9 @@ public class Cassandra {
}
switch (field.id) {
case 0: // SUCCESS
- if (field.type == TType.MAP) {
- {
- TMap _map103 = iprot.readMapBegin();
- this.success = new
HashMap<String,Map<String,String>>(2*_map103.size);
- for (int _i104 = 0; _i104 < _map103.size; ++_i104)
- {
- String _key105;
- Map<String,String> _val106;
- _key105 = iprot.readString();
- {
- TMap _map107 = iprot.readMapBegin();
- _val106 = new HashMap<String,String>(2*_map107.size);
- for (int _i108 = 0; _i108 < _map107.size; ++_i108)
- {
- String _key109;
- String _val110;
- _key109 = iprot.readString();
- _val110 = iprot.readString();
- _val106.put(_key109, _val110);
- }
- iprot.readMapEnd();
- }
- this.success.put(_key105, _val106);
- }
- iprot.readMapEnd();
- }
+ if (field.type == TType.STRUCT) {
+ this.success = new KsDef();
+ this.success.read(iprot);
} else {
TProtocolUtil.skip(iprot, field.type);
}
@@ -20730,23 +20670,7 @@ public class Cassandra {
if (this.isSetSuccess()) {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
- {
- oprot.writeMapBegin(new TMap(TType.STRING, TType.MAP,
this.success.size()));
- for (Map.Entry<String, Map<String,String>> _iter111 :
this.success.entrySet())
- {
- oprot.writeString(_iter111.getKey());
- {
- oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING,
_iter111.getValue().size()));
- for (Map.Entry<String, String> _iter112 :
_iter111.getValue().entrySet())
- {
- oprot.writeString(_iter112.getKey());
- oprot.writeString(_iter112.getValue());
- }
- oprot.writeMapEnd();
- }
- }
- oprot.writeMapEnd();
- }
+ this.success.write(oprot);
oprot.writeFieldEnd();
} else if (this.isSetNfe()) {
oprot.writeFieldBegin(NFE_FIELD_DESC);
@@ -21686,13 +21610,13 @@ public class Cassandra {
case 0: // SUCCESS
if (field.type == TType.LIST) {
{
- TList _list113 = iprot.readListBegin();
- this.success = new ArrayList<String>(_list113.size);
- for (int _i114 = 0; _i114 < _list113.size; ++_i114)
+ TList _list103 = iprot.readListBegin();
+ this.success = new ArrayList<String>(_list103.size);
+ for (int _i104 = 0; _i104 < _list103.size; ++_i104)
{
- String _elem115;
- _elem115 = iprot.readString();
- this.success.add(_elem115);
+ String _elem105;
+ _elem105 = iprot.readString();
+ this.success.add(_elem105);
}
iprot.readListEnd();
}
@@ -21718,9 +21642,9 @@ public class Cassandra {
oprot.writeFieldBegin(SUCCESS_FIELD_DESC);
{
oprot.writeListBegin(new TList(TType.STRING, this.success.size()));
- for (String _iter116 : this.success)
+ for (String _iter106 : this.success)
{
- oprot.writeString(_iter116);
+ oprot.writeString(_iter106);
}
oprot.writeListEnd();
}
Modified:
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
---
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java
(original)
+++
cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Constants.java
Thu Aug 12 18:29:46 2010
@@ -42,6 +42,6 @@ import org.slf4j.LoggerFactory;
public class Constants {
- public static final String VERSION = "10.0.0";
+ public static final String VERSION = "11.0.0";
}
Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Thu Aug 12
18:29:46 2010
@@ -66,7 +66,7 @@ public class CliClient
private CliSessionState css_ = null;
private String keySpace = null;
private String username = null;
- private Map<String, Map<String, Map<String, String>>> keyspacesMap = new
HashMap<String, Map<String,Map<String,String>>>();
+ private Map<String, KsDef> keyspacesMap = new HashMap<String, KsDef>();
public CliClient(CliSessionState css, Cassandra.Client thriftClient)
{
@@ -402,9 +402,9 @@ public class CliClient
System.exit(0);
}
- Map<String, Map<String, String>> getCFMetaData(String keyspace) throws
NotFoundException, TException
+ KsDef getKSMetaData(String keyspace) throws NotFoundException, TException
{
- // Lazily lookup column family meta-data.
+ // Lazily lookup keyspace meta-data.
if (!(keyspacesMap.containsKey(keyspace)))
keyspacesMap.put(keyspace,
thriftClient_.describe_keyspace(keyspace));
return keyspacesMap.get(keyspace);
@@ -462,14 +462,20 @@ public class CliClient
byte[] superColumnName = null;
byte[] columnName = null;
boolean isSuper;
-
- if (!(keyspacesMap.get(keySpace).containsKey(columnFamily)))
+
+ List<String> cfnames = new ArrayList<String>();
+ for (CfDef cfd : keyspacesMap.get(keySpace).cf_defs) {
+ cfnames.add(cfd.name);
+ }
+
+ int idx = cfnames.indexOf(columnFamily);
+ if (idx == -1)
{
css_.out.println("No such column family: " + columnFamily);
return;
}
- isSuper =
keyspacesMap.get(keySpace).get(columnFamily).get("Type").equals("Super");
+ isSuper =
keyspacesMap.get(keySpace).cf_defs.get(idx).column_type.equals("Super");
if ((columnSpecCnt < 0) || (columnSpecCnt > 2))
{
@@ -534,17 +540,17 @@ public class CliClient
private String formatSuperColumnName(String keyspace, String columnFamily,
SuperColumn column) throws NotFoundException, TException,
IllegalAccessException, InstantiationException, NoSuchFieldException
{
- return
getFormatTypeForColumn(keyspacesMap.get(keyspace).get(columnFamily).get("CompareWith")).getString(column.name);
+ return
getFormatTypeForColumn(getCfDef(keyspace,columnFamily).comparator_type).getString(column.name);
}
private String formatSubcolumnName(String keyspace, String columnFamily,
Column subcolumn) throws NotFoundException, TException, IllegalAccessException,
InstantiationException, NoSuchFieldException
{
- return
getFormatTypeForColumn(keyspacesMap.get(keyspace).get(columnFamily).get("CompareSubcolumnsWith")).getString(subcolumn.name);
+ return
getFormatTypeForColumn(getCfDef(keyspace,columnFamily).subcomparator_type).getString(subcolumn.name);
}
private String formatColumnName(String keyspace, String columnFamily,
Column column) throws NotFoundException, TException, IllegalAccessException,
InstantiationException, NoSuchFieldException
{
- return
getFormatTypeForColumn(keyspacesMap.get(keyspace).get(columnFamily).get("CompareWith")).getString(column.name);
+ return
getFormatTypeForColumn(getCfDef(keyspace,columnFamily).comparator_type).getString(column.name);
}
private AbstractType getFormatTypeForColumn(String compareWith) throws
IllegalAccessException, InstantiationException, NoSuchFieldException
@@ -574,15 +580,21 @@ public class CliClient
String key = CliCompiler.getKey(columnFamilySpec);
String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
- int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
-
- if (!(keyspacesMap.get(keySpace).containsKey(columnFamily)))
+ int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
+
+ List<String> cfnames = new ArrayList<String>();
+ for (CfDef cfd : keyspacesMap.get(keySpace).cf_defs) {
+ cfnames.add(cfd.name);
+ }
+
+ int idx = cfnames.indexOf(columnFamily);
+ if (idx == -1)
{
css_.out.println("No such column family: " + columnFamily);
return;
}
-
- boolean isSuper =
keyspacesMap.get(keySpace).get(columnFamily).get("Type").equals("Super");
+
+ boolean isSuper =
keyspacesMap.get(keySpace).cf_defs.get(idx).column_type.equals("Super");
byte[] superColumnName = null;
byte[] columnName = null;
@@ -905,10 +917,9 @@ public class CliClient
if (!CliMain.isConnected())
return;
- Set<String> tables = thriftClient_.describe_keyspaces();
- for (String table : tables)
- {
- css_.out.println(table);
+ List<KsDef> tables = thriftClient_.describe_keyspaces();
+ for (KsDef t : tables) {
+ describeTableInternal(t.name, t);
}
}
@@ -930,7 +941,9 @@ public class CliClient
public void setKeyspace(String keySpace) throws NotFoundException,
TException
{
this.keySpace = keySpace;
- getCFMetaData(keySpace);
+ //We do nothing with the return value, but it hits a cache and
+ // the tab-completer.
+ getKSMetaData(keySpace);
}
public String getUsername()
@@ -991,7 +1004,12 @@ public class CliClient
{
keyspacesMap.put(keySpace,
thriftClient_.describe_keyspace(keySpace));
}
- CliMain.updateCompletor(keyspacesMap.get(keySpace).keySet());
+ Set<String> cfnames = new HashSet<String>();
+ KsDef ksd = keyspacesMap.get(keySpace);
+ for (CfDef cfd : ksd.cf_defs) {
+ cfnames.add(cfd.name);
+ }
+ CliMain.updateCompletor(cfnames);
css_.out.println("Authenticated to keyspace: " + keySpace);
}
catch (AuthenticationException e)
@@ -1025,43 +1043,36 @@ public class CliClient
}
}
- // process a statement of the form: describe table <tablename>
- private void executeDescribeTable(CommonTree ast) throws TException
- {
- if (!CliMain.isConnected())
- return;
-
- // Get table name
- int childCount = ast.getChildCount();
- assert(childCount == 1);
-
- String tableName = ast.getChild(0).getText();
-
- if( tableName == null ) {
- css_.out.println("Keyspace argument required");
- return;
- }
-
+ private void describeTableInternal(String tableName, KsDef metadata)
throws TException {
// Describe and display
css_.out.println("Keyspace: " + tableName);
-
- Map<String, Map<String, String>> columnFamiliesMap;
try
{
- columnFamiliesMap = thriftClient_.describe_keyspace(tableName);
- for (String columnFamilyName: columnFamiliesMap.keySet())
+ KsDef ks_def;
+ if (metadata != null) {
+ ks_def = metadata;
+ }
+ else {
+ ks_def = thriftClient_.describe_keyspace(tableName);
+ }
+ css_.out.println(" Replication Factor: " +
ks_def.replication_factor);
+ css_.out.println(" Column Families:");
+
+ for (CfDef cf_def : ks_def.cf_defs)
{
- Map<String, String> columnMap =
columnFamiliesMap.get(columnFamilyName);
+ /**
String desc = columnMap.get("Desc");
String columnFamilyType = columnMap.get("Type");
String sort = columnMap.get("CompareWith");
String flushperiod = columnMap.get("FlushPeriodInMinutes");
css_.out.println(desc);
- css_.out.println("Column Family Name: " + columnFamilyName);
- css_.out.println("Column Family Type: " + columnFamilyType);
- css_.out.println("Column Sorted By: " + sort);
- css_.out.println("flush period: " + flushperiod + " minutes");
- css_.out.println("------");
+ */
+ //css_.out.println("description");
+ css_.out.println(" Column Family Name: " + cf_def.name + "
{");
+ css_.out.println(" Column Family Type: " +
cf_def.column_type);
+ css_.out.println(" Column Sorted By: " +
cf_def.comparator_type);
+ //css_.out.println(" flush period: " + flushperiod + "
minutes");
+ css_.out.println(" }");
}
}
catch (NotFoundException e)
@@ -1069,6 +1080,25 @@ public class CliClient
css_.out.println("Keyspace " + tableName + " could not be found.");
}
}
+ // process a statement of the form: describe table <tablename>
+ private void executeDescribeTable(CommonTree ast) throws TException
+ {
+ if (!CliMain.isConnected())
+ return;
+
+ // Get table name
+ int childCount = ast.getChildCount();
+ assert(childCount == 1);
+
+ String tableName = ast.getChild(0).getText();
+
+ if( tableName == null ) {
+ css_.out.println("Keyspace argument required");
+ return;
+ }
+
+ describeTableInternal(tableName, null);
+ }
// process a statement of the form: connect hostname/port
private void executeConnect(CommonTree ast)
@@ -1092,4 +1122,14 @@ public class CliClient
css_.thriftPort = portNumber;
CliMain.connect(css_.hostName, css_.thriftPort);
}
+
+ private CfDef getCfDef(String ksname, String cfname) {
+ List<String> cfnames = new ArrayList<String>();
+ KsDef ksd = keyspacesMap.get(ksname);
+ for (CfDef cfd : ksd.cf_defs) {
+ cfnames.add(cfd.name);
+ }
+ int idx = cfnames.indexOf(cfname);
+ return ksd.cf_defs.get(idx);
+ }
}
Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java Thu Aug 12
18:29:46 2010
@@ -21,12 +21,7 @@ package org.apache.cassandra.cli;
import jline.ConsoleReader;
import jline.History;
import org.apache.cassandra.auth.SimpleAuthenticator;
-import org.apache.cassandra.thrift.AuthenticationException;
-import org.apache.cassandra.thrift.AuthenticationRequest;
-import org.apache.cassandra.thrift.AuthorizationException;
-import org.apache.cassandra.thrift.Cassandra;
-import org.apache.cassandra.thrift.InvalidRequestException;
-import org.apache.cassandra.thrift.NotFoundException;
+import org.apache.cassandra.thrift.*;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TFramedTransport;
@@ -106,7 +101,13 @@ public class CliMain
try {
thriftClient_.set_keyspace(css_.keyspace);
cliClient_.setKeyspace(css_.keyspace);
-
updateCompletor(cliClient_.getCFMetaData(css_.keyspace).keySet());
+
+ Set<String> cfnames = new HashSet<String>();
+ KsDef ksd = cliClient_.getKSMetaData(css_.keyspace);
+ for (CfDef cfd : ksd.cf_defs) {
+ cfnames.add(cfd.name);
+ }
+ updateCompletor(cfnames);
}
catch (InvalidRequestException e)
Modified:
cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
---
cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
(original)
+++
cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
Thu Aug 12 18:29:46 2010
@@ -191,9 +191,18 @@ public class ColumnFamilyRecordReader ex
try
{
partitioner =
FBUtilities.newPartitioner(client.describe_partitioner());
- Map<String, String> info =
client.describe_keyspace(keyspace).get(cfName);
- comparator =
FBUtilities.getComparator(info.get("CompareWith"));
- subComparator = info.get("CompareSubcolumnsWith") == null ?
null : FBUtilities.getComparator(info.get("CompareSubcolumnsWith"));
+
+ // Get the Keyspace metadata, then get the specific CF metadata
+ // in order to populate the sub/comparator.
+ KsDef ks_def = client.describe_keyspace(keyspace);
+ List<String> cfnames = new ArrayList<String>();
+ for (CfDef cfd : ks_def.cf_defs)
+ cfnames.add(cfd.name);
+ int idx = cfnames.indexOf(cfName);
+ CfDef cf_def = ks_def.cf_defs.get(idx);
+
+ comparator = FBUtilities.getComparator(cf_def.comparator_type);
+ subComparator = cf_def.subcomparator_type == null ? null :
FBUtilities.getComparator(cf_def.subcomparator_type);
}
catch (ConfigurationException e)
{
Modified:
cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java
Thu Aug 12 18:29:46 2010
@@ -485,32 +485,36 @@ public class CassandraServer implements
}
}
- public Map<String, Map<String, String>> describe_keyspace(String table)
throws NotFoundException
+ public KsDef describe_keyspace(String table) throws NotFoundException
{
- Map<String, Map<String, String>> columnFamiliesMap = new
HashMap<String, Map<String, String>>();
-
- KSMetaData ksm = DatabaseDescriptor.getTableDefinition(table);
+ KSMetaData ksm = DatabaseDescriptor.getTableDefinition(table);
if (ksm == null)
throw new NotFoundException();
-
- for (Map.Entry<String, CFMetaData> stringCFMetaDataEntry :
ksm.cfMetaData().entrySet())
+ List<CfDef> cfDefs = new ArrayList<CfDef>();
+ for (CFMetaData cfm : ksm.cfMetaData().values())
{
- CFMetaData columnFamilyMetaData = stringCFMetaDataEntry.getValue();
+ CfDef def = new CfDef(cfm.tableName, cfm.cfName);
+ if (cfm.subcolumnComparator != null)
+ {
+
def.setSubcomparator_type(cfm.subcolumnComparator.getClass().getName());
+ def.setColumn_type("Super");
+ }
+ def.setComparator_type(cfm.comparator.getClass().getName());
- Map<String, String> columnMap = new HashMap<String, String>();
- columnMap.put("Type", columnFamilyMetaData.cfType.name());
- columnMap.put("ClockType", columnFamilyMetaData.clockType.name());
- columnMap.put("Desc", columnFamilyMetaData.comment == null ?
columnFamilyMetaData.pretty() : columnFamilyMetaData.comment);
- columnMap.put("CompareWith",
columnFamilyMetaData.comparator.getClass().getName());
- if (columnFamilyMetaData.cfType == ColumnFamilyType.Super)
+ List<ColumnDef> cdef_list = new ArrayList<ColumnDef>();
+ for (ColumnDefinition col_definition :
cfm.column_metadata.values())
{
- columnMap.put("CompareSubcolumnsWith",
columnFamilyMetaData.subcolumnComparator.getClass().getName());
- columnMap.put("Reconciler",
columnFamilyMetaData.reconciler.getClass().getName());
+ ColumnDef cdef = new ColumnDef(col_definition.name,
col_definition.validator.getClass().getName());
+ cdef.setIndex_name(col_definition.index_name);
+ cdef.setIndex_type(col_definition.index_type);
+ cdef_list.add(cdef);
}
- columnFamiliesMap.put(columnFamilyMetaData.cfName, columnMap);
+
+ def.setColumn_metadata(cdef_list);
+ cfDefs.add(def);
}
- return columnFamiliesMap;
+ return new KsDef(ksm.name, ksm.strategyClass.toString(),
ksm.replicationFactor, cfDefs);
}
public List<KeySlice> get_range_slices(ColumnParent column_parent,
SlicePredicate predicate, KeyRange range, ConsistencyLevel consistency_level)
@@ -605,9 +609,19 @@ public class CassandraServer implements
return thriftifyKeySlices(rows, column_parent, column_predicate);
}
- public Set<String> describe_keyspaces() throws TException
+ public List<KsDef> describe_keyspaces() throws TException
{
- return DatabaseDescriptor.getTables();
+ Set<String> keyspaces = DatabaseDescriptor.getTables();
+ List<KsDef> ksset = new ArrayList<KsDef>();
+ for (String ks : keyspaces) {
+ try {
+ ksset.add(describe_keyspace(ks));
+ }
+ catch (NotFoundException nfe) {
+ logger.info("Failed to find metadata for keyspace '" + ks +
"'. Continuing... ");
+ }
+ }
+ return ksset;
}
public String describe_cluster_name() throws TException
Modified: cassandra/trunk/test/system/test_thrift_server.py
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_thrift_server.py?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_thrift_server.py (original)
+++ cassandra/trunk/test/system/test_thrift_server.py Thu Aug 12 18:29:46 2010
@@ -1106,12 +1106,16 @@ class TestMutations(ThriftTester):
assert len(slice) == n, "expected %s results; found %s" % (n,
slice)
def test_describe_keyspace(self):
- """ Test keyspace description """
kspaces = client.describe_keyspaces()
- assert len(kspaces) == 3, kspaces # ['system', 'Keyspace2',
'Keyspace1']
- ks1 = client.describe_keyspace("Keyspace1")
- assert set(ks1.keys()) == set(['Super1', 'Standard1', 'Standard2',
'StandardLong1', 'StandardLong2', 'StandardInteger1', 'Super3', 'Super2',
'Super4', 'Indexed1'])
+ assert len(kspaces) == 3, kspaces # ['Keyspace2', 'Keyspace1',
'system']
+
sysks = client.describe_keyspace("system")
+ assert sysks == kspaces[2]
+
+ ks1 = client.describe_keyspace("Keyspace1")
+ assert ks1.replication_factor == 1
+ cf0 = ks1.cf_defs[0]
+ assert cf0.comparator_type ==
"org.apache.cassandra.db.marshal.BytesType"
def test_describe(self):
server_version = client.describe_version()
@@ -1128,14 +1132,14 @@ class TestMutations(ThriftTester):
[CfDef('CreateKeyspace', 'CreateKsCf')])
client.system_add_keyspace(keyspace)
newks = client.describe_keyspace('CreateKeyspace')
- assert 'CreateKsCf' in newks
+ assert 'CreateKsCf' in [x.name for x in newks.cf_defs]
_set_keyspace('CreateKeyspace')
# rename
client.system_rename_keyspace('CreateKeyspace', 'RenameKeyspace')
renameks = client.describe_keyspace('RenameKeyspace')
- assert 'CreateKsCf' in renameks
+ assert 'CreateKsCf' in [x.name for x in renameks.cf_defs]
def get_first_ks():
client.describe_keyspace('CreateKeyspace')
_expect_exception(get_first_ks, NotFoundException)
@@ -1152,8 +1156,8 @@ class TestMutations(ThriftTester):
cd = ColumnDef('col', 'LongType', None, None)
cf = CfDef('Keyspace1', 'ValidatorColumnFamily', column_metadata=[cd])
client.system_add_column_family(cf)
- dks = client.describe_keyspace(ks)
- assert 'ValidatorColumnFamily' in dks
+ ks_def = client.describe_keyspace(ks)
+ assert 'ValidatorColumnFamily' in [x.name for x in ks_def.cf_defs]
cp = ColumnParent('ValidatorColumnFamily')
col0 = Column('col', _i64(42), Clock(0))
@@ -1169,20 +1173,20 @@ class TestMutations(ThriftTester):
newcf = CfDef('Keyspace1', 'NewColumnFamily', column_metadata=[cd])
client.system_add_column_family(newcf)
ks1 = client.describe_keyspace('Keyspace1')
- assert 'NewColumnFamily' in ks1
+ assert 'NewColumnFamily' in [x.name for x in ks1.cf_defs]
# rename
client.system_rename_column_family('NewColumnFamily',
'RenameColumnFamily')
ks1 = client.describe_keyspace('Keyspace1')
- assert 'RenameColumnFamily' in ks1
- assert 'NewColumnFamily' not in ks1
+ assert 'RenameColumnFamily' in [x.name for x in ks1.cf_defs]
+ assert 'NewColumnFamily' not in [x.name for x in ks1.cf_defs]
# drop
client.system_drop_column_family('RenameColumnFamily')
ks1 = client.describe_keyspace('Keyspace1')
- assert 'RenameColumnFamily' not in ks1
- assert 'NewColumnFamily' not in ks1
- assert 'Standard1' in ks1
+ assert 'RenameColumnFamily' not in [x.name for x in ks1.cf_defs]
+ assert 'NewColumnFamily' not in [x.name for x in ks1.cf_defs]
+ assert 'Standard1' in [x.name for x in ks1.cf_defs]
def test_system_super_column_family_operations(self):
_set_keyspace('Keyspace1')
@@ -1192,20 +1196,20 @@ class TestMutations(ThriftTester):
newcf = CfDef('Keyspace1', 'NewSuperColumnFamily', 'Super',
column_metadata=[cd])
client.system_add_column_family(newcf)
ks1 = client.describe_keyspace('Keyspace1')
- assert 'NewSuperColumnFamily' in ks1
+ assert 'NewSuperColumnFamily' in [x.name for x in ks1.cf_defs]
# rename
client.system_rename_column_family('NewSuperColumnFamily',
'RenameSuperColumnFamily')
ks1 = client.describe_keyspace('Keyspace1')
- assert 'RenameSuperColumnFamily' in ks1
- assert 'NewSuperColumnFamily' not in ks1
+ assert 'RenameSuperColumnFamily' in [x.name for x in ks1.cf_defs]
+ assert 'NewSuperColumnFamily' not in [x.name for x in ks1.cf_defs]
# drop
client.system_drop_column_family('RenameSuperColumnFamily')
ks1 = client.describe_keyspace('Keyspace1')
- assert 'RenameSuperColumnFamily' not in ks1
- assert 'NewSuperColumnFamily' not in ks1
- assert 'Standard1' in ks1
+ assert 'RenameSuperColumnFamily' not in [x.name for x in ks1.cf_defs]
+ assert 'NewSuperColumnFamily' not in [x.name for x in ks1.cf_defs]
+ assert 'Standard1' in [x.name for x in ks1.cf_defs]
def test_insert_ttl(self):
""" Test simple insertion of a column with ttl """
Modified:
cassandra/trunk/test/unit/org/apache/cassandra/hadoop/ColumnFamilyOutputFormatTest.java
URL:
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/hadoop/ColumnFamilyOutputFormatTest.java?rev=984901&r1=984900&r2=984901&view=diff
==============================================================================
---
cassandra/trunk/test/unit/org/apache/cassandra/hadoop/ColumnFamilyOutputFormatTest.java
(original)
+++
cassandra/trunk/test/unit/org/apache/cassandra/hadoop/ColumnFamilyOutputFormatTest.java
Thu Aug 12 18:29:46 2010
@@ -21,6 +21,7 @@ package org.apache.cassandra.hadoop;
import java.io.IOError;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -131,7 +132,9 @@ public class ColumnFamilyOutputFormatTes
Cassandra.Client cassandraClient = new
Cassandra.Client(binaryProtocol);
transport.open();
thriftClient = cassandraClient;
- Set<String> keyspaces = thriftClient.describe_keyspaces();
+ Set<String> keyspaces = new HashSet<String>();
+ for (KsDef def : thriftClient.describe_keyspaces())
+ keyspaces.add(def.name);
if (!keyspaces.contains(KEYSPACE))
{
List<CfDef> cfDefs = new ArrayList<CfDef>();