Changeset: e51038a1dc27 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e51038a1dc27
Modified Files:
        monetdb5/modules/kernel/mmath.c
        monetdb5/modules/mal/txtsim.c
        sql/backends/monet5/sql.c
        sql/common/sql_types.c
        sql/jdbc/tests/Tests/Test_PSsomeamount.timeout
        sql/server/sql_atom.c
        sql/test/miscellaneous/Tests/simple_selects.sql
        sql/test/miscellaneous/Tests/simple_selects.stable.err
        sql/test/miscellaneous/Tests/simple_selects.stable.out
Branch: linear-hashing
Log Message:

Merged with Nov2019


diffs (truncated from 440 to 300 lines):

diff --git a/monetdb5/modules/kernel/mmath.c b/monetdb5/modules/kernel/mmath.c
--- a/monetdb5/modules/kernel/mmath.c
+++ b/monetdb5/modules/kernel/mmath.c
@@ -312,4 +312,3 @@ MATHpi(dbl *pi)
        *pi = 3.14159265358979323846;
        return MAL_SUCCEED;
 }
-
diff --git a/monetdb5/modules/mal/txtsim.c b/monetdb5/modules/mal/txtsim.c
--- a/monetdb5/modules/mal/txtsim.c
+++ b/monetdb5/modules/mal/txtsim.c
@@ -107,6 +107,11 @@ levenshtein_impl(int *result, str *S, st
        int sz;                 /* number of cells in matrix */
        int diag2 = 0, cost2 = 0;
 
+       if (strNil(*S) || strNil(*T)) {
+               *result = int_nil;
+               return MAL_SUCCEED;
+       }
+
        /* Step 1 */
        n = (int) strlen(s);    /* 64bit: assume strings are less than 2 GB */
        m = (int) strlen(t);
@@ -812,6 +817,11 @@ fstrcmp_impl(dbl *ret, str *S1, str *S2,
        static int *fdiag_buf;
        static size_t fdiag_max;
 
+       if (strNil(*S1) || strNil(*S2) || is_dbl_nil(*minimum)) {
+               *ret = dbl_nil;
+               return MAL_SUCCEED;
+       }
+
        /* set the info for each string.  */
        string[0].data = string1;
        string[0].data_length = (int) strlen(string1); /* 64bit: assume string 
not too long */
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3535,6 +3535,10 @@ str
 second_interval_2_daytime(daytime *res, const lng *s, const int *digits)
 {
        daytime d;
+       if (is_lng_nil(*s)) {
+               *res = daytime_nil;
+               return MAL_SUCCEED;
+       }
        d = daytime_add_usec(daytime_create(0, 0, 0, 0), *s * 1000);
        return daytime_2time_daytime(res, &d, digits);
 }
@@ -3793,32 +3797,38 @@ str
 month_interval(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        int *ret = getArgReference_int(stk, pci, 0);
-       int k = digits2ek(*getArgReference_int(stk, pci, 2));
-       int r;
+       int k = digits2ek(*getArgReference_int(stk, pci, 2)), r = 0, isnil = 0;
 
        (void) cntxt;
-       (void) mb;
+       *ret = int_nil;
        switch (getArgType(mb, pci, 1)) {
        case TYPE_bte:
                r = stk->stk[getArg(pci, 1)].val.btval;
+               isnil = (stk->stk[getArg(pci, 1)].val.btval == bte_nil);
                break;
        case TYPE_sht:
                r = stk->stk[getArg(pci, 1)].val.shval;
+               isnil = (stk->stk[getArg(pci, 1)].val.shval == sht_nil);
                break;
        case TYPE_int:
                r = stk->stk[getArg(pci, 1)].val.ival;
+               isnil = (stk->stk[getArg(pci, 1)].val.ival == int_nil);
                break;
        case TYPE_lng:
                r = (int) stk->stk[getArg(pci, 1)].val.lval;
+               isnil = (stk->stk[getArg(pci, 1)].val.lval == lng_nil);
                break;
 #ifdef HAVE_HGE
        case TYPE_hge:
                r = (int) stk->stk[getArg(pci, 1)].val.hval;
+               isnil = (stk->stk[getArg(pci, 1)].val.hval == hge_nil);
                break;
 #endif
        default:
                throw(ILLARG, "calc.month_interval", SQLSTATE(42000) "Illegal 
argument");
        }
+       if (isnil) 
+               return MAL_SUCCEED;
        switch (k) {
        case iyear:
                r *= 12;
@@ -4122,7 +4132,6 @@ sql_rt_credentials_wrap(Client cntxt, Ma
        return msg;
 }
 
-
 str
 sql_querylog_catalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
@@ -4432,7 +4441,6 @@ vacuum(Client cntxt, MalBlkPtr mb, MalSt
                return MAL_SUCCEED;
        }
 
-
        i = 0;
        bids[i] = 0;
        for (o = t->columns.set->h; o; o = o->next, i++) {
@@ -4602,7 +4610,6 @@ SQLdrop_hash(Client cntxt, MalBlkPtr mb,
        return MAL_SUCCEED;
 }
 
-
 /* after an update on the optimizer catalog, we have to change
  * the internal optimizer pipe line administration
  * The minimal and default pipelines may not be changed.
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -110,8 +110,8 @@ static int convert_matrix[EC_MAX][EC_MAX
 /* EC_BLOB */  { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
 /* EC_POS */   { 0, 0, 2, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
 /* EC_NUM */   { 0, 0, 2, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
-/* EC_MONTH*/   { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0 },
-/* EC_SEC*/     { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0 },
+/* EC_MONTH*/   { 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 },
+/* EC_SEC*/     { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
 /* EC_DEC */   { 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
 /* EC_FLT */   { 0, 0, 0, 1, 1, 0, 1, 1, 0, 3, 1, 1, 0, 0, 0, 0, 0 },
 /* EC_TIME */  { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
diff --git a/sql/jdbc/tests/Tests/Test_PSsomeamount.timeout 
b/sql/jdbc/tests/Tests/Test_PSsomeamount.timeout
--- a/sql/jdbc/tests/Tests/Test_PSsomeamount.timeout
+++ b/sql/jdbc/tests/Tests/Test_PSsomeamount.timeout
@@ -1,1 +1,1 @@
-80
+2
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -611,7 +611,7 @@ atom_num_digits( atom *a )
 #endif
        unsigned int inlen = 1;
 
-       switch(a->tpe.type->localtype) {
+       switch (a->tpe.type->localtype) {
        case TYPE_bte:
                v = a->data.val.btval;
                break;
@@ -659,7 +659,7 @@ atom_cast(sql_allocator *sa, atom *a, sq
                if (at->type->eclass == EC_NUM && tp->type->eclass == EC_NUM &&
                    at->type->localtype <= tp->type->localtype) {
                        /* cast numerics */
-                       switch( tp->type->localtype) {
+                       switch ( tp->type->localtype) {
                        case TYPE_bte:
                                if (at->type->localtype != TYPE_bte) 
                                        return 0;
@@ -725,7 +725,7 @@ atom_cast(sql_allocator *sa, atom *a, sq
                        lng mul = 1, div = 0, rnd = 0;
 #endif
                        /* cast numerics */
-                       switch( tp->type->localtype) {
+                       switch (tp->type->localtype) {
                        case TYPE_bte:
                                if (at->type->localtype != TYPE_bte) 
                                        return 0;
@@ -983,7 +983,7 @@ atom_cast(sql_allocator *sa, atom *a, sq
                        lng mul = 1;
 #endif
                        /* cast numerics */
-                       switch( tp->type->localtype) {
+                       switch (tp->type->localtype) {
                        case TYPE_bte:
                                if (at->type->localtype != TYPE_bte) 
                                        return 0;
@@ -1099,7 +1099,7 @@ atom_cast(sql_allocator *sa, atom *a, sq
                                size_t len = 0;
                                ssize_t res = 0;
                                /* cast decimals to doubles */
-                               switch( at->type->localtype) {
+                               switch (at->type->localtype) {
                                case TYPE_bte:
                                        dec = a->data.val.btval;
                                        break;
@@ -1168,9 +1168,11 @@ atom_cast(sql_allocator *sa, atom *a, sq
 }
 
 int 
-atom_neg( atom *a )
+atom_neg(atom *a)
 {
        ValRecord dst;
+       if (a->isnull)
+               return 0;
        VALempty(&dst);
        dst.vtype = a->data.vtype;
        if (VARcalcnegate(&dst, &a->data) != GDK_SUCCEED)
@@ -1201,9 +1203,8 @@ atom_add(atom *a1, atom *a2)
 {
        ValRecord dst;
 
-       if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != 
EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) 
|| a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != 
a2->tpe.type->localtype) {
+       if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != 
EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) 
|| a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != 
a2->tpe.type->localtype)
                return NULL;
-       }
        if (a1->tpe.type->localtype < a2->tpe.type->localtype ||
            (a1->tpe.type->localtype == a2->tpe.type->localtype &&
             a1->tpe.digits < a2->tpe.digits)) {
@@ -1228,9 +1229,8 @@ atom_sub(atom *a1, atom *a2)
 {
        ValRecord dst;
 
-       if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != 
EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) 
|| a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != 
a2->tpe.type->localtype) {
+       if ((!EC_COMPUTE(a1->tpe.type->eclass) && (a1->tpe.type->eclass != 
EC_DEC || a1->tpe.digits != a2->tpe.digits || a1->tpe.scale != a2->tpe.scale)) 
|| a1->tpe.digits < a2->tpe.digits || a1->tpe.type->localtype != 
a2->tpe.type->localtype)
                return NULL;
-       }
        if (a1->tpe.type->localtype < a2->tpe.type->localtype ||
            (a1->tpe.type->localtype == a2->tpe.type->localtype &&
             a1->tpe.digits < a2->tpe.digits))
@@ -1298,7 +1298,7 @@ atom_mul(atom *a1, atom *a2)
 }
 
 int
-atom_inc( atom *a )
+atom_inc(atom *a)
 {
        ValRecord dst;
 
@@ -1315,11 +1315,11 @@ atom_inc( atom *a )
 }
 
 int
-atom_is_zero( atom *a )
+atom_is_zero(atom *a)
 {
        if (a->isnull)
                return 0;
-       switch(a->tpe.type->localtype) {
+       switch (a->tpe.type->localtype) {
        case TYPE_bte:
                return a->data.val.btval == 0;
        case TYPE_sht:
@@ -1343,11 +1343,11 @@ atom_is_zero( atom *a )
 }
 
 int
-atom_is_true( atom *a )
+atom_is_true(atom *a)
 {
        if (a->isnull)
                return 0;
-       switch(a->tpe.type->localtype) {
+       switch (a->tpe.type->localtype) {
        case TYPE_bit:
                return a->data.val.btval != 0;
        case TYPE_bte:
@@ -1482,7 +1482,7 @@ atom_zero_value(sql_allocator *sa, sql_s
                        break;
        } //no support for strings and blobs zero value
 
-       if(ret != NULL) {
+       if (ret != NULL) {
                res = atom_create(sa);
                res->tpe = *tpe;
                res->isnull = 0;
diff --git a/sql/test/miscellaneous/Tests/simple_selects.sql 
b/sql/test/miscellaneous/Tests/simple_selects.sql
--- a/sql/test/miscellaneous/Tests/simple_selects.sql
+++ b/sql/test/miscellaneous/Tests/simple_selects.sql
@@ -14,6 +14,41 @@ select cast(sum(42) as bigint) having 42
 
 select 1 having false;
 select 1 having true;
+select -NULL;
+
+create table x (x interval second, y interval month);
+insert into x values (1, 1);
+select cast(x as date) from x; --error, cannot cast
+select cast(x as time) from x;
+select cast(x as timestamp) from x; --error, cannot cast
+select cast(y as date) from x; --error, cannot cast
+select cast(y as time) from x; --We throw error, but PostgreSQL doesn't
+select cast(y as timestamp) from x; --error, cannot cast
+insert into x values (null, null);
+select cast(x as date) from x; --error, cannot cast
+select cast(x as time) from x;
+select cast(x as timestamp) from x; --error, cannot cast
+select cast(y as date) from x; --error, cannot cast
+select cast(y as time) from x; --We throw error, but PostgreSQL doesn't
+select cast(y as timestamp) from x; --error, cannot cast
+drop table x;
+
+create table x (x time, y date, z timestamp);
+insert into x values (null, null, null);
+select cast(x as interval second) from x; --We throw error, but PostgreSQL 
doesn't
+select cast(x as interval month) from x; --We throw error, but PostgreSQL 
doesn't
+select cast(y as interval second) from x; --error, cannot cast
+select cast(y as interval month) from x; --error, cannot cast
+select cast(z as interval second) from x; --error, cannot cast
+select cast(z as interval month) from x; --error, cannot cast
+drop table x;
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to