mariadb/mysql-test/t/cassandra.test
Sergey Petrunya 73dfd5782b Cassandra SE: more datatypes support
- Support mapping Cassandra's timestamp to INT64
- Support mapping Cassadnra's decimal to VARBINARY.
2012-09-25 16:20:19 +04:00

482 lines
16 KiB
Text

#
# Tests for cassandra storage engine
#
--source include/have_cassandra.inc
--disable_warnings
drop table if exists t0, t1;
--enable_warnings
# Test various errors on table creation.
--error ER_WRONG_COLUMN_NAME
create table t1 (a int) engine=cassandra
thrift_host='localhost' keyspace='foo' column_family='colfam';
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
create table t1 (a int primary key, b int) engine=cassandra
thrift_host='localhost' keyspace='foo' column_family='colfam';
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
create table t1 (rowkey char(10) primary key, column1 char(10)) engine=cassandra
thrift_host='127.0.0.2' keyspace='foo' column_family='colfam';
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
create table t1 (rowkey char(10) primary key, column1 char(10)) engine=cassandra
thrift_host='localhost' keyspace='no_such_keyspace' column_family='colfam';
# No column family specified
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
create table t1 (rowkey char(10) primary key, column1 char(10)) engine=cassandra
thrift_host='localhost' keyspace='no_such_keyspace';
############################################################################
## Cassandra initialization
############################################################################
# Step 1: remove the keyspace that could be left over from the previous test
--remove_files_wildcard $MYSQLTEST_VARDIR cassandra_test_cleanup.cql
--write_file $MYSQLTEST_VARDIR/cassandra_test_cleanup.cql
drop keyspace mariadbtest2;
EOF
--error 0,1,2
--system cqlsh -3 -f $MYSQLTEST_VARDIR/cassandra_test_cleanup.cql
# Step 2: create new keyspace and test column families
--remove_files_wildcard $MYSQLTEST_VARDIR cassandra_test_init.cql
--write_file $MYSQLTEST_VARDIR/cassandra_test_init.cql
CREATE KEYSPACE mariadbtest2
WITH strategy_class = 'org.apache.cassandra.locator.SimpleStrategy'
AND strategy_options:replication_factor='1';
USE mariadbtest2;
create columnfamily cf1 ( pk varchar primary key, data1 varchar, data2 bigint);
create columnfamily cf2 (rowkey bigint primary key, a bigint);
create columnfamily cf3 (rowkey bigint primary key, intcol int);
create columnfamily cf4 (rowkey bigint primary key, datecol timestamp);
create columnfamily cf5 (rowkey bigint primary key, uuidcol uuid);
create columnfamily cf6 (rowkey uuid primary key, col1 int);
create columnfamily cf7 (rowkey int primary key, boolcol boolean);
create columnfamily cf8 (rowkey varchar primary key, countercol counter);
update cf8 set countercol=countercol+1 where rowkey='cnt1';
update cf8 set countercol=countercol+100 where rowkey='cnt2';
create columnfamily cf9 (rowkey varchar primary key, varint_col varint);
insert into cf9 (rowkey, varint_col) values ('val-01', 1);
insert into cf9 (rowkey, varint_col) values ('val-0x123456', 1193046);
insert into cf9 (rowkey, varint_col) values ('val-0x12345678', 305419896);
create columnfamily cf11 (rowkey varchar primary key, decimal_col decimal);
insert into cf11 (rowkey, decimal_col) values ('val_0.5', 0.5);
insert into cf11 (rowkey, decimal_col) values ('val_1.5', 1.5);
insert into cf11 (rowkey, decimal_col) values ('val_1234', 1234);
EOF
--error 0,1,2
--system cqlsh -3 -f $MYSQLTEST_VARDIR/cassandra_test_init.cql
# Step 3: Cassandra's CQL doesn't allow certain kinds of queries. Run them in
# CLI
--remove_files_wildcard $MYSQLTEST_VARDIR cassandra_test_init.cli
--write_file $MYSQLTEST_VARDIR/cassandra_test_init.cli
use mariadbtest2;
CREATE COLUMN FAMILY cf10
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND default_validation_class = UTF8Type;
EOF
--error 0,1,2
--system cassandra-cli -f $MYSQLTEST_VARDIR/cassandra_test_init.cli
############################################################################
## Cassandra initialization ends
############################################################################
--echo # Now, create a table for real and insert data
create table t1 (pk varchar(36) primary key, data1 varchar(60), data2 bigint) engine=cassandra
thrift_host='localhost' keyspace='mariadbtest2' column_family='cf1';
--echo # Just in case there were left-overs from previous:
delete from t1;
select * from t1;
insert into t1 values ('rowkey10', 'data1-value', 123456);
insert into t1 values ('rowkey11', 'data1-value2', 34543);
insert into t1 values ('rowkey12', 'data1-value3', 454);
select * from t1;
explain
select * from t1 where pk='rowkey11';
select * from t1 where pk='rowkey11';
# Deletion functions weirdly: it sets all columns to NULL
# but when If I do this in cassandra-cli:
#
# del cf1[ascii('rowkey10')]
#
# Subsequent 'list cf1' command also gives
#
# RowKey: rowkey10
#
# without any columns.
#
# CQL seems to simply ignore all "incomplete" records.
delete from t1 where pk='rowkey11';
select * from t1;
delete from t1;
select * from t1;
--echo #
--echo # A query with filesort (check that table_flags() & HA_REC_NOT_IN_SEQ,
--echo # also check ::rnd_pos()
--echo #
insert into t1 values ('rowkey10', 'data1-value', 123456);
insert into t1 values ('rowkey11', 'data1-value2', 34543);
insert into t1 values ('rowkey12', 'data1-value3', 454);
select * from t1 order by data2;
delete from t1;
drop table t1;
--echo #
--echo # MDEV-476: Cassandra: Server crashes in calculate_key_len on DELETE with ORDER BY
--echo #
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
INSERT INTO t1 VALUES (1,1),(2,2);
DELETE FROM t1 ORDER BY a LIMIT 1;
DROP TABLE t1;
--echo #
--echo # Batched INSERT
--echo #
show variables like 'cassandra_insert_batch_size';
show status like 'cassandra_row_insert%';
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
delete from t1;
INSERT INTO t1 VALUES (1,1),(2,2);
DELETE FROM t1 ORDER BY a LIMIT 1;
DROP TABLE t1;
show status like 'cassandra_row_insert%';
--echo # FLUSH STATUS doesn't work for our variables, just like with InnoDB.
flush status;
show status like 'cassandra_row_insert%';
--echo #
--echo # Batched Key Access
--echo #
--echo # Control variable (we are not yet able to make use of MRR's buffer)
show variables like 'cassandra_multi%';
--echo # MRR-related status variables:
show status like 'cassandra_multi%';
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
delete from t1;
INSERT INTO t1 VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
set @tmp_jcl=@@join_cache_level;
set join_cache_level=8;
explain select * from t1 A, t1 B where B.rowkey=A.a;
select * from t1 A, t1 B where B.rowkey=A.a;
show status like 'cassandra_multi%';
# The following INSERTs are really UPDATEs
insert into t1 values(1, 8);
insert into t1 values(3, 8);
insert into t1 values(5, 8);
insert into t1 values(7, 8);
select * from t1 A, t1 B where B.rowkey=A.a;
show status like 'cassandra_multi%';
delete from t1;
drop table t1;
--echo #
--echo # MDEV-480: TRUNCATE TABLE on a Cassandra table does not remove rows
--echo #
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
INSERT INTO t1 VALUES (0,0),(1,1),(2,2);
truncate table t1;
select * from t1;
drop table t1;
--echo #
--echo # MDEV-494, part #1: phantom row for big full-scan selects
--echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
insert into t1 select A.a + 10 * B.a + 100*C.a, 12345 from t0 A, t0 B, t0 C;
select count(*) from t1;
select count(*) from t1 where a=12345;
delete from t1;
drop table t1;
drop table t0;
--echo # 32-bit INT type support
CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, intcol INT) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf3';
insert into t1 values (10,10);
insert into t1 values (12,12);
delete from t1;
drop table t1;
--echo #
--echo # Try accessing column family w/o explicitly defined columns
--echo #
--error ER_INTERNAL_ERROR
CREATE TABLE t1 (my_primary_key varchar(10) PRIMARY KEY) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf10';
CREATE TABLE t1 (rowkey varchar(10) PRIMARY KEY) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf10';
DROP TABLE t1;
--echo #
--echo # Timestamp datatype support
--echo #
CREATE TABLE t2 (rowkey bigint PRIMARY KEY, datecol timestamp) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf4';
delete from t2;
insert into t2 values (1, '2012-08-29 01:23:45');
select * from t2;
delete from t2;
--echo # MDEV-498: Cassandra: Inserting a timestamp does not work on a 32-bit system
INSERT INTO t2 VALUES (10,'2012-12-12 12:12:12');
SELECT * FROM t2;
delete from t2;
--echo #
--echo # (no MDEV#) Check that insert counters work correctly
--echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
let $start_inserts=`select variable_value from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_inserts'`;
let $start_insert_batches=`select variable_value from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_insert_batches'`;
set cassandra_insert_batch_size=10;
insert into t2 select A.a+10*B.a, now() from t0 A, t0 B;
--disable_query_log
eval select
(select variable_value - $start_inserts from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_inserts')
AS 'inserts',
(select variable_value - $start_insert_batches from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_insert_batches')
AS 'insert_batches';
--enable_query_log
let $start_inserts=`select variable_value from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_inserts'`;
let $start_insert_batches=`select variable_value from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_insert_batches'`;
set cassandra_insert_batch_size=1;
insert into t2 select A.a+10*B.a+100, now() from t0 A, t0 B;
--disable_query_log
eval select
(select variable_value - $start_inserts from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_inserts')
AS 'inserts',
(select variable_value - $start_insert_batches from information_schema.SESSION_STATUS
where variable_name ='Cassandra_row_insert_batches')
AS 'insert_batches';
--enable_query_log
delete from t2;
drop table t2;
drop table t0;
--echo #
--echo # UUID datatype support
--echo #
#create columnfamily cf5 (rowkey bigint primary key, uuidcol uuid);
CREATE TABLE t2 (rowkey bigint PRIMARY KEY, uuidcol char(36)) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf5';
delete from t2;
insert into t2 values(1,'9b5658dc-f32f-11e1-94cd-f46d046e9f09');
--error ER_WARN_DATA_OUT_OF_RANGE
insert into t2 values(2,'not-an-uuid');
--error ER_WARN_DATA_OUT_OF_RANGE
insert into t2 values(3,'9b5658dc-f32f-11e1=94cd-f46d046e9f09');
--error ER_WARN_DATA_OUT_OF_RANGE
insert into t2 values(4,'9b5658dc-fzzf-11e1-94cd-f46d046e9f09');
--error ER_WARN_DATA_OUT_OF_RANGE
insert into t2 values
(5,'9b5658dc-f11f-11e1-94cd-f46d046e9f09'),
(6,'9b5658dc-f11f011e1-94cd-f46d046e9f09');
select * from t2;
delete from t2;
drop table t2;
# create columnfamily cf6 (rowkey uuid primary key, col1 int);
CREATE TABLE t2 (rowkey char(36) PRIMARY KEY, col1 int) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf6';
delete from t2;
insert into t2 values('9b5658dc-f32f-11e1-94cd-f46d046e9f09', 1234);
--error ER_WARN_DATA_OUT_OF_RANGE
insert into t2 values('not-an-uuid', 563);
select * from t2;
delete from t2;
drop table t2;
--echo #
--echo # boolean datatype support
--echo #
# create columnfamily cf7 (rowkey int primary key, boolcol boolean);
CREATE TABLE t2 (rowkey int PRIMARY KEY, boolcol bool) 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;
--echo #
--echo # Counter datatype support (read-only)
--echo #
# create columnfamily cf8 (rowkey int primary key, countercol counter);
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf8';
select * from t2;
drop table t2;
--echo #
--echo # Check that @@cassandra_default_thrift_host works
--echo #
show variables like 'cassandra_default_thrift_host';
set @tmp=@@cassandra_default_thrift_host;
--error ER_GLOBAL_VARIABLE
set cassandra_default_thrift_host='localhost';
set global cassandra_default_thrift_host='localhost';
--echo # Try creating a table without specifying thrift_host:
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, countercol bigint) ENGINE=CASSANDRA
keyspace='mariadbtest2' column_family = 'cf8';
select * from t2;
drop table t2;
set global cassandra_default_thrift_host=@tmp;
--echo #
--echo # Consistency settings
--echo #
show variables like 'cassandra_%consistency';
set @tmp=@@cassandra_write_consistency;
--echo # Unfortunately, there is no easy way to check if setting have the effect..
set cassandra_write_consistency='ONE';
set cassandra_write_consistency='QUORUM';
set cassandra_write_consistency='LOCAL_QUORUM';
set cassandra_write_consistency='EACH_QUORUM';
set cassandra_write_consistency='ALL';
set cassandra_write_consistency='ANY';
set cassandra_write_consistency='TWO';
set cassandra_write_consistency='THREE';
set cassandra_write_consistency=@tmp;
--echo #
--echo # varint datatype support
--echo #
# create columnfamily cf9 (rowkey varchar primary key, varint_col varint);
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, varint_col varbinary(32)) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf9';
--sorted_result
select rowkey, hex(varint_col) from t2;
drop table t2;
--echo # now, let's check what happens when MariaDB's column is not wide enough:
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, varint_col varbinary(2)) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf9';
--sorted_result
--error ER_INTERNAL_ERROR
select rowkey, hex(varint_col) from t2;
drop table t2;
--echo #
--echo # Decimal datatype support
--echo #
CREATE TABLE t2 (rowkey varchar(32) PRIMARY KEY, decimal_col varbinary(32)) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf11';
select rowkey, hex(decimal_col) from t2;
drop table t2;
--echo #
--echo # Mapping TIMESTAMP -> int64
--echo #
CREATE TABLE t2 (rowkey bigint PRIMARY KEY, datecol timestamp) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf4';
insert into t2 values (1, '2012-08-29 01:23:45');
INSERT INTO t2 VALUES (10,'2012-08-29 01:23:46');
drop table t2;
CREATE TABLE t2 (rowkey bigint PRIMARY KEY, datecol bigint) ENGINE=CASSANDRA
thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf4';
select * from t2;
drop table t2;
############################################################################
## Cassandra cleanup
############################################################################
--disable_parsing
drop columnfamily cf1;
drop columnfamily cf2;
drop columnfamily cf3;
drop columnfamily cf4;
drop columnfamily cf5;
drop columnfamily cf6;
drop columnfamily cf7;
--enable_parsing
############################################################################
## Cassandra cleanup ends
############################################################################