Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed issue with composite column metadata marshalling

  • Loading branch information...
commit 1191611cede60eeae8adced44474ed295590f87d 1 parent bce46eb
@devdazed devdazed authored
View
30 lib/column_family.js
@@ -186,20 +186,41 @@ var ColumnFamily = function(keyspace, definition){
this.subcolumnMarshaller = this.isSuper ? new Marshal(definition.subcomparator_type) : null;
this.valueMarshaller = new Marshal(definition.default_validation_class);
this.keyMarshaller = new Marshal(definition.key_validation_class);
- this.columns = {};
+ this.columnValidators = {};
var self = this;
if(definition.column_metadata && Array.isArray(definition.column_metadata)){
var i = 0, len = definition.column_metadata.length, col;
for(; i < len; i += 1){
col = definition.column_metadata[i];
- this.columns[col.name] = new Marshal(col.validation_class);
+ col.name = this.columnMarshaller.deserialize(col.name);
+ this.setColumnValidator(col.name, col.validation_class);
}
}
+};
+/**
+ * Sets the marshaller for a given column name
+ * @param name {Object} The name of column to set
+ * @param type {String} The validation Class to use for the specified column
+ */
+ColumnFamily.prototype.setColumnValidator = function(name, type){
+ var binName = this.columnMarshaller.serialize(name).toString('binary');
+ this.columnValidators[binName] = new Marshal(type);
};
/**
+ * Gets the column validator (marshaller) for a column
+ * @param name
+ * @return {Marshal}
+ */
+ColumnFamily.prototype.getColumnValidator = function(name){
+ var marshalledName = this.columnMarshaller.serialize(name),
+ binName = marshalledName.toString('binary');
+
+ return this.columnValidators[binName];
+};
+/**
* Performs a set command to the cluster
*
* @param {String} key The key for the row
@@ -223,7 +244,8 @@ ColumnFamily.prototype.insert = function(key, columns, options, callback){
for(; i < len; i += 1){
col = columns[i];
- valueMarshaller = this.columns[col.name] || this.valueMarshaller;
+ valueMarshaller = this.getColumnValidator(col.name) || this.valueMarshaller;
+
mutations.push(new ttype.Mutation({
column_or_supercolumn: new ttype.ColumnOrSuperColumn({
column: col.toThrift(this.columnMarshaller, valueMarshaller)
@@ -364,7 +386,7 @@ ColumnFamily.prototype.getIndexed = function(query, options, callback){
for(; i < len; i += 1){
field = query.fields[i];
- valueMarshaller = this.columns[field.column] || this.valueMarshaller;
+ valueMarshaller = this.getColumnValidator(field.column) || this.valueMarshaller;
indexExpressions.push(new ttype.IndexExpression({
column_name:this.columnMarshaller.serialize(field.column),
View
15 lib/keyspace.js
@@ -1,5 +1,6 @@
var ColumnFamily = require('./column_family'),
- ttypes = require('./cassandra/cassandra_types');
+ ttypes = require('./cassandra/cassandra_types'),
+ Marshal = require('./marshal');
/**
@@ -136,16 +137,20 @@ Keyspace.prototype.createColumnFamily = function(name, options, callback){
callback = callback || NOOP;
options = options || {};
- var meta;
+ var meta,
+ comparator = options.comparator_type || 'BytesType';
+
if(options.columns && Array.isArray(options.columns)){
- var i = 0, len = options.columns.length, col;
+ var i = 0, len = options.columns.length, col,
+ columnMarshaller = new Marshal(comparator);
+
meta = [];
for(; i < len; i += 1){
col = options.columns[i];
meta.push(new ttypes.ColumnDef({
- name: col.name,
+ name: columnMarshaller.serialize(col.name),
validation_class: col.validation_class,
index_type: col.index_type,
index_name: col.index_name,
@@ -158,7 +163,7 @@ Keyspace.prototype.createColumnFamily = function(name, options, callback){
keyspace: this.name,
name: name,
column_type: options.column_type || 'Standard',
- comparator_type: options.comparator_type || 'BytesType',
+ comparator_type: comparator,
subcomparator_type: options.subcomparator_type,
comment: options.comment,
read_repair_chance: options.read_repair_chance || 1,
View
11 lib/marshal/index.js
@@ -210,7 +210,7 @@ function getSerializer(type){
return compositeSerializer(serializers);
} else {
- return TYPES[type].ser;
+ return TYPES[type.replace(/^\s+|\s+$/g,'')].ser;
}
}
@@ -230,7 +230,7 @@ function getDeserializer(type){
} else {
return function(val) {
return val !== null ? TYPES[type].de(val) : null;
- }
+ };
}
}
@@ -242,12 +242,7 @@ function getDeserializer(type){
var Marshal = function(type){
var parsedType = parseTypeString(type);
this.type = parsedType;
-
- if(Array.isArray(parsedType)){
- this.isComposite = true;
- } else {
- this.isComposite = false;
- }
+ this.isComposite = Array.isArray(parsedType);
/**
* Serializes data for the type specified
View
7 test/helpers/thrift.json → test/helpers/thrift.js
@@ -1,4 +1,4 @@
-{
+module.exports = {
"keyspace" : "helenus_test_keyspace",
"cf_standard" : "cf_standard_test",
"cf_standard_composite" : "cf_standard_composite_test",
@@ -29,7 +29,10 @@
"cf_standard_composite_options" : {
"key_validation_class" : "CompositeType(UTF8Type, UUIDType)",
"comparator_type" : "CompositeType(LongType, DateType)",
- "default_validation_class" : "UTF8Type"
+ "default_validation_class" : "UTF8Type",
+ "columns": [
+ { "name": [123, new Date(2012,9,1)], "validation_class" : "BytesType"}
+ ]
},
"cf_supercolumn_options" : {
"column_type" : "Super",
View
2  test/thrift.js
@@ -183,6 +183,8 @@ module.exports = {
],
key = [ 'åbcd', new Helenus.UUID('e491d6ac-b124-4795-9ab3-c8a0cf92615c') ];
+ cf_composite.setColumnValidator(values[0].name, 'UTF8Type');
+
cf_composite.insert(key, values, function(err, results){
assert.ifError(err);
test.finish();
Please sign in to comment.
Something went wrong with that request. Please try again.