Changeset: 8fa9335035aa for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8fa9335035aa
Modified Files:
clients/Tests/exports.stable.out
sql/backends/monet5/vaults/parquet/parquet.c
sql/backends/monet5/vaults/parquet/pqc_dict_lookup.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_filemetadata.h
sql/backends/monet5/vaults/parquet/pqc_reader.c
sql/backends/monet5/vaults/parquet/pqc_reader.h
Branch: pp_hashjoin
Log Message:
add support for blob, timestamp (based on INT96).
Cast into smaller types (todo fix signedness and handle nil in values space)
diffs (truncated from 1103 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1632,7 +1632,7 @@ int pqc_open(pqc_file **pq, char *fn);
int pqc_put_int32(char *in, uint32_t v);
int pqc_put_int64(char *in, uint64_t v);
int64_t pqc_read(pqc_file *pq, int64_t offset, char *buffer, int nrbytes);
-int64_t pqc_read_chunk(pqc_reader_t *r, int wnr, void *d, void *vd, uint64_t
nrows, int *ssize, int *dict);
+int64_t pqc_read_chunk(pqc_reader_t *r, int wnr, void *d, void *vd, uint64_t
nrows, size_t *ssize, int *dict);
int pqc_read_filemetadata(pqc_file *pq);
int pqc_read_schema(pqc_file *pq);
pqc_reader_t *pqc_reader(pqc_reader_t *p, pqc_file *pq, int nr_workers,
pqc_filemetadata *fmd, int colnr, int64_t nrows, const void *nil);
diff --git a/sql/backends/monet5/vaults/parquet/parquet.c
b/sql/backends/monet5/vaults/parquet/parquet.c
--- a/sql/backends/monet5/vaults/parquet/parquet.c
+++ b/sql/backends/monet5/vaults/parquet/parquet.c
@@ -244,13 +244,16 @@ pqc_find_subtype(mvc *sql, const pqc_sch
return tpe;
break;
case inttype:
- if (pse->size == 8 && sql_find_subtype(tpe, "tinyint",
pse->precision, 0))
+ if (pse->precision == 8 && sql_find_subtype(tpe,
"tinyint", pse->precision, 0))
return tpe;
- if (pse->size == 16 && sql_find_subtype(tpe,
"smallint", pse->precision, 0))
+ if (pse->precision == 16 && sql_find_subtype(tpe,
"smallint", pse->precision, 0))
return tpe;
- if (pse->size == 32 && sql_find_subtype(tpe, "int",
pse->precision, 0))
+ if (pse->precision == 32 && sql_find_subtype(tpe,
"int", pse->precision, 0))
return tpe;
- if (pse->size == 64 && sql_find_subtype(tpe, "bigint",
pse->precision, 0))
+ if (pse->precision == 64 && sql_find_subtype(tpe,
"bigint", pse->precision, 0))
+ return tpe;
+ //if (pse->size == 96 && sql_find_subtype(tpe,
"hugeint", pse->precision, 0))
+ if (pse->precision == 96 && sql_find_subtype(tpe,
"timestamp", 6, 0))
return tpe;
break;
case floattype:
@@ -268,7 +271,7 @@ pqc_find_subtype(mvc *sql, const pqc_sch
return tpe;
break;
case timestamptype:
- if (pse->precision <= 6 && sql_find_subtype(tpe,
"timestamp", pse->precision, 0))
+ if (pse->precision == 6 && sql_find_subtype(tpe,
"timestamp", pse->precision, 0))
return tpe;
break;
case decimaltype:
@@ -293,6 +296,14 @@ pqc_find_subtype(mvc *sql, const pqc_sch
if (sql_find_subtype(tpe, "oid", 0, 0))
return tpe;
break;
+ case blobtype:
+ if (pse->physical_type == PT_BYTE_ARRAY) { /* byte
array */
+ if (sql_find_subtype(tpe, "blob",
pse->precision, pse->scale)) {
+ tpe->digits = pse->precision;
+ return tpe;
+ }
+ }
+ return NULL;
default:
return NULL;
}
@@ -310,14 +321,24 @@ pqc_find_localtype(const pqc_schema_elem
return TYPE_bte;
break;
case inttype:
- if (pse->size == 8)
+ //if (pse->size == 8)
+ if (pse->precision == 8)
return TYPE_bte;
- if (pse->size == 16)
+ //if (pse->size == 16)
+ if (pse->precision == 16)
return TYPE_sht;
- if (pse->size == 32)
+ //if (pse->size == 32)
+ if (pse->precision == 32)
return TYPE_int;
- if (pse->size == 64)
+ //if (pse->size == 64)
+ if (pse->precision == 64)
return TYPE_lng;
+ if (pse->precision == 96)
+ return TYPE_timestamp;
+#ifdef HAVE_HGE
+ if (pse->size == 128)
+ return TYPE_hge;
+#endif
break;
case floattype:
if (pse->precision == 32)
@@ -349,6 +370,10 @@ pqc_find_localtype(const pqc_schema_elem
break;
case listtype:
return TYPE_oid;
+ case blobtype:
+ if (pse->physical_type == PT_BYTE_ARRAY) /* byte array
*/
+ return TYPE_blob;
+ return TYPE_void;
default:
return TYPE_void;
}
@@ -408,7 +433,7 @@ pqc_relation(mvc *sql, sql_subfunc *f, c
list *types = sa_list(sql->sa), *names = sa_list(sql->sa);
for(int i = 1; i < nr; i++) {
const pqc_schema_element *e = pse+i;
- sql_subtype *t =
(e->type!=LT_UNKNOWN)?pqc_find_subtype(sql, e):NULL;
+ sql_subtype *t = (e->type !=
LT_UNKNOWN)?pqc_find_subtype(sql, e):NULL;
if (e->type != LT_UNKNOWN && !t) {
int tpe = e->type;
@@ -603,8 +628,10 @@ PARQUETread_large(BAT **R, pqc_creader *
BAT *rb = NULL;
- if (pse->type == stringtype) { /* remove vector from interface */
- int ssize = 0, dict = 0;
+ if (pse->type == stringtype || pse->type == blobtype) { /* remove
vector from interface */
+ int dict = 0;
+ bool is_string = (pse->type == stringtype);
+ size_t ssize = 0;
if (pqc_read_chunk(r->c[pse->ccnr], wnr, NULL, NULL, sz,
&ssize, &dict) < 0) {
char *err = pqc_get_error(r->c[pse->ccnr]);
if (err)
@@ -623,15 +650,15 @@ PARQUETread_large(BAT **R, pqc_creader *
throw(SQL, "parquet.read", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
Heap *h = rb->tvheap;
- BUN size = GDK_STRHASHTABLE * sizeof(stridx_t) + ssize/* *
GDK_VARALIGN*/;
+ BUN size = GDK_STRHASHTABLE * sizeof(stridx_t) + ssize/* *
GDK_VARALIGN*/ + 8;
if (h->storage == STORE_INVALID) {
- if (HEAPalloc(h, size, 1) != GDK_SUCCEED) {
+ if (h->size < size && HEAPalloc(h, size, 1) !=
GDK_SUCCEED) {
BBPreclaim(rb);
throw(SQL, "parquet.read", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
}
}
assert(h->size >= size);
- h->free = GDK_STRHASHTABLE * sizeof(stridx_t);
+ h->free = is_string?GDK_STRHASHTABLE * sizeof(stridx_t): 0;
h->dirty = true;
#ifdef NDEBUG
memset(h->base, 0, h->free);
@@ -640,7 +667,7 @@ PARQUETread_large(BAT **R, pqc_creader *
memset(h->base, 0, h->size);
#endif
rb->tascii = true; /* tobe fixed */
- int offset = 0;
+ size_t offset = 0;
if (dict == 4)
offset = h->free;
ssize_t rsz = 0, tsz = 0;
@@ -654,6 +681,7 @@ PARQUETread_large(BAT **R, pqc_creader *
h->free += ssize;
tsz += rsz;
while(tsz < sz) {
+ bool plain = 0;
dict = 0;
if (rsz == 0)
break;
@@ -663,19 +691,30 @@ PARQUETread_large(BAT **R, pqc_creader *
throw (SQL, "parquet.read",
SQLSTATE(HY002) "Error reading parquet file '%s'", err);
throw (SQL, "parquet.read", SQLSTATE(HY002)
"Error reading parquet file");
}
- if (dict) {
- assert(0); /* only one dict */
+ Heap *h = rb->tvheap;
+ if (!dict) { /* only one dict, but could be some plain
values */
+ plain = 1;
+ BUN _d = h->free + (ssize /** GDK_VARALIGN*/);
+ if (rb->twidth < SIZEOF_VAR_T &&
+ (rb->twidth <= 2 ? _d -
GDK_VAROFFSET : _d) >= ((size_t) 1 << (8 << rb->tshift))) {
+ /* doesn't fit in current heap, upgrade
it */
+ if (GDKupgradevarheap(rb, _d, 0, tsz)
!= GDK_SUCCEED) {
+ BBPreclaim(rb);
+ throw(SQL, "parquet.read",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ h = rb->tvheap;
+ }
+ if (h->size < _d && HEAPextend(h, _d, 1) !=
GDK_SUCCEED) {
+ BBPreclaim(rb);
+ throw(SQL, "parquet.read",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+ assert(h->size >= size);
}
- Heap *h = rb->tvheap;
- BUN size = h->free + (ssize /** GDK_VARALIGN*/);
- if (HEAPextend(h, size, 1) != GDK_SUCCEED) {
- BBPreclaim(rb);
- throw(SQL, "parquet.read", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
- /* realloc (TODO handle extending the width) */
- assert(h->size >= size);
dict = rb->twidth;
- offset = h->free;
+ if (dict > 2)
+ offset = h->free;
+ else if (plain)
+ offset = h->free - GDK_STRHASHTABLE *
sizeof(stridx_t);
if ((rsz = pqc_read_chunk(r->c[pse->ccnr], wnr,
((char*)rb->theap->base)+(tsz*dict), ((char*)h->base)+h->free, sz-tsz, &offset,
&dict)) < 0) {
BBPreclaim(rb);
char *err = pqc_get_error(r->c[pse->ccnr]);
@@ -686,7 +725,8 @@ PARQUETread_large(BAT **R, pqc_creader *
if (rsz == 0)
break;
tsz += rsz;
- h->free += ssize;
+ if (plain)
+ h->free += ssize;
}
sz = tsz;
} else { /* fixed sized */
diff --git a/sql/backends/monet5/vaults/parquet/pqc_dict_lookup.h
b/sql/backends/monet5/vaults/parquet/pqc_dict_lookup.h
--- a/sql/backends/monet5/vaults/parquet/pqc_dict_lookup.h
+++ b/sql/backends/monet5/vaults/parquet/pqc_dict_lookup.h
@@ -14,15 +14,16 @@ pqc_dict_lookup( pqc_creader_t *cr, void
uint8_t *data = (uint8_t*)cr->data;
int nr_bits = cr->nr_bits;
int64_t i = 0;
- bool mul8 = ((8/nr_bits)*nr_bits == 8);
+ bool mul8 = nr_bits?((8/nr_bits)*nr_bits == 8):false;
T *dst = output;
uint32_t idx = cr->idx;
uint32_t j = 0;
int mask = (1<<nr_bits) -1;
+ P *dict = (P*)cr->dict;
if (cr->remaining) {
if (cr->is_rle) {
for(; i < nrows && j < cr->remaining; j++, i++)
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
} else {
int sh = idx;
@@ -36,7 +37,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
sh = 0;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if ((cr->remaining - j) == 0)
pos += (sh)/8;
@@ -52,7 +53,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if ((cr->remaining - j) == 0)
pos += (sh)/8;
@@ -68,7 +69,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if ((cr->remaining - j) == 0)
pos += (sh)/8;
@@ -84,7 +85,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if ((cr->remaining - j) == 0)
pos += (sh)/8;
@@ -112,7 +113,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
sh = 0;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if (j < m) {
cr->is_rle = false;
@@ -133,7 +134,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if (j < m) {
cr->is_rle = false;
@@ -154,7 +155,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
+ dst[i] = (T)dict[idx];
}
if (j < m) {
cr->is_rle = false;
@@ -175,7 +176,7 @@ pqc_dict_lookup( pqc_creader_t *cr, void
idx |= (v << (nr_bits-sh))&mask;
}
assert(idx < cr->dict_num_values);
- dst[i] = ((T*)cr->dict)[idx];
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]