MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / lookupPK

Method lookupPK

src/storage/table/arrow_node_table.cpp:213–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211}
212
213bool ArrowNodeTable::lookupPK([[maybe_unused]] const transaction::Transaction* transaction,
214 common::ValueVector* keyVector, uint64_t vectorPos, common::offset_t& result) const {
215 if (keyVector->isNull(vectorPos)) {
216 return false;
217 }
218
219 int64_t pkArrowColumnIdx = -1;
220 for (common::idx_t propIdx = 0; propIdx < nodeTableCatalogEntry->getNumProperties();
221 ++propIdx) {
222 if (nodeTableCatalogEntry->getColumnID(propIdx) == getPKColumnID()) {
223 pkArrowColumnIdx = static_cast<int64_t>(propIdx);
224 break;
225 }
226 }
227 if (pkArrowColumnIdx < 0 || !schema.children || pkArrowColumnIdx >= schema.n_children ||
228 !schema.children[pkArrowColumnIdx]) {
229 return false;
230 }
231
232 auto keyToLookup = keyVector->getAsValue(vectorPos);
233 auto pkType = getColumn(getPKColumnID()).getDataType().copy();
234 auto singleValueState = common::DataChunkState::getSingleValueDataChunkState();
235 auto arrowPKVector =
236 std::make_unique<common::ValueVector>(std::move(pkType), memoryManager, singleValueState);
237 arrowPKVector->state->setToFlat();
238
239 for (size_t batchIdx = 0; batchIdx < arrays.size(); ++batchIdx) {
240 const auto& batch = arrays[batchIdx];
241 const auto batchLength = getArrowBatchLength(batch);
242 if (batchLength == 0 || !batch.children || pkArrowColumnIdx >= batch.n_children ||
243 !batch.children[pkArrowColumnIdx]) {
244 continue;
245 }
246 auto* pkChildArray = batch.children[pkArrowColumnIdx];
247 auto* pkChildSchema = schema.children[pkArrowColumnIdx];
248 common::ArrowNullMaskTree nullMask(pkChildSchema, pkChildArray, pkChildArray->offset,
249 pkChildArray->length);
250 for (uint64_t rowIdx = 0; rowIdx < batchLength; ++rowIdx) {
251 common::ArrowConverter::fromArrowArray(pkChildSchema, pkChildArray, *arrowPKVector,
252 &nullMask, pkChildArray->offset + rowIdx, 0, 1);
253 if (arrowPKVector->isNull(0)) {
254 continue;
255 }
256 if (*arrowPKVector->getAsValue(0) == *keyToLookup) {
257 result = batchStartOffsets[batchIdx] + rowIdx;
258 return true;
259 }
260 }
261 }
262 return false;
263}
264
265bool ArrowNodeTable::isVisible([[maybe_unused]] const transaction::Transaction* transaction,
266 common::offset_t offset) const {

Callers

nothing calls this directly

Calls 10

getPKColumnIDFunction · 0.85
getAsValueMethod · 0.80
getDataTypeMethod · 0.80
getArrowBatchLengthFunction · 0.70
getColumnFunction · 0.50
isNullMethod · 0.45
getNumPropertiesMethod · 0.45
getColumnIDMethod · 0.45
copyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected