Changeset: 449167582ca3 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=449167582ca3
Modified Files:
        sql/backends/monet5/sql_result.c
Branch: Protobuf
Log Message:

Wrapup, now experiments


Unterschiede (160 Zeilen):

diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1519,44 +1519,6 @@ static void appendjson(str* string, str 
        *jsonpos += toappendlen;
 }
 
-/* adapted from zlib/compress.c/compress2 */
-static int gzipstring (dest, destLen, source, sourceLen)
-    Bytef *dest;
-    uLongf *destLen;
-    const Bytef *source;
-    uLong sourceLen;
-{
-    z_stream stream;
-    int err;
-
-    stream.next_in = (Bytef *)source;
-    stream.avail_in = (uInt)sourceLen;
-#ifdef MAXSEG_64K
-    /* Check for source > 64K on 16-bit machine: */
-    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
-#endif
-    stream.next_out = dest;
-    stream.avail_out = (uInt)*destLen;
-    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
-
-    stream.zalloc = (alloc_func)0;
-    stream.zfree = (free_func)0;
-    stream.opaque = (voidpf)0;
-
-    err = deflateInit2 (&stream, Z_BEST_COMPRESSION, Z_DEFLATED, (15 | 16), 8, 
Z_DEFAULT_STRATEGY);
-    if (err != Z_OK) return err;
-
-    err = deflate(&stream, Z_FINISH);
-    if (err != Z_STREAM_END) {
-        deflateEnd(&stream);
-        return err == Z_OK ? Z_BUF_ERROR : err;
-    }
-    *destLen = stream.total_out;
-
-    err = deflateEnd(&stream);
-    return err;
-}
-
 int
 mvc_export_result(backend *b, stream *s, int res_id)
 {
@@ -1571,10 +1533,11 @@ mvc_export_result(backend *b, stream *s,
 
        size_t jsonstringpos = 0;
        size_t jsonstringlen = BUFSIZ;
-       size_t jsoncompressedlen = 0;
        str* jsonstring = malloc(1);
        *jsonstring = malloc(BUFSIZ);
-       Bytef * jsoncompressed;
+       char * jsoncompressed;
+       size_t jsoncompressedlen = 0;
+       int compressresult = TRUE;
 
        if (*jsonstring == NULL) {
                // TODO complain about malloc not working again
@@ -1669,14 +1632,14 @@ mvc_export_result(backend *b, stream *s,
 
                case EC_DEC:
                        assert(cbat->T->type==TYPE_lng);
-                       /*
-                       col->n_floatvalues = count;
-                       col->type = 
MAPI_REPLY__QUERY_RESULT__COLUMN__TYPE__FLOAT;
-                       col->floatvalues = malloc(sizeof(double) * count);
                        for (j = 0; j < BATcount(cbat); j++) {
-                               col->floatvalues[j] = ((long*) Tloc(cbat, 
BUNfirst(cbat)))[j];
+                               char* decstr;
+                               lng tl = ((lng*) Tloc(cbat, BUNfirst(cbat)))[j];
+                               decstr = decimal_to_str(tl, &c->type);
+                               appendjson(jsonstring, decstr, strlen(decstr), 
&jsonstringpos, &jsonstringlen);
+                               GDKfree(decstr);
+                               appendjson(jsonstring, ",", 1, &jsonstringpos, 
&jsonstringlen);
                        }
-                       */
                        jsonstringpos--;
                        break;
                case EC_BIT:
@@ -1694,6 +1657,20 @@ mvc_export_result(backend *b, stream *s,
                        jsonstringpos--;
                        break;
 
+               case EC_DATE:
+                       // TODO: where does this 21 come from?
+                       assert(cbat->T->type==21);
+                       for (j = 0; j < BATcount(cbat); j++) {
+                               int tl = ((int*) Tloc(cbat, BUNfirst(cbat)))[j];
+                               l = date_tostr(&convbuf, &bs, &tl);
+                               appendjson(jsonstring, "\"", 1, &jsonstringpos, 
&jsonstringlen);
+                               appendjson(jsonstring, convbuf, l, 
&jsonstringpos, &jsonstringlen);
+                               appendjson(jsonstring, "\"", 1, &jsonstringpos, 
&jsonstringlen);
+                               appendjson(jsonstring, ",", 1, &jsonstringpos, 
&jsonstringlen);
+                       }
+                       jsonstringpos--;
+                       break;
+
                default:
                        // TODO: implement other types
                        printf("XX: unknown type for col %s: %s (%d)\n", 
c->name,c->type.type->sqlname,cbat->T->type);
@@ -1702,11 +1679,12 @@ mvc_export_result(backend *b, stream *s,
                }
                appendjson(jsonstring, "]}", 2, &jsonstringpos, &jsonstringlen);
                if (i < t->nr_cols-1) {
-                       appendjson(jsonstring, ",", 1, &jsonstringpos, 
&jsonstringlen);
+                       appendjson(jsonstring, ",\n", 2, &jsonstringpos, 
&jsonstringlen);
                }
        }
 
        appendjson(jsonstring,"]}\n", 3, &jsonstringpos, &jsonstringlen);
+       mnstr_printf(s,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n");
 
        jsoncompressedlen = compressBound(jsonstringpos);
        jsoncompressed = malloc(jsoncompressedlen);
@@ -1715,24 +1693,31 @@ mvc_export_result(backend *b, stream *s,
        }
        // TODO: compress iff Accept-Encoding request header contains gzip
        // ZLIB to the rescue
-       if (gzipstring(jsoncompressed, &jsoncompressedlen, (const Bytef 
*)*jsonstring, jsonstringpos) != Z_OK) {
-               // TODO complain
+       if (gzipstring(jsoncompressed, &jsoncompressedlen, *jsonstring, 
jsonstringpos) != Z_OK) {
+               printf("Compression problem\n");
        }
-       mnstr_printf(s,"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n");
-       mnstr_printf(s,"Content-Encoding: gzip\r\nVary: Accept-Encoding\r\n");
-       mnstr_printf(s, "Content-Length: %lu\r\n\r\n", jsoncompressedlen);
+       if (compressresult) {
+               mnstr_printf(s,"Content-Encoding: gzip\r\nVary: 
Accept-Encoding\r\n");
+               mnstr_printf(s, "Content-Length: %lu\r\n\r\n", 
jsoncompressedlen);
+               mnstr_write(s, jsoncompressed, jsoncompressedlen, 1);
+               free(jsonstring);
+               free(jsoncompressed);
+       } else {
+               mnstr_printf(s, "Content-Length: %lu\r\n\r\n", jsonstringpos);
+               mnstr_write(s, *jsonstring, jsonstringpos, 1);
 
-       mnstr_write(s, jsoncompressed, jsoncompressedlen, 1);
+
+       }
+       printf("II: compressed result from %lu to %lu 
bytes\n",jsonstringpos,jsoncompressedlen);
+
+
        mnstr_flush(s);
        mnstr_close(s);
 
        s_time = end_timer_ms(&start)/1000.0;
-       printf("II: serialized query result %d cols, %lu rows, %lu bytes in %f 
s\n",t->nr_cols,count,rlen,s_time);
-       printf("II: compressed result from %lu to %lu 
bytes\n",jsonstringpos,jsoncompressedlen);
+       printf("II: serialized query result %d cols, %lu rows, %lu bytes in %f 
s\n",t->nr_cols,BATcount(order),rlen,s_time);
 
        free(*jsonstring);
-       free(jsonstring);
-       free(jsoncompressed);
 
        BBPunfix(order->batCacheid);
        if (clean)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to