[Commits] Rev 3506: Cassandra SE: added support for boolean type. in file:///data0/psergey/dev2/5.5-cassandra-r01/

Sergey Petrunya psergey at askmonty.org
Fri Sep 7 14:32:45 EEST 2012


At file:///data0/psergey/dev2/5.5-cassandra-r01/

------------------------------------------------------------
revno: 3506
revision-id: psergey at askmonty.org-20120907113243-vn56s52q8fj157lr
parent: psergey at askmonty.org-20120831070359-s93t7miw28cvdi83
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-cassandra-r01
timestamp: Fri 2012-09-07 15:32:43 +0400
message:
  Cassandra SE: added support for boolean type.
=== modified file 'mysql-test/r/cassandra.result'
--- a/mysql-test/r/cassandra.result	2012-08-31 07:03:59 +0000
+++ b/mysql-test/r/cassandra.result	2012-09-07 11:32:43 +0000
@@ -266,3 +266,13 @@
 9b5658dc-f32f-11e1-94cd-f46d046e9f09	1234
 delete from t2;
 drop table t2;
+CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol varchar(12)) ENGINE=CASSANDRA
+thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
+insert into t2 values (0, 0);
+insert into t2 values (1, 1);
+select * from t2;
+rowkey	boolcol
+0	0
+1	1
+delete from t2;
+drop table t2;

=== modified file 'mysql-test/t/cassandra.test'
--- a/mysql-test/t/cassandra.test	2012-08-31 07:03:59 +0000
+++ b/mysql-test/t/cassandra.test	2012-09-07 11:32:43 +0000
@@ -53,6 +53,8 @@
 
 create columnfamily cf6 (rowkey uuid primary key, col1 int);
 
+create columnfamily cf7 (rowkey int primary key, boolcol boolean);
+
 ./cassandra-cli 
 
 CREATE COLUMN FAMILY cf10
@@ -329,6 +331,16 @@
 delete from t2;
 drop table t2;
 
+
+# create columnfamily cf7 (rowkey int primary key, boolcol boolean);
+CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol varchar(12)) ENGINE=CASSANDRA
+  thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf7';
+insert into t2 values (0, 0);
+insert into t2 values (1, 1);
+select * from t2;
+delete from t2;
+drop table t2;
+
 ############################################################################
 ## Cassandra cleanup
 ############################################################################
@@ -337,6 +349,9 @@
 drop columnfamily cf2;
 drop columnfamily cf3;
 drop columnfamily cf4;
+drop columnfamily cf5;
+drop columnfamily cf6;
+drop columnfamily cf7;
 --enable_parsing
 ############################################################################
 ## Cassandra cleanup ends

=== modified file 'storage/cassandra/ha_cassandra.cc'
--- a/storage/cassandra/ha_cassandra.cc	2012-08-31 07:03:59 +0000
+++ b/storage/cassandra/ha_cassandra.cc	2012-09-07 11:32:43 +0000
@@ -529,6 +529,28 @@
   to[3]= from[0];
 }
 
+
+class TinyintDataConverter : public ColumnDataConverter
+{
+  char buf;
+public:
+  void cassandra_to_mariadb(const char *cass_data, int cass_data_len)
+  {
+    DBUG_ASSERT(cass_data_len == 1);
+    field->store(cass_data[0]);
+  }
+
+  bool mariadb_to_cassandra(char **cass_data, int *cass_data_len)
+  {
+    buf= field->val_int()? 1 : 0; /* TODO: error handling? */
+    *cass_data= (char*)&buf;
+    *cass_data_len= 1;
+    return false;
+  }
+  ~TinyintDataConverter(){}
+};
+
+
 class Int32DataConverter : public ColumnDataConverter
 {
   int32_t buf;
@@ -683,6 +705,7 @@
   ~UuidDataConverter(){}
 };
 
+
 const char * const validator_bigint=  "org.apache.cassandra.db.marshal.LongType";
 const char * const validator_int=     "org.apache.cassandra.db.marshal.Int32Type";
 const char * const validator_counter= "org.apache.cassandra.db.marshal.CounterColumnType";
@@ -698,12 +721,20 @@
 
 const char * const validator_uuid= "org.apache.cassandra.db.marshal.UUIDType";
 
+const char * const validator_boolean= "org.apache.cassandra.db.marshal.BooleanType";
+
 ColumnDataConverter *map_field_to_validator(Field *field, const char *validator_name)
 {
   ColumnDataConverter *res= NULL;
 
   switch(field->type()) {
     case MYSQL_TYPE_TINY:
+      if (!strcmp(validator_name, validator_boolean))
+      {
+        res= new TinyintDataConverter;
+        break;
+      }
+      /* fall through: */
     case MYSQL_TYPE_SHORT:
     case MYSQL_TYPE_LONGLONG:
       if (!strcmp(validator_name, validator_bigint))



More information about the commits mailing list