Changeset: 79531404c371 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/79531404c371
Modified Files:
clients/mapiclient/dump.c
gdk/gdk_string.c
sql/backends/monet5/sql_cat.c
sql/storage/bat/bat_storage.c
sql/storage/bat/bat_storage.h
sql/storage/sql_storage.h
sql/storage/store.c
Branch: ustr
Log Message:
Fixed dump for ustr bats; implemented storage_type (ST_USTR) value.
diffs (231 lines):
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -1933,7 +1933,7 @@ bailout:
}
static int
-dump_table_storage(Mapi mid, const char *schema, const char *tname, stream
*sqlf)
+dump_table_storage(Mapi mid, const char *schema, const char *tname, stream
*sqlf, bool after)
{
char *query = NULL;
size_t maxquerylen;
@@ -1951,10 +1951,10 @@ dump_table_storage(Mapi mid, const char
snprintf(query, maxquerylen,
"SELECT name, storage FROM sys._columns "
- "WHERE storage IS NOT NULL "
+ "WHERE storage %s LIKE 'USTR' "
"AND table_id = (SELECT id FROM sys._tables WHERE name
= '%s' "
"AND schema_id = (SELECT id FROM sys.schemas WHERE
name = '%s'))",
- t, s);
+ after ? "NOT" : "", t, s);
if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
goto bailout;
while ((mapi_fetch_row(hdl)) != 0) {
@@ -1999,27 +1999,29 @@ dump_table_access(Mapi mid, const char *
snprintf(query, maxquerylen,
"SELECT t.access FROM sys._tables t, sys.schemas s "
- "WHERE s.name = '%s' AND t.schema_id = s.id AND t.name
= '%s'",
+ "WHERE s.name = '%s' AND t.schema_id = s.id AND t.name
= '%s' AND t.access in (1, 2)",
s, t);
if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid))
goto bailout;
- if (mapi_rows_affected(hdl) != 1) {
- if (mapi_rows_affected(hdl) == 0)
- fprintf(stderr, "table %s.%s does not exist\n", schema,
tname);
- else
- fprintf(stderr, "table %s.%s is not unique\n", schema,
tname);
+ switch (mapi_rows_affected(hdl)) {
+ case 0:
+ break;
+ case 1:
+ while ((mapi_fetch_row(hdl)) != 0) {
+ const char *access = mapi_fetch_field(hdl, 0);
+ if (access && (*access == '1' || *access == '2')) {
+ mnstr_printf(sqlf, "ALTER TABLE ");
+ dquoted_print(sqlf, schema, ".");
+ dquoted_print(sqlf, tname, " ");
+ mnstr_printf(sqlf, "SET %s ONLY;\n", *access ==
'1' ? "READ" : "INSERT");
+ }
+ }
+ rc = 0; /* success */
+ break;
+ default:
+ fprintf(stderr, "table %s.%s is not unique\n", schema, tname);
goto bailout;
}
- while ((mapi_fetch_row(hdl)) != 0) {
- const char *access = mapi_fetch_field(hdl, 0);
- if (access && (*access == '1' || *access == '2')) {
- mnstr_printf(sqlf, "ALTER TABLE ");
- dquoted_print(sqlf, schema, ".");
- dquoted_print(sqlf, tname, " ");
- mnstr_printf(sqlf, "SET %s ONLY;\n", *access == '1' ?
"READ" : "INSERT");
- }
- }
- rc = 0; /* success */
bailout:
free(query);
free(s);
@@ -2204,11 +2206,13 @@ dump_table(Mapi mid, const char *schema,
rc = describe_table(mid, schema, tname, sqlf, foreign, databaseDump);
if (rc == 0)
- rc = dump_table_storage(mid, schema, tname, sqlf);
+ rc = dump_table_storage(mid, schema, tname, sqlf, false);
if (rc == 0 && !describe)
rc = dump_table_data(mid, schema, tname, sqlf, ddir, ext,
useInserts, noescape);
if (rc == 0)
rc = dump_table_access(mid, schema, tname, sqlf);
+ if (rc == 0)
+ rc = dump_table_storage(mid, schema, tname, sqlf, true);
if (rc == 0 && !databaseDump)
rc = dump_table_defaults(mid, schema, tname, sqlf);
doreturn:
diff --git a/gdk/gdk_string.c b/gdk/gdk_string.c
--- a/gdk/gdk_string.c
+++ b/gdk/gdk_string.c
@@ -308,6 +308,11 @@ BATconvert2ustr(BAT *b)
GDKerror("BAT must be empty to convert to ustr\n");
return GDK_FAIL;
}
+ if (b->ttype != TYPE_str) {
+ MT_lock_unset(&b->theaplock);
+ GDKerror("BAT must be a string BAT to convert to ustr\n");
+ return GDK_FAIL;
+ }
if (b->batRole != PERSISTENT) {
MT_lock_unset(&b->theaplock);
GDKerror("BAT must be in persistent farm to convert to ustr\n");
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -1252,16 +1252,18 @@ alter_table(Client cntxt, mvc *sql, char
}
if ((c->storage_type || nc->storage_type) && (!c->storage_type
|| !nc->storage_type || strcmp(c->storage_type, nc->storage_type) != 0)) {
- if (c->t->access == TABLE_WRITABLE)
+ if (c->t->access == TABLE_WRITABLE && (c->storage_type
== NULL || strcmp(c->storage_type, "USTR") != 0))
throw(SQL,"sql.alter_table", SQLSTATE(40002)
"ALTER TABLE: SET STORAGE for column %s.%s only allowed on READ or INSERT ONLY
tables", c->t->base.name, c->base.name);
switch (mvc_storage(sql, nc, c->storage_type)) {
- case -1:
- throw(SQL,"sql.alter_table",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- case -2:
- case -3:
- throw(SQL,"sql.alter_table",
SQLSTATE(42000) "ALTER TABLE: SET STORAGE transaction conflict detected");
- default:
- break;
+ case -1:
+ throw(SQL,"sql.alter_table", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ case -2:
+ case -3:
+ throw(SQL,"sql.alter_table", SQLSTATE(42000)
"ALTER TABLE: SET STORAGE transaction conflict detected");
+ case -4:
+ throw(SQL, "sql.alter_table", SQLSTATE(42000)
"ALTER TABLE: SET STORAGE error converting column");
+ default:
+ break;
}
}
if (subtype_cmp(&c->type, &nc->type) != 0) {
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2342,7 +2342,7 @@ append_col(sql_trans *tr, sql_column *c,
if ((delta = bind_col_data(tr, c, NULL)) == NULL)
return LOG_ERR;
- assert(delta->cs.st == ST_DEFAULT || delta->cs.st == ST_DICT ||
delta->cs.st == ST_FOR);
+ assert(delta->cs.st == ST_DEFAULT || delta->cs.st == ST_DICT ||
delta->cs.st == ST_FOR || delta->cs.st == ST_USTR);
odelta = delta;
if ((res = append_col_execute(tr, &delta, c, offset, offsets, data,
cnt, isbat, tpe, c->storage_type)) != LOG_OK)
@@ -2731,7 +2731,7 @@ set_stats_col(sql_trans *tr, sql_column
lock_column(tr->store, c);
if (unique_est) {
sql_delta *d;
- if ((d = ATOMIC_PTR_GET(&c->data)) && d->cs.st == ST_DEFAULT) {
+ if ((d = ATOMIC_PTR_GET(&c->data)) && (d->cs.st == ST_DEFAULT
|| d->cs.st == ST_USTR)) {
BAT *b;
if ((b = bind_col_no_view(tr, c, RDONLY))) {
MT_lock_set(&b->theaplock);
@@ -2889,6 +2889,9 @@ double_elim_col(sql_trans *tr, sql_colum
de = 1;
else if (b && b->ttype == TYPE_sht)
de = 2;
+ } else if (d->cs.st == ST_USTR) {
+ BAT *b = bind_col(tr, col, QUICK);
+ de = b->twidth;
}
} else if (col && ATOMstorage(col->type.type->localtype) == TYPE_str &&
ATOMIC_PTR_GET(&col->data)) {
BAT *b = bind_col(tr, col, QUICK);
@@ -2941,7 +2944,7 @@ col_stats(sql_trans *tr, sql_column *c,
ok |= 2;
}
if (d->cs.ucnt == 0) {
- if (d->cs.st == ST_DEFAULT) {
+ if (d->cs.st == ST_DEFAULT || d->cs.st ==
ST_USTR) {
*unique = bi.key;
*unique_est = bi.unique_est;
if (*unique_est == 0)
@@ -3193,6 +3196,8 @@ create_col(sql_trans *tr, sql_column *c)
bat->cs.st = ST_DICT;
} else if (strncmp(c->storage_type, "FOR", 3) == 0) {
bat->cs.st = ST_FOR;
+ } else if (strcmp(c->storage_type, "USTR") == 0) {
+ bat->cs.st = ST_USTR;
}
}
return ok;
@@ -3804,7 +3809,7 @@ clear_cs(sql_trans *tr, column_storage *
BUN sz = 0;
(void)tr;
- assert(cs->st == ST_DEFAULT || cs->st == ST_DICT || cs->st == ST_FOR);
+ assert(cs->st == ST_DEFAULT || cs->st == ST_DICT || cs->st == ST_FOR ||
cs->st == ST_USTR);
if (cs->bid && renew) {
b = quick_descriptor(cs->bid);
if (b) {
diff --git a/sql/storage/bat/bat_storage.h b/sql/storage/bat/bat_storage.h
--- a/sql/storage/bat/bat_storage.h
+++ b/sql/storage/bat/bat_storage.h
@@ -20,7 +20,7 @@ typedef struct column_storage {
int ebid; /* extra bid */
int uibid; /* bat with positions of updates */
int uvbid; /* bat with values of updates */
- storage_type st; /* ST_DEFAULT, ST_DICT, ST_FOR */
+ storage_type st; /* ST_DEFAULT, ST_DICT, ST_FOR, ST_USTR */
bool cleared;
bool merged; /* only merge changes once */
size_t ucnt; /* number of updates */
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -199,6 +199,7 @@ typedef enum storage_type {
ST_DEFAULT = 0,
ST_DICT,
ST_FOR,
+ ST_USTR,
} storage_type;
typedef int (*col_compress_fptr) (sql_trans *tr, sql_column *c, storage_type
st, BAT *offsets, BAT *vals);
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -6775,6 +6775,15 @@ sql_trans_alter_storage(sql_trans *tr, s
if (is_oid_nil(rid))
return -1;
+ if (strcmp(p, "USTR") == 0) {
+ sql_delta *d = ATOMIC_PTR_GET(&col->data);
+ BAT *b = BATdescriptor(d->cs.bid);
+ if (b == NULL || BATconvert2ustr(b) != GDK_SUCCEED) {
+ BBPreclaim(b);
+ return -4;
+ }
+ BBPreclaim(b);
+ }
if ((res = store->table_api.column_update_value(tr, col_dfs,
rid, p)))
return res;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]