void init_ai_objLong(ai_obj *a, ulong l) { init_ai_obj(a); a->l = l; a->type = a->enc = COL_TYPE_LONG; a->empty = 0; }
/* * Return 0 in case of success * -1 in case of failure */ static int add_recs_from_nbtr(as_sindex_metadata *imd, ai_obj *ikey, bt *nbtr, as_sindex_qctx *qctx, bool fullrng) { int ret = 0; ai_obj sfk, efk; init_ai_obj(&sfk); init_ai_obj(&efk); btSIter *nbi; btEntry *nbe; btSIter stack_nbi; if (fullrng) { nbi = btSetFullRangeIter(&stack_nbi, nbtr, 1, NULL); } else { // search from LAST batches end-point init_ai_objFromDigest(&sfk, &qctx->bdig); assignMaxKey(nbtr, &efk); nbi = btSetRangeIter(&stack_nbi, nbtr, &sfk, &efk, 1); } if (nbi) { while ((nbe = btRangeNext(nbi, 1))) { ai_obj *akey = nbe->key; // FIRST can be REPEAT (last batch) if (!fullrng && ai_objEQ(&sfk, akey)) { continue; } if (btree_addsinglerec(imd, ikey, (cf_digest *)&akey->y, qctx->recl, &qctx->n_bdigs, qctx->can_partition_query, qctx->partitions_pre_reserved)) { ret = -1; break; } if (qctx->n_bdigs == qctx->bsize) { if (ikey) { ai_objClone(qctx->bkey, ikey); } cloneDigestFromai_obj(&qctx->bdig, akey); break; } } btReleaseRangeIterator(nbi); } else { cf_warning(AS_QUERY, "Could not find nbtr iterator.. skipping !!"); } return ret; }
static btSIter *setIterator(btSIter *iter, bt *btr, iter_single *itl, iter_single *itn) { btSIter *siter = iter; siter->dofree = 0; siter->missed = 0; siter->nim = 0; siter->empty = 1; siter->scan = 0; siter->ktype = btr->s.ktype; init_ai_obj(&siter->key); siter->be.key = &(siter->key); siter->be.val = NULL; init_iter(&siter->x, btr, itl, itn); return siter; }
int ai_btree_query(as_sindex_metadata *imd, as_sindex_range *srange, as_sindex_qctx *qctx) { bool err = 1; if (!srange->isrange) { // EQUALITY LOOKUP ai_obj afk; init_ai_obj(&afk); if (C_IS_DG(imd->sktype)) { init_ai_objFromDigest(&afk, &srange->start.digest); } else { init_ai_objLong(&afk, srange->start.u.i64); } err = get_recl(imd, &afk, qctx); } else { // RANGE LOOKUP err = get_numeric_range_recl(imd, srange->start.u.i64, srange->end.u.i64, qctx); } return (err ? AS_SINDEX_ERR_NO_MEMORY : (qctx->n_bdigs >= qctx->bsize) ? AS_SINDEX_CONTINUE : AS_SINDEX_OK); }