Changeset: dff1ed3d3681 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dff1ed3d3681
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/test/merge-partitions/Tests/mergepart01.stable.err
        sql/test/merge-partitions/Tests/mergepart07.stable.err
        sql/test/merge-partitions/Tests/mergepart18.stable.err
        sql/test/merge-partitions/Tests/mergepart19.stable.err
Branch: default
Log Message:

Throw better error message.


diffs (191 lines):

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
@@ -74,68 +74,68 @@ table_has_updates(sql_trans *tr, sql_tab
 }
 
 static char *
-rel_check_tables(sql_table *nt, sql_table *nnt, const char* errtable)
+rel_check_tables(sql_table *nt, sql_table *nnt, const char *errtable)
 {
        node *n, *m, *nn, *mm;
 
        if (cs_size(&nt->columns) != cs_size(&nnt->columns))
-               throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s 
TABLE: to be added table doesn't match %s TABLE definition", errtable, 
errtable);
+               throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to 
be added table doesn't match %s definition", errtable, errtable);
        for (n = nt->columns.set->h, m = nnt->columns.set->h; n && m; n = 
n->next, m = m->next) {
                sql_column *nc = n->data;
                sql_column *mc = m->data;
 
                if (subtype_cmp(&nc->type, &mc->type) != 0)
-                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s TABLE: to be added table column type doesn't match %s TABLE definition", 
errtable, errtable);
+                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s: to be added table column type doesn't match %s definition", errtable, 
errtable);
                if(isRangePartitionTable(nt) || isListPartitionTable(nt)) {
                        if (nc->null != mc->null)
-                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table column NULL check doesn't match %s TABLE definition", errtable, errtable);
+                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
column NULL check doesn't match %s definition", errtable, errtable);
                        if ((!nc->def && mc->def) || (nc->def && !mc->def) || 
(nc->def && mc->def && strcmp(nc->def, mc->def) != 0))
-                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table column DEFAULT value doesn't match %s TABLE definition", errtable, 
errtable);
+                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
column DEFAULT value doesn't match %s definition", errtable, errtable);
                }
        }
        if(isNonPartitionedTable(nt)) {
                if (cs_size(&nt->idxs) != cs_size(&nnt->idxs))
-                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s TABLE: to be added table index doesn't match %s TABLE definition", errtable, 
errtable);
+                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s: to be added table index doesn't match %s definition", errtable, errtable);
                if (cs_size(&nt->idxs))
                        for (n = nt->idxs.set->h, m = nnt->idxs.set->h; n && m; 
n = n->next, m = m->next) {
                                sql_idx *ni = n->data;
                                sql_idx *mi = m->data;
 
                                if (ni->type != mi->type)
-                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table index type doesn't match %s TABLE definition", errtable, errtable);
+                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
index type doesn't match %s definition", errtable, errtable);
                        }
        } else { //for partitioned tables we allow indexes but the key set must 
be exactly the same
                if (cs_size(&nt->keys) != cs_size(&nnt->keys))
-                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s TABLE: to be added table key doesn't match %s TABLE definition", errtable, 
errtable);
+                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s: to be added table key doesn't match %s definition", errtable, errtable);
                if (cs_size(&nt->keys))
                        for (n = nt->keys.set->h, m = nnt->keys.set->h; n && m; 
n = n->next, m = m->next) {
                                sql_key *ni = n->data;
                                sql_key *mi = m->data;
 
                                if (ni->type != mi->type)
-                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table key type doesn't match %s TABLE definition", errtable, errtable);
+                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
key type doesn't match %s definition", errtable, errtable);
                                if (list_length(ni->columns) != 
list_length(mi->columns))
-                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table key type doesn't match %s TABLE definition", errtable, errtable);
+                                       
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
key type doesn't match %s definition", errtable, errtable);
                                for (nn = ni->columns->h, mm = mi->columns->h; 
nn && mm; nn = nn->next, mm = mm->next) {
                                        sql_kc *nni = nn->data;
                                        sql_kc *mmi = mm->data;
 
                                        if (nni->c->colnr != mmi->c->colnr)
-                                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s TABLE: to be added 
table key's columns doesn't match %s TABLE definition", errtable, errtable);
+                                               
throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table 
key's columns doesn't match %s definition", errtable, errtable);
                                }
                        }
        }
 
        for(sql_table *up = nt->p ; up ; up = up->p) {
                if(!strcmp(up->s->base.name, nnt->s->base.name) && 
!strcmp(up->base.name, nnt->base.name))
-                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s TABLE: to be added table is a parent of the %s TABLE", errtable, errtable);
+                       throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER 
%s: to be added table is a parent of the %s", errtable, errtable);
        }
        return MAL_SUCCEED;
 }
 
 static char*
 validate_alter_table_add_table(mvc *sql, char* call, char *msname, char 
*mtname, char *psname, char *ptname,
-                                                          sql_table **mt, 
sql_table **pt, int update, const char* errtable)
+                                                          sql_table **mt, 
sql_table **pt, int update)
 {
        sql_schema *ms = mvc_bind_schema(sql, msname), *ps = 
mvc_bind_schema(sql, psname);
        sql_table *rmt = NULL, *rpt = NULL;
@@ -151,11 +151,12 @@ validate_alter_table_add_table(mvc *sql,
        if (rmt && rpt) {
                char *msg;
                node *n = cs_find_id(&rmt->members, rpt->base.id);
+               const char *errtable = TABLE_TYPE_DESCRIPTION(rmt->type, 
rmt->properties);
 
                if (n && !update)
-                       throw(SQL,call,SQLSTATE(42S02) "ALTER TABLE: table 
'%s.%s' is already part of the MERGE TABLE '%s.%s'", psname, ptname, msname, 
mtname);
-               if(!n && update)
-                       throw(SQL,call,SQLSTATE(42S02) "ALTER TABLE: table 
'%s.%s' isn't part of the MERGE TABLE '%s.%s'", psname, ptname, msname, mtname);
+                       throw(SQL,call,SQLSTATE(42S02) "ALTER TABLE: table 
'%s.%s' is already part of the %s '%s.%s'", psname, ptname, errtable, msname, 
mtname);
+               if (!n && update)
+                       throw(SQL,call,SQLSTATE(42S02) "ALTER TABLE: table 
'%s.%s' isn't part of the %s '%s.%s'", psname, ptname, errtable, msname, 
mtname);
                if ((msg = rel_check_tables(rmt, rpt, errtable)) != NULL)
                        return msg;
                return MAL_SUCCEED;
@@ -170,7 +171,7 @@ static char *
 alter_table_add_table(mvc *sql, char *msname, char *mtname, char *psname, char 
*ptname)
 {
        sql_table *mt = NULL, *pt = NULL;
-       str msg = validate_alter_table_add_table(sql, 
"sql.alter_table_add_table", msname, mtname, psname, ptname, &mt, &pt, 0, 
"MERGE");
+       str msg = validate_alter_table_add_table(sql, 
"sql.alter_table_add_table", msname, mtname, psname, ptname, &mt, &pt, 0);
 
        if(msg == MAL_SUCCEED)
                sql_trans_add_table(sql->session->tr, mt, pt);
@@ -191,7 +192,7 @@ alter_table_add_range_partition(mvc *sql
        sql_subtype tpe;
 
        if((msg = validate_alter_table_add_table(sql, 
"sql.alter_table_add_range_partition", msname, mtname, psname, ptname,
-                                                                               
         &mt, &pt, update, "RANGE PARTITION"))) {
+                                                                               
         &mt, &pt, update))) {
                return msg;
        } else if(!isRangePartitionTable(mt)) {
                msg = 
createException(SQL,"sql.alter_table_add_range_partition",SQLSTATE(42000)
@@ -292,7 +293,7 @@ alter_table_add_value_partition(mvc *sql
        sql_subtype tpe;
 
        if((msg = validate_alter_table_add_table(sql, 
"sql.alter_table_add_value_partition", msname, mtname, psname, ptname,
-                                                                               
         &mt, &pt, update, "LIST PARTITION"))) {
+                                                                               
         &mt, &pt, update))) {
                return msg;
        } else if(!isListPartitionTable(mt)) {
                msg = 
createException(SQL,"sql.alter_table_add_value_partition",SQLSTATE(42000)
diff --git a/sql/test/merge-partitions/Tests/mergepart01.stable.err 
b/sql/test/merge-partitions/Tests/mergepart01.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart01.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart01.stable.err
@@ -31,7 +31,7 @@ stderr of test 'mergepart01` in director
 
 MAPI  = (monetdb) /var/tmp/mtest-24782/.s.monetdb.30770
 QUERY = ALTER TABLE testme ADD TABLE subtable1 AS PARTITION BETWEEN 5 AND 10; 
--error
-ERROR = !ALTER TABLE: table 'sys.subtable1' is already part of the MERGE TABLE 
'sys.testme'
+ERROR = !ALTER TABLE: table 'sys.subtable1' is already part of the RANGE 
PARTITION TABLE 'sys.testme'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-24782/.s.monetdb.30770
 QUERY = ALTER TABLE testme ADD TABLE wrongtable AS PARTITION BETWEEN 5 AND 6; 
--error
diff --git a/sql/test/merge-partitions/Tests/mergepart07.stable.err 
b/sql/test/merge-partitions/Tests/mergepart07.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart07.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart07.stable.err
@@ -53,19 +53,19 @@ ERROR = !ALTER TABLE: there are values i
 CODE  = M0M29
 MAPI  = (monetdb) /var/tmp/mtest-14313/.s.monetdb.34865
 QUERY = ALTER TABLE anothertest ADD TABLE othersub1 AS PARTITION BETWEEN NULL 
AND 'nono'; --error
-ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the MERGE TABLE 
'sys.anothertest'
+ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the RANGE 
PARTITION TABLE 'sys.anothertest'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-20774/.s.monetdb.31597
 QUERY = ALTER TABLE anothertest ADD TABLE othersub1 AS PARTITION BETWEEN 
'nono' AND NULL; --error
-ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the MERGE TABLE 
'sys.anothertest'
+ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the RANGE 
PARTITION TABLE 'sys.anothertest'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-20774/.s.monetdb.31597
 QUERY = ALTER TABLE anothertest ADD TABLE othersub1 AS PARTITION BETWEEN NULL 
AND NULL; --error
-ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the MERGE TABLE 
'sys.anothertest'
+ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the RANGE 
PARTITION TABLE 'sys.anothertest'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-20774/.s.monetdb.31597
 QUERY = ALTER TABLE anothertest ADD TABLE othersub1 AS PARTITION BETWEEN 
'nono' AND 'wrong' WITH NULL; --error
-ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the MERGE TABLE 
'sys.anothertest'
+ERROR = !ALTER TABLE: table 'sys.othersub1' is already part of the RANGE 
PARTITION TABLE 'sys.anothertest'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-2104/.s.monetdb.37654
 QUERY = ALTER TABLE anothertest ADD TABLE othersub1 AS PARTITION BETWEEN 'a' 
AND 'string'; --error
diff --git a/sql/test/merge-partitions/Tests/mergepart18.stable.err 
b/sql/test/merge-partitions/Tests/mergepart18.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart18.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart18.stable.err
@@ -30,7 +30,7 @@ stderr of test 'mergepart18` in director
 
 MAPI  = (monetdb) /var/tmp/mtest-9747/.s.monetdb.32333
 QUERY = ALTER TABLE updateme SET TABLE subt1 AS PARTITION BETWEEN '1' AND 
'100'; --error
-ERROR = !ALTER TABLE: table 'sys.subt1' isn't part of the MERGE TABLE 
'sys.updateme'
+ERROR = !ALTER TABLE: table 'sys.subt1' isn't part of the RANGE PARTITION 
TABLE 'sys.updateme'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-9747/.s.monetdb.32333
 QUERY = ALTER TABLE updateme SET TABLE subt1 AS PARTITION BETWEEN '-100' AND 
'0'; --error
diff --git a/sql/test/merge-partitions/Tests/mergepart19.stable.err 
b/sql/test/merge-partitions/Tests/mergepart19.stable.err
--- a/sql/test/merge-partitions/Tests/mergepart19.stable.err
+++ b/sql/test/merge-partitions/Tests/mergepart19.stable.err
@@ -30,7 +30,7 @@ stderr of test 'mergepart19` in director
 
 MAPI  = (monetdb) /var/tmp/mtest-15034/.s.monetdb.31422
 QUERY = ALTER TABLE testme SET TABLE subt1 AS PARTITION IN ('21', '22', '23'); 
--error
-ERROR = !ALTER TABLE: table 'sys.subt1' isn't part of the MERGE TABLE 
'sys.testme'
+ERROR = !ALTER TABLE: table 'sys.subt1' isn't part of the LIST PARTITION TABLE 
'sys.testme'
 CODE  = 42S02
 MAPI  = (monetdb) /var/tmp/mtest-15034/.s.monetdb.31422
 QUERY = ALTER TABLE testme SET TABLE subt1 AS PARTITION IN ('44', '45', '46'); 
--error
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to