Commit 082ff593 authored by unknown's avatar unknown

Post-post review fixes.

parent 40ae63dd
......@@ -33,13 +33,6 @@
#include <my_decimal_limits.h>
#include <mysql_time.h>
/*
Max length for data in a dynamic colums. This comes from how the
how the offset are stored.
*/
#define MAX_DYNAMIC_COLUMN_LENGTH 0X1FFFFFFFL
#define MAX_DYNAMIC_COLUMN_LENGTH_NM 0XFFFFFFFFFL
/*
Limits of implementation
*/
......@@ -101,7 +94,6 @@ struct st_dynamic_column_value
typedef struct st_dynamic_column_value DYNAMIC_COLUMN_VALUE;
/* old functions (deprecated) */
#ifdef MADYNCOL_DEPRECATED
enum enum_dyncol_func_result
dynamic_column_create(DYNAMIC_COLUMN *str,
......@@ -168,7 +160,7 @@ mariadb_dyncol_exists_named(DYNAMIC_COLUMN *str, LEX_STRING *name);
/* List of not NULL columns */
enum enum_dyncol_func_result
mariadb_dyncol_list(DYNAMIC_COLUMN *org, DYNAMIC_ARRAY *array_of_uint);
mariadb_dyncol_list(DYNAMIC_COLUMN *str, uint *count, uint **nums);
enum enum_dyncol_func_result
mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names);
......@@ -213,17 +205,11 @@ int mariadb_dyncol_column_cmp_named(const LEX_STRING *s1, const LEX_STRING *s2);
enum enum_dyncol_func_result
mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count);
/***************************************************************************
Internal functions, don't use if you don't know what you are doing...
***************************************************************************/
#define mariadb_dyncol_reassociate(V,P,L, A) dynstr_reassociate((V),(P),(L),(A))
#define dyncol_value_init(V) (V)->type= DYN_COL_NULL
#define mariadb_dyncol_value_init(V) (V)->type= DYN_COL_NULL
/*
Prepare value for using as decimal
*/
void dynamic_column_prepare_decimal(DYNAMIC_COLUMN_VALUE *value);
void mariadb_dyncol_prepare_decimal(DYNAMIC_COLUMN_VALUE *value);
#endif
......@@ -448,7 +448,7 @@ CREATE TABLE t2 (rowkey bigint PRIMARY KEY, dyn blob DYNAMIC_COLUMN_STORAGE=yes)
insert into t2 values (1, column_create("dyn1", 1, "dyn2", "two"));
select rowkey, column_json(dyn) from t2;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn2":"two"}]
1 {"dyn1":"1","dyn2":"two"}
delete from t2;
drop table t2;
# bigint
......@@ -457,8 +457,8 @@ insert into t1 values (1, column_create("dyn1", 1, "dyn2", "two", 'a', 254324));
insert into t1 values (2, column_create("dyn1", 1, "dyn2", "two", 'a', 2543));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":254324},{"dyn1":"1"},{"dyn2":"two"}]
2 [{"a":2543},{"dyn1":"1"},{"dyn2":"two"}]
1 {"a":254324,"dyn1":"1","dyn2":"two"}
2 {"a":2543,"dyn1":"1","dyn2":"two"}
delete from t1;
drop table t1;
# int
......@@ -467,8 +467,8 @@ insert into t1 values (1, column_create("dyn1", 1, "dyn2", "two", 'intcol', 2543
insert into t1 values (2, column_create("dyn1", 1, "dyn2", "two", 'intcol', 2543));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn2":"two"},{"intcol":254324}]
2 [{"dyn1":"1"},{"dyn2":"two"},{"intcol":2543}]
1 {"dyn1":"1","dyn2":"two","intcol":254324}
2 {"dyn1":"1","dyn2":"two","intcol":2543}
delete from t1;
drop table t1;
# timestamp
......@@ -477,8 +477,8 @@ insert into t1 values (1, column_create("dyn1", 1, "dyn2", "two", 'datecol', 254
insert into t1 values (2, column_create("dyn1", 1, "dyn2", "two", 'datecol', 2543));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn2":"two"},{"datecol":254324}]
2 [{"dyn1":"1"},{"dyn2":"two"},{"datecol":2543}]
1 {"dyn1":"1","dyn2":"two","datecol":254324}
2 {"dyn1":"1","dyn2":"two","datecol":2543}
delete from t1;
drop table t1;
# boolean
......@@ -487,47 +487,47 @@ insert into t1 values (1, column_create("dyn1", 1, "dyn2", "two", 'boolcol', 254
insert into t1 values (2, column_create("dyn1", 1, "dyn2", "two", 'boolcol', 0));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn2":"two"},{"boolcol":1}]
2 [{"dyn1":"1"},{"dyn2":"two"},{"boolcol":0}]
1 {"dyn1":"1","dyn2":"two","boolcol":1}
2 {"dyn1":"1","dyn2":"two","boolcol":0}
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn2":"two"},{"boolcol":1}]
2 [{"dyn1":"1"},{"dyn2":"two"},{"boolcol":0}]
1 {"dyn1":"1","dyn2":"two","boolcol":1}
2 {"dyn1":"1","dyn2":"two","boolcol":0}
update t1 set dyn=column_add(dyn, "dyn2", null, "dyn3", "3");
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn1":"1"},{"dyn3":"3"},{"boolcol":1}]
2 [{"dyn1":"1"},{"dyn3":"3"},{"boolcol":0}]
1 {"dyn1":"1","dyn3":"3","boolcol":1}
2 {"dyn1":"1","dyn3":"3","boolcol":0}
update t1 set dyn=column_add(dyn, "dyn1", null) where rowkey= 1;
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"dyn3":"3"},{"boolcol":1}]
2 [{"dyn1":"1"},{"dyn3":"3"},{"boolcol":0}]
1 {"dyn3":"3","boolcol":1}
2 {"dyn1":"1","dyn3":"3","boolcol":0}
update t1 set dyn=column_add(dyn, "dyn3", null, "a", "ddd");
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":"ddd"},{"boolcol":1}]
2 [{"a":"ddd"},{"dyn1":"1"},{"boolcol":0}]
1 {"a":"ddd","boolcol":1}
2 {"a":"ddd","dyn1":"1","boolcol":0}
update t1 set dyn=column_add(dyn, "12345678901234", "ddd");
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":"ddd"},{"boolcol":1},{"12345678901234":"ddd"}]
2 [{"a":"ddd"},{"dyn1":"1"},{"boolcol":0},{"12345678901234":"ddd"}]
1 {"a":"ddd","boolcol":1,"12345678901234":"ddd"}
2 {"a":"ddd","dyn1":"1","boolcol":0,"12345678901234":"ddd"}
update t1 set dyn=column_add(dyn, "12345678901234", null);
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":"ddd"},{"boolcol":1}]
2 [{"a":"ddd"},{"dyn1":"1"},{"boolcol":0}]
1 {"a":"ddd","boolcol":1}
2 {"a":"ddd","dyn1":"1","boolcol":0}
update t1 set dyn=column_add(dyn, 'boolcol', null) where rowkey= 2;
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":"ddd"},{"boolcol":1}]
2 [{"a":"ddd"},{"dyn1":"1"}]
1 {"a":"ddd","boolcol":1}
2 {"a":"ddd","dyn1":"1"}
update t1 set rowkey= 3, dyn=column_add(dyn, "dyn1", null, 'boolcol', 0) where rowkey= 2;
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
1 [{"a":"ddd"},{"boolcol":1}]
3 [{"a":"ddd"},{"boolcol":0}]
1 {"a":"ddd","boolcol":1}
3 {"a":"ddd","boolcol":0}
delete from t1;
drop table t1;
CREATE TABLE t1 (rowkey varchar(10) PRIMARY KEY, dyn blob DYNAMIC_COLUMN_STORAGE=yes) ENGINE=CASSANDRA thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cfd1';
......@@ -567,14 +567,14 @@ ENGINE=CASSANDRA thrift_host='localhost' keyspace='mariadbtest2' column_family =
INSERT INTO t1 VALUES(2,column_create("ab","ab"));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
2 [{"ab":"ab"}]
2 {"ab":"ab"}
UPDATE t1 set dyn=NULL;
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
INSERT INTO t1 VALUES(2,column_create("ab","ab"));
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
2 [{"ab":"ab"}]
2 {"ab":"ab"}
UPDATE t1 set dyn="";
select rowkey, column_json(dyn) from t1;
rowkey column_json(dyn)
......
......@@ -1568,10 +1568,10 @@ ERROR 22007: Illegal value used as argument of dynamic column function
#
select column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" AS datetime, "date", "2011-04-05" AS date));
column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001"
[{"int":-1212},{"date":"2011-04-05"},{"time":"00:45:49.000001"},{"uint":12334},{"double":"1.23444e+50"},{"string":"gdgd\\dhdjh\"dhdhd"},{"decimal":23.344},{"datetime":"2011-04-05 00:45:49.000001"}]
{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":"1.23444e+50","string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"}
select column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date));
column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date))
[{"1":-1212},{"2":12334},{"3":23.344},{"4":"1.23444e+50"},{"5":"gdgd\\dhdjh\"dhdhd"},{"6":"00:45:49.000001"},{"7":"2011-04-05 00:45:49.000001"},{"8":"2011-04-05"}]
{"1":-1212,"2":12334,"3":23.344,"4":"1.23444e+50","5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"}
#
# CHECK test
#
......@@ -1592,48 +1592,48 @@ NULL
#
select column_json(column_create("string", "'\"/\\`.,whatever")),hex(column_create("string", "'\"/\\`.,whatever"));
column_json(column_create("string", "'\"/\\`.,whatever")) hex(column_create("string", "'\"/\\`.,whatever"))
[{"string":"'\"/\\`.,whatever"}] 040100060000000300737472696E670827222F5C602E2C7768617465766572
{"string":"'\"/\\`.,whatever"} 040100060000000300737472696E670827222F5C602E2C7768617465766572
#
# embedding test
#
select column_json(column_create("val", "val", "emb", column_create("val2", "val2")));
column_json(column_create("val", "val", "emb", column_create("val2", "val2")))
[{"emb":[{"val2":"val2"}],{"val":"val"}]
{"emb":{"val2":"val2"},"val":"val"}
select column_json(column_create(1, "val", 2, column_create(3, "val2")));
column_json(column_create(1, "val", 2, column_create(3, "val2")))
[{"1":"val"},{"2":[{"3":"val2"}]]
{"1":"val","2":{"3":"val2"}}
#
# Time encoding
#
select hex(column_create("t", "800:46:06.23434" AS time)) as hex,
column_json(column_create("t", "800:46:06.23434" AS time)) as json;
hex json
04010001000000070074649363B82003 [{"t":"800:46:06.234340"}]
04010001000000070074649363B82003 {"t":"800:46:06.234340"}
select hex(column_create(1, "800:46:06.23434" AS time)) as hex,
column_json(column_create(1, "800:46:06.23434" AS time)) as json;
hex json
000100010007649363B82003 [{"1":"800:46:06.234340"}]
000100010007649363B82003 {"1":"800:46:06.234340"}
select hex(column_create("t", "800:46:06" AS time)) as hex,
column_json(column_create("t", "800:46:06" AS time)) as json;
hex json
04010001000000070074860B32 [{"t":"800:46:06"}]
04010001000000070074860B32 {"t":"800:46:06"}
select hex(column_create(1, "800:46:06" AS time)) as hex,
column_json(column_create(1, "800:46:06" AS time)) as json;
hex json
000100010007000060B82003 [{"1":"800:46:06"}]
000100010007000060B82003 {"1":"800:46:06"}
select hex(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as hex,
column_json(column_create("t", "2012-12-21 10:46:06.23434" AS datetime)) as json;
hex json
0401000100000005007495B90F649363B80A00 [{"t":"2012-12-21 10:46:06.234340"}]
0401000100000005007495B90F649363B80A00 {"t":"2012-12-21 10:46:06.234340"}
select hex(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as hex,
column_json(column_create(1, "2012-12-21 10:46:06.23434" AS datetime)) as json;
hex json
00010001000595B90F649363B80A00 [{"1":"2012-12-21 10:46:06.234340"}]
00010001000595B90F649363B80A00 {"1":"2012-12-21 10:46:06.234340"}
select hex(column_create("t", "2012-12-21 10:46:06" AS datetime)) as hex,
column_json(column_create("t", "2012-12-21 10:46:06" AS datetime)) as json;
hex json
0401000100000005007495B90F86AB00 [{"t":"2012-12-21 10:46:06"}]
0401000100000005007495B90F86AB00 {"t":"2012-12-21 10:46:06"}
select hex(column_create(1, "2012-12-21 10:46:06" AS datetime)) as hex,
column_json(column_create(1, "2012-12-21 10:46:06" AS datetime)) as json;
hex json
00010001000595B90F000060B80A00 [{"1":"2012-12-21 10:46:06"}]
00010001000595B90F000060B80A00 {"1":"2012-12-21 10:46:06"}
......@@ -2368,7 +2368,7 @@ dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key,
/**
List not-null columns in the packed string (only numeric foemat)
List not-null columns in the packed string (only numeric format)
@param str The packed string
@param array_of_uint Where to put reference on created array
......@@ -2377,12 +2377,6 @@ dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key,
*/
enum enum_dyncol_func_result
dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint)
{
return mariadb_dyncol_list(str, array_of_uint);
}
enum enum_dyncol_func_result
mariadb_dyncol_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint)
{
DYN_HEADER header;
uchar *read;
......@@ -2417,6 +2411,48 @@ mariadb_dyncol_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint)
return ER_DYNCOL_OK;
}
/**
List not-null columns in the packed string (only numeric format)
@param str The packed string
@param array_of_uint Where to put reference on created array
@return ER_DYNCOL_* return code
*/
enum enum_dyncol_func_result
mariadb_dyncol_list(DYNAMIC_COLUMN *str, uint *count, uint **nums)
{
DYN_HEADER header;
uchar *read;
uint i;
enum enum_dyncol_func_result rc;
(*nums)= 0; /* In case of errors */
if (str->length == 0)
return ER_DYNCOL_OK; /* no columns */
if ((rc= init_read_hdr(&header, str)) < 0)
return rc;
if (header.format != dyncol_fmt_num)
return ER_DYNCOL_FORMAT;
if (header.entry_size * header.column_count + FIXED_HEADER_SIZE >
str->length)
return ER_DYNCOL_FORMAT;
if (!((*nums)= my_malloc(sizeof(uint) * header.column_count, MYF(0))))
return ER_DYNCOL_RESOURCE;
for (i= 0, read= header.header;
i < header.column_count;
i++, read+= header.entry_size)
{
(*nums)[i]= uint2korr(read);
}
(*count)= header.column_count;
return ER_DYNCOL_OK;
}
/**
List not-null columns in the packed string (any format)
......@@ -4058,7 +4094,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
rc= ER_DYNCOL_RESOURCE;
if (dynstr_append_mem(json, "[", 1))
if (dynstr_append_mem(json, "{", 1))
goto err;
for (i= 0, header.entry= header.header;
i < header.column_count;
......@@ -4080,8 +4116,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
rc= ER_DYNCOL_FORMAT;
goto err;
}
if ((rc= dynamic_column_get_value(&header, &val)) < 0 ||
dynstr_append_mem(json, "{", 1))
if ((rc= dynamic_column_get_value(&header, &val)) < 0)
goto err;
if (header.format == dyncol_fmt_num)
{
......@@ -4125,12 +4160,11 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json,
else
{
if ((rc= mariadb_dyncol_val_str(json, &val,
&my_charset_utf8_general_ci, '"')) < 0 ||
dynstr_append_mem(json, "}", 1))
&my_charset_utf8_general_ci, '"')) < 0)
goto err;
}
}
if (dynstr_append_mem(json, "]", 1))
if (dynstr_append_mem(json, "}", 1))
{
rc= ER_DYNCOL_RESOURCE;
goto err;
......
......@@ -58,7 +58,7 @@ public:
NOW_FUNC, TRIG_COND_FUNC,
SUSERVAR_FUNC, GUSERVAR_FUNC, COLLATE_FUNC,
EXTRACT_FUNC, CHAR_TYPECAST_FUNC, FUNC_SP, UDF_FUNC,
NEG_FUNC, GSYSVAR_FUNC, DYNCOL };
NEG_FUNC, GSYSVAR_FUNC, DYNCOL_FUNC };
enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL,
OPTIMIZE_EQUAL };
enum Type type() const { return FUNC_ITEM; }
......
......@@ -3837,7 +3837,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
if (type == DYN_COL_STRING &&
args[valpos]->type() == Item::FUNC_ITEM &&
((Item_func *)args[valpos])->functype() == DYNCOL)
((Item_func *)args[valpos])->functype() == DYNCOL_FUNC)
{
force_names= 1;
break;
......@@ -3904,7 +3904,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
}
if (type == DYN_COL_STRING &&
args[valpos]->type() == Item::FUNC_ITEM &&
((Item_func *)args[valpos])->functype() == DYNCOL)
((Item_func *)args[valpos])->functype() == DYNCOL_FUNC)
{
DBUG_ASSERT(names || force_names);
type= DYN_COL_DYNCOL;
......@@ -3988,7 +3988,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
case DYN_COL_DECIMAL:
if ((dres= args[valpos]->val_decimal(&dtmp)))
{
dynamic_column_prepare_decimal(&vals[i]);
mariadb_dyncol_prepare_decimal(&vals[i]);
DBUG_ASSERT(vals[i].x.decimal.value.len == dres->len);
vals[i].x.decimal.value.intg= dres->intg;
vals[i].x.decimal.value.frac= dres->frac;
......@@ -3998,7 +3998,7 @@ bool Item_func_dyncol_create::prepare_arguments(bool force_names_arg)
}
else
{
dynamic_column_prepare_decimal(&vals[i]); // just to be safe
mariadb_dyncol_prepare_decimal(&vals[i]); // just to be safe
DBUG_ASSERT(args[valpos]->null_value);
}
break;
......@@ -4055,7 +4055,7 @@ String *Item_func_dyncol_create::val_str(String *str)
/* Move result from DYNAMIC_COLUMN to str_value */
char *ptr;
size_t length, alloc_length;
mariadb_dyncol_reassociate(&col, &ptr, &length, &alloc_length);
dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str_value.reassociate(ptr, (uint32) length, (uint32) alloc_length,
&my_charset_bin);
res= &str_value;
......@@ -4197,7 +4197,7 @@ String *Item_func_dyncol_add::val_str(String *str)
/* Move result from DYNAMIC_COLUMN to str */
char *ptr;
size_t length, alloc_length;
mariadb_dyncol_reassociate(&col, &ptr, &length, &alloc_length);
dynstr_reassociate(&col, &ptr, &length, &alloc_length);
str->reassociate(ptr, (uint32) length, (uint32) alloc_length,
&my_charset_bin);
null_value= FALSE;
......
......@@ -1013,7 +1013,7 @@ public:
const char *func_name() const{ return "column_create"; }
String *val_str(String *);
virtual void print(String *str, enum_query_type query_type);
virtual enum Functype functype() const { return DYNCOL; }
virtual enum Functype functype() const { return DYNCOL_FUNC; }
};
......@@ -1051,11 +1051,9 @@ class Item_dyncol_get: public Item_str_func
public:
Item_dyncol_get(Item *str, Item *num)
:Item_str_func(str, num)
{
max_length= MAX_DYNAMIC_COLUMN_LENGTH;
}
{}
void fix_length_and_dec()
{ maybe_null= 1; }
{ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
/* Mark that collation can change between calls */
bool dynamic_result() { return 1; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment