[Commits] Rev 3518: Cassandra SE: varint datatype support: in file:///data0/psergey/dev2/5.5-cassandra-r01/

Sergey Petrunya psergey at askmonty.org
Mon Sep 24 19:58:27 EEST 2012


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

------------------------------------------------------------
revno: 3518
revision-id: psergey at askmonty.org-20120924165826-5iyrtubi2xe445hm
parent: psergey at askmonty.org-20120924151512-g9t6nh7pc816iib2
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-cassandra-r01
timestamp: Mon 2012-09-24 20:58:26 +0400
message:
  Cassandra SE: varint datatype support: 
  - allow only VARBINARY(n), all other types can get meaningless data after conversions
  - more comments
=== modified file 'mysql-test/r/cassandra.result'
--- a/mysql-test/r/cassandra.result	2012-09-24 15:15:12 +0000
+++ b/mysql-test/r/cassandra.result	2012-09-24 16:58:26 +0000
@@ -341,5 +341,5 @@
 CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, varint_col varbinary(2)) ENGINE=CASSANDRA
 thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf9';
 select rowkey, hex(varint_col) from t2;
-ERROR HY000: Internal error: 'Unable to convert value of field `varint_col` from cassandra's data  format. Source has 4 bytes, data: 12345678'
+ERROR HY000: Internal error: 'Unable to convert value for field `varint_col` from Cassandra's data format. Source data is 4 bytes, 0x12345678'
 drop table t2;

=== modified file 'storage/cassandra/ha_cassandra.cc'
--- a/storage/cassandra/ha_cassandra.cc	2012-09-24 15:15:12 +0000
+++ b/storage/cassandra/ha_cassandra.cc	2012-09-24 16:58:26 +0000
@@ -848,9 +848,7 @@
 
 const char * const validator_boolean= "org.apache.cassandra.db.marshal.BooleanType";
 
-/*
-  VARINTs are stored as little-endian big numbers.
-*/
+/* VARINTs are stored as big-endian big numbers. */
 const char * const validator_varint= "org.apache.cassandra.db.marshal.IntegerType";
 
 
@@ -900,19 +898,32 @@
         break;
       }
       /* fall through: */
+    case MYSQL_TYPE_VAR_STRING:
     case MYSQL_TYPE_VARCHAR:
-    case MYSQL_TYPE_VAR_STRING:
     {
-      bool is_varint;
+      /*
+        Cassandra's "varint" type is a binary-encoded arbitary-length
+        big-endian number. 
+        - It can be mapped to VARBINARY(N), with sufficiently big N.
+        - If the value does not fit into N bytes, it is an error. We should not
+          truncate it, because that is just as good as returning garbage.
+        - varint should not be mapped to BINARY(N), because BINARY(N) values
+          are zero-padded, which will work as multiplying the value by
+          2^k for some value of k.
+      */
+      if (field->type() == MYSQL_TYPE_VARCHAR && 
+          field->binary() &&
+          !strcmp(validator_name, validator_varint))
+      {
+        res= new StringCopyConverter(field->field_length);
+        break;
+      }
+
       if (!strcmp(validator_name, validator_blob) ||
           !strcmp(validator_name, validator_ascii) ||
-          !strcmp(validator_name, validator_text) ||
-          (is_varint= !strcmp(validator_name, validator_varint)))
+          !strcmp(validator_name, validator_text))
       {
-        size_t max_size= (size_t)-1;
-        if (is_varint)
-          max_size= field->field_length;
-        res= new StringCopyConverter(max_size);
+        res= new StringCopyConverter((size_t)-1);
       }
       break;
     }



More information about the commits mailing list