Changeset: c70d5a791521 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c70d5a791521
Modified Files:
        monetdb5/modules/atoms/json.c
        sql/test/json/Tests/aggregate00.sql
        sql/test/json/Tests/aggregate00.stable.out
        sql/test/json/Tests/aggregate01.sql
        sql/test/json/Tests/aggregate01.stable.out
Branch: default
Log Message:

add null handling for double columns and add tests


diffs (217 lines):

diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c
--- a/monetdb5/modules/atoms/json.c
+++ b/monetdb5/modules/atoms/json.c
@@ -1825,12 +1825,16 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, 
                                v = (const char *) BUNtail(bi, BUNfirst(b) + 
(map ? (BUN) map[p] : p + mapoff));
                                break;
                        case TYPE_dbl:
-                               val = (const double *) BUNtail(bi, BUNfirst(b) 
+ (map ? (BUN) map[p] : p + mapoff));
-                               snprintf(temp, sizeof(temp), "%f", *val);
-                               v = (const char *)temp;
+                               val = (const double *) BUNtail(bi, BUNfirst(b) 
+ (map ? (BUN) map[p] : p + mapoff));
+                               if (*val != dbl_nil) {
+                                       snprintf(temp, sizeof(temp), "%f", 
*val);
+                                       v = (const char *)temp;
+                               } else {
+                                       v =  NULL;
+                               } 
                                break;
                        }
-                       if (strNil(v)) {
+                       if (!v||strNil(v)) {
                                if (skip_nils)
                                        continue;
                                strncpy(buf, str_nil, buflen);
diff --git a/sql/test/json/Tests/aggregate00.sql 
b/sql/test/json/Tests/aggregate00.sql
--- a/sql/test/json/Tests/aggregate00.sql
+++ b/sql/test/json/Tests/aggregate00.sql
@@ -1,21 +1,37 @@
-create table aggrtest ( col1 varchar(10), col2 integer );
+create table aggrtest00 ( col1 varchar(10), col2 integer );
 
-select json.tojsonarray(col1) from aggrtest;
+select json.tojsonarray(col1) from aggrtest00;
 
-insert into aggrtest values ('hallo', 1);
+insert into aggrtest00 values ('hallo', 1);
 
-select json.tojsonarray(col1) from aggrtest;
+select json.tojsonarray(col1) from aggrtest00;
 
-insert into aggrtest values ('world', 1);
+insert into aggrtest00 values ('world', 1);
 
-select json.tojsonarray(col1) from aggrtest;
+select json.tojsonarray(col1) from aggrtest00;
 
-select json.tojsonarray(col1) from aggrtest group by col2;
+select json.tojsonarray(col1) from aggrtest00 group by col2;
 
-insert into aggrtest values ('foobar', 2);
+insert into aggrtest00 values ('foobar', 2);
 
-select json.tojsonarray(col1) from aggrtest;
+select json.tojsonarray(col1) from aggrtest00;
 
-select json.tojsonarray(col1) from aggrtest group by col2;
+select json.tojsonarray(col1) from aggrtest00 group by col2;
 
-drop table aggrtest;
+delete from aggrtest00;
+
+insert into aggrtest00 values (NULL, 1);
+
+select json.tojsonarray(col1) from aggrtest00;
+
+insert into aggrtest00 values ('hello', 1);
+
+select json.tojsonarray(col1) from aggrtest00;
+
+insert into aggrtest00 values ('world', 2);
+
+select json.tojsonarray(col1) from aggrtest00;
+
+select json.tojsonarray(col1) from aggrtest00 group by col2;
+
+drop table aggrtest00;
diff --git a/sql/test/json/Tests/aggregate00.stable.out 
b/sql/test/json/Tests/aggregate00.stable.out
--- a/sql/test/json/Tests/aggregate00.stable.out
+++ b/sql/test/json/Tests/aggregate00.stable.out
@@ -94,6 +94,40 @@ Ready.
 % 20 # length
 [ "[ \"hallo\", \"world\" ]"   ]
 [ "[ \"foobar\" ]"     ]
+#delete from aggrtest00;
+[ 3    ]
+#insert into aggrtest00 values (NULL, 1);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest00;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 0 # length
+[ NULL ]
+#insert into aggrtest00 values ('hello', 1);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest00;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 11 # length
+[ "[ \"hello\" ]"      ]
+#insert into aggrtest00 values ('world', 2);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest00;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 20 # length
+[ "[ \"hello\", \"world\" ]"   ]
+#select json.tojsonarray(col1) from aggrtest00 group by col2;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 11 # length
+[ "[ \"hello\" ]"      ]
+[ "[ \"world\" ]"      ]
+#drop table aggrtest00;
 
 # 15:08:41 >  
 # 15:08:41 >  "Done."
diff --git a/sql/test/json/Tests/aggregate01.sql 
b/sql/test/json/Tests/aggregate01.sql
--- a/sql/test/json/Tests/aggregate01.sql
+++ b/sql/test/json/Tests/aggregate01.sql
@@ -1,21 +1,37 @@
-create table aggrtest1 ( col1 double, col2 integer );
+create table aggrtest01 ( col1 double, col2 integer );
 
-select json.tojsonarray(col1) from aggrtest1;
+select json.tojsonarray(col1) from aggrtest01;
 
-insert into aggrtest1 values (0.1234, 1);
+insert into aggrtest01 values (0.1234, 1);
 
-select json.tojsonarray(col1) from aggrtest1;
+select json.tojsonarray(col1) from aggrtest01;
 
-insert into aggrtest1 values (5.6789, 1);
+insert into aggrtest01 values (5.6789, 1);
 
-select json.tojsonarray(col1) from aggrtest1;
+select json.tojsonarray(col1) from aggrtest01;
 
-select json.tojsonarray(col1) from aggrtest1 group by col2;
+select json.tojsonarray(col1) from aggrtest01 group by col2;
 
-insert into aggrtest1 values (0.516273849, 2);
+insert into aggrtest01 values (0.516273849, 2);
 
-select json.tojsonarray(col1) from aggrtest1;
+select json.tojsonarray(col1) from aggrtest01;
 
-select json.tojsonarray(col1) from aggrtest1 group by col2;
+select json.tojsonarray(col1) from aggrtest01 group by col2;
 
-drop table aggrtest1;
+delete from aggrtest01;
+
+insert into aggrtest01 values (NULL, 1);
+
+select json.tojsonarray(col1) from aggrtest01;
+
+insert into aggrtest01 values (0.1234, 1);
+
+select json.tojsonarray(col1) from aggrtest01;
+
+insert into aggrtest01 values (0.516273849, 2);
+
+select json.tojsonarray(col1) from aggrtest01;
+
+select json.tojsonarray(col1) from aggrtest01 group by col2;
+
+drop table aggrtest01;
diff --git a/sql/test/json/Tests/aggregate01.stable.out 
b/sql/test/json/Tests/aggregate01.stable.out
--- a/sql/test/json/Tests/aggregate01.stable.out
+++ b/sql/test/json/Tests/aggregate01.stable.out
@@ -95,7 +95,40 @@ Ready.
 % 22 # length
 [ "[ 0.123400, 5.678900 ]"     ]
 [ "[ 0.516274 ]"       ]
-#drop table aggrtest1;
+#delete from aggrtest01;
+[ 3    ]
+#insert into aggrtest01 values (NULL, 1);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest01;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 0 # length
+[ NULL ]
+#insert into aggrtest01 values (0.1234, 1);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest01;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 12 # length
+[ "[ 0.123400 ]"       ]
+#insert into aggrtest01 values (0.516273849, 2);
+[ 1    ]
+#select json.tojsonarray(col1) from aggrtest01;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 22 # length
+[ "[ 0.123400, 0.516274 ]"     ]
+#select json.tojsonarray(col1) from aggrtest01 group by col2;
+% sys.L1 # table_name
+% L1 # name
+% clob # type
+% 12 # length
+[ "[ 0.123400 ]"       ]
+[ "[ 0.516274 ]"       ]
+#drop table aggrtest01;
 
 # 12:36:43 >  
 # 12:36:43 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to