Changeset: fddf938a1e40 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fddf938a1e40
Modified Files:
        sql/backends/monet5/vaults/parquet/offset_string_read_chunk.h
        sql/backends/monet5/vaults/parquet/pqc_dict_lookup_var.h
        sql/backends/monet5/vaults/parquet/pqc_filemetadata.c
        sql/backends/monet5/vaults/parquet/pqc_reader.c
        sql/backends/monet5/vaults/parquet/pqc_thrift.c
Branch: pp_hashjoin
Log Message:

Windows build.


diffs (truncated from 577 to 300 lines):

diff --git a/sql/backends/monet5/vaults/parquet/offset_string_read_chunk.h 
b/sql/backends/monet5/vaults/parquet/offset_string_read_chunk.h
--- a/sql/backends/monet5/vaults/parquet/offset_string_read_chunk.h
+++ b/sql/backends/monet5/vaults/parquet/offset_string_read_chunk.h
@@ -8,7 +8,7 @@
  * For copyright information, see the file debian/copyright.
  */
 
-static int
+static int64_t
 offset_string_read_chunk( pqc_reader_t *r, pqc_creader_t *cr, T *output, char 
*voutput, int64_t nrows, int pos, int offset)
 {
        T *rc = output;
@@ -31,7 +31,8 @@ offset_string_read_chunk( pqc_reader_t *
                data += sizeof(int);
                memcpy(buf, data, len);
                buf[len] = 0;
-               rc[i] = offset + (buf-voutput);
+               assert((int64_t) (offset + (buf-voutput)) < (INT64_C(1) << (8 * 
sizeof(T))));
+               rc[i] = (T) (offset + (buf-voutput));
                buf += len+1;
                data += len;
        }
diff --git a/sql/backends/monet5/vaults/parquet/pqc_dict_lookup_var.h 
b/sql/backends/monet5/vaults/parquet/pqc_dict_lookup_var.h
--- a/sql/backends/monet5/vaults/parquet/pqc_dict_lookup_var.h
+++ b/sql/backends/monet5/vaults/parquet/pqc_dict_lookup_var.h
@@ -86,7 +86,8 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                                                idx |= (v << (nr_bits-sh))&mask;
                                        }
                                        assert(idx < cr->dict_num_values);
-                                       dst[i] = ((int64_t*)cr->dict)[idx];
+                                       assert(((int64_t*)cr->dict)[idx] < 
((int64_t) 1 << 8*sizeof(T)));
+                                       dst[i] = (T) ((int64_t*)cr->dict)[idx];
                                }
                                if ((cr->remaining - j) == 0)
                                        pos += (sh)/8;
@@ -102,9 +103,8 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                        len>>=1;
                        /* only 2 bits for now */
                        int sh = 0;
-                       int mask = (1<<nr_bits) -1;
-                       int64_t j = 0;
-                       int m = len*8;
+                       uint32_t mask = (1<<nr_bits) -1;
+                       uint32_t m = len*8;
                        if (mul8) {
                                for (; i < nrows && j < m; j++, i++) {
                                        uint8_t v = data[pos];
@@ -167,8 +167,6 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                                        pos+=(sh/8);
                                }
                        } else if (nr_bits < 32) {
-                               int64_t j = 0;
-                               int m = len*8;
                                for (; i < nrows && j < m; j++, i++) {
                                        uint32_t v = *(uint32_t*)(data+pos);
                                        uint32_t idx = (v >> sh)&mask;
@@ -180,7 +178,8 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                                                idx |= (v << (nr_bits-sh))&mask;
                                        }
                                        assert(idx < cr->dict_num_values);
-                                       dst[i] = ((int64_t*)cr->dict)[idx];
+                                       assert(((int64_t*)cr->dict)[idx] < 
((int64_t) 1 << 8*sizeof(T)));
+                                       dst[i] = (T) ((int64_t*)cr->dict)[idx];
                                }
                                if (j < m) {
                                        cr->is_rle = false;
@@ -193,7 +192,6 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                } else if (nr_bits <= 8) { /* rle */
                        len>>=1;
                        uint8_t idx = data[pos++];
-                       uint32_t j = 0;
                        for(; i < nrows && j < len; j++, i++)
                                dst[i] = offset+offsets[idx];
                        if (j < len) {
@@ -204,7 +202,6 @@ pqc_dict_lookup( pqc_creader_t *cr, void
                } else if (nr_bits <= 16) { /* rle */
                        len>>=1;
                        uint16_t idx = *(uint16_t*)(data+pos);
-                       uint32_t j = 0;
                        pos += 2;
                        for(; i < nrows && j < len; j++, i++)
                                dst[i] = offset+offsets[idx];
diff --git a/sql/backends/monet5/vaults/parquet/pqc_filemetadata.c 
b/sql/backends/monet5/vaults/parquet/pqc_filemetadata.c
--- a/sql/backends/monet5/vaults/parquet/pqc_filemetadata.c
+++ b/sql/backends/monet5/vaults/parquet/pqc_filemetadata.c
@@ -132,6 +132,19 @@ pqc_dup(pqc_file *pq)
        return pq;
 }
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+#ifdef NATIVE_WIN32
+static inline int64_t
+mylseek(int fd, int64_t offset, int whence)
+{
+       return (int64_t) _lseeki64(fd, (__int64) offset, whence);
+}
+#else
+#define mylseek(fd, offset, whence)    lseek(fd, (off_t) (offset), whence)
+#endif
+
 pqc_file *
 pqc_copy(pqc_file *opq)
 {
@@ -141,7 +154,7 @@ pqc_copy(pqc_file *opq)
                return pq;
        pq->refcnt = 1;
        pq->filename = opq->filename;
-       pq->fd = open(opq->filename, O_RDONLY);
+       pq->fd = open(opq->filename, O_RDONLY | O_BINARY);
        pq->pa = create_allocator("pqc_copy", false);
        if (!pq->pa) {
                _DELETE(pq);
@@ -156,12 +169,12 @@ pqc_read( pqc_file *pq, int64_t offset, 
 {
        MT_lock_set(&pq->lock);
        if (offset == 0 && sz < PQC_SMALL) {
-               if (lseek(pq->fd, offset, SEEK_SET) != offset)
+               if (mylseek(pq->fd, offset, SEEK_SET) != offset)
                        offset = -3;
                if (read(pq->fd, buffer, sz) != sz)
                        offset = -3;
        } else {
-               if (lseek(pq->fd, offset, SEEK_SET) != offset)
+               if (mylseek(pq->fd, offset, SEEK_SET) != offset)
                        offset = -3;
                if (read(pq->fd, buffer, sz) != sz)
                        offset = -4;
@@ -195,16 +208,18 @@ pqc_open( pqc_file **PQ, char *fn)
        TRC_DEBUG(PARQUET, "fd = %d, file_size = %zu\n", pq->fd, pq->sz);
 
        ssize_t sz = pq->sz;
-       off_t offset = 0;
+       int64_t offset = 0;
        if (sz > 1024) {
                sz = 1024;
                offset = pq->sz - sz;
        }
-       if (offset && lseek(pq->fd, offset, SEEK_SET) != offset) {
+       if (offset && mylseek(pq->fd, offset, SEEK_SET) != offset) {
                pqc_destroy(pq);
                return -3;
        }
-       if (read(pq->fd, buffer, sz) != sz) {
+       /* cast to int for Windows; we know it fits, and Linux automatically
+        * casts back */
+       if (read(pq->fd, buffer, (int) sz) != sz) {
                pqc_destroy(pq);
                return -3;
        }
@@ -225,11 +240,11 @@ pqc_open( pqc_file **PQ, char *fn)
        TRC_DEBUG(PARQUET, "fmdlen %u\n", fmdlen);
 
        offset = (pq->sz > pq->bsz) ? pq->sz - (pq->bsz + 8) : 0;
-       if (offset && lseek(pq->fd, offset, SEEK_SET) != offset) {
+       if (offset && mylseek(pq->fd, offset, SEEK_SET) != offset) {
                pqc_destroy(pq);
                return -3;
        }
-       if (read(pq->fd, pq->buffer, pq->bsz) != (ssize_t)pq->bsz) {
+       if (read(pq->fd, pq->buffer, fmdlen) != (ssize_t)pq->bsz) {
                pqc_destroy(pq);
                return -3;
        }
@@ -242,8 +257,8 @@ pqc_close( pqc_file *pq)
        pqc_destroy(pq);
 }
 
-static int
-pqc_struct( pqc_file *pq, int pos)
+static size_t
+pqc_struct( pqc_file *pq, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -257,8 +272,8 @@ pqc_struct( pqc_file *pq, int pos)
        return pos;
 }
 
-static int
-pqc_timeunit( pqc_file *pq, pqc_schema_element *pse, int pos)
+static size_t
+pqc_timeunit( pqc_file *pq, pqc_schema_element *pse, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -285,8 +300,8 @@ pqc_timeunit( pqc_file *pq, pqc_schema_e
        return pos;
 }
 
-static int
-pqc_timestamp( pqc_file *pq, pqc_schema_element *pse, int pos)
+static size_t
+pqc_timestamp( pqc_file *pq, pqc_schema_element *pse, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -309,8 +324,8 @@ pqc_timestamp( pqc_file *pq, pqc_schema_
        return pos;
 }
 
-static int
-pqc_decimal( pqc_file *pq, pqc_schema_element *pse, int pos)
+static size_t
+pqc_decimal( pqc_file *pq, pqc_schema_element *pse, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -337,8 +352,8 @@ pqc_decimal( pqc_file *pq, pqc_schema_el
        return pos;
 }
 
-static int
-pqc_integer( pqc_file *pq, pqc_schema_element *pse, int pos)
+static size_t
+pqc_integer( pqc_file *pq, pqc_schema_element *pse, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -362,8 +377,8 @@ pqc_integer( pqc_file *pq, pqc_schema_el
        return pos;
 }
 
-static int
-pqc_logicaltype( pqc_file *pq, pqc_schema_element *pse, int pos)
+static size_t
+pqc_logicaltype( pqc_file *pq, pqc_schema_element *pse, size_t pos)
 {
        int fieldid = 0, type = 0;
 
@@ -406,7 +421,7 @@ pqc_logicaltype( pqc_file *pq, pqc_schem
                        break;
                case LOGICAL_TYPE_TIME:
                        TRC_ERROR(PARQUET, "ERROR No support for 
LOGICAL_TYPE_TIME");
-                       return -1;
+                       return (size_t) -1;
                case LOGICAL_TYPE_TIMESTAMP: /* timestamp */
                        pos = pqc_timestamp(pq, pse, pos);
                        break;
@@ -419,19 +434,19 @@ pqc_logicaltype( pqc_file *pq, pqc_schem
                        break;
                case LOGICAL_TYPE_JSON:
                        TRC_ERROR(PARQUET, "no support for LOGICAL_TYPE_JSON");
-                       return -1;
+                       return (size_t) -1;
                case LOGICAL_TYPE_BSON:
                        TRC_ERROR(PARQUET, "no support for LOGICAL_TYPE_BSON");
-                       return -1;
+                       return (size_t) -1;
                case LOGICAL_TYPE_UUID:
                        TRC_ERROR(PARQUET, "no support for LOGICAL_TYPE_UUID");
-                       return -1;
+                       return (size_t) -1;
                case LOGICAL_TYPE_FLOAT16:
                        TRC_ERROR(PARQUET, "no support for 
LOGICAL_TYPE_FLOAT16");
-                       return -1;
+                       return (size_t) -1;
                default:
                        TRC_ERROR(PARQUET, "no support or unknown LOGICAL_TYPE  
%d\n", fieldid);
-                       return -1;
+                       return (size_t) -1;
                }
        }
        return pos;
@@ -600,8 +615,8 @@ pqc_convertedtype2logicaltype( pqc_schem
        return 0;
 }
 
-static int
-pqc_read_schema_element( pqc_file *pq, int nr, int pos, int *ccnr, 
pqc_schema_element *parent)
+static size_t
+pqc_read_schema_element( pqc_file *pq, int nr, size_t pos, int *ccnr, 
pqc_schema_element *parent)
 {
        int fieldid = 0, type = 0;
        pqc_schema_element *pse = pq->fmd->elements + nr;
@@ -635,7 +650,7 @@ pqc_read_schema_element( pqc_file *pq, i
                        pos += pqc_get_zint32(pq->buffer+pos, &precision);
                        if (pse->type != stringtype) {
                                TRC_ERROR(PARQUET, "precision %u used with 
wrong type %d\n", precision, pse->type);
-                               return -1;
+                               return (size_t) -1;
                        }
                        pse->type_length = precision;
                        TRC_INFO(PARQUET, "precision %u\n", precision);
@@ -653,7 +668,7 @@ pqc_read_schema_element( pqc_file *pq, i
                        int res = pqc_string(pq, pq->buffer+pos, &pse->name);
                        if (res < 0) {
                                TRC_ERROR(PARQUET, "failure reading 
SCHEMA_ELEMENT_NAME");
-                               return -1;
+                               return (size_t) -1;
                        }
                        pos += res;
                        TRC_INFO(PARQUET, "name %s\n", pse->name);
@@ -675,7 +690,7 @@ pqc_read_schema_element( pqc_file *pq, i
                        pos += pqc_get_zint32(pq->buffer+pos, &scale);
                        if (pse->type != decimaltype) {
                                TRC_ERROR(PARQUET, "scale %u used with wrong 
type %d\n", scale, pse->type);
-                               return -1;
+                               return (size_t) -1;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to