Skip to content

Commit

Permalink
fix rdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ray6080 committed Mar 2, 2024
1 parent 276b2bc commit dac8b8d
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 44 deletions.
2 changes: 0 additions & 2 deletions src/function/table/call/storage_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ struct StorageInfoSharedState final : public CallFuncSharedState {
columns.push_back(relTable->getCSRLengthColumn(RelDataDirection::FWD));
columns.push_back(relTable->getCSROffsetColumn(RelDataDirection::BWD));
columns.push_back(relTable->getCSRLengthColumn(RelDataDirection::BWD));
columns.push_back(relTable->getAdjColumn(RelDataDirection::FWD));
columns.push_back(relTable->getAdjColumn(RelDataDirection::BWD));
for (auto columnID = 0u; columnID < relTable->getNumColumns(); columnID++) {
auto column = relTable->getColumn(columnID, RelDataDirection::FWD);
auto collectedColumns = collectColumns(column);
Expand Down
5 changes: 0 additions & 5 deletions src/include/storage/local_storage/local_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ class LocalDataChunkCollection {
}
void update(
common::offset_t offset, common::column_id_t columnID, common::ValueVector* propertyVector);
// Only used for rel tables. Should be moved out later.
void update(common::offset_t srcOffset, common::offset_t relOffset,
common::column_id_t columnID, common::ValueVector* propertyVector) {
update(relOffset, columnID, propertyVector);
}
void remove(common::offset_t offset) {
if (offsetToRowIdx.contains(offset)) {
offsetToRowIdx.erase(offset);
Expand Down
5 changes: 2 additions & 3 deletions src/include/storage/storage_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ class StorageUtils {
DATA = 3, // This is used for data columns in VAR_LIST and STRING columns.
CSR_OFFSET = 4,
CSR_LENGTH = 5,
ADJ = 6,
STRUCT_CHILD = 7,
NULL_MASK = 8,
STRUCT_CHILD = 6,
NULL_MASK = 7,
};

// TODO: Constrain T1 and T2 to numerics.
Expand Down
4 changes: 0 additions & 4 deletions src/include/storage/store/rel_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class RelTable final : public Table {
fwdRelTableData->dropColumn(columnID);
bwdRelTableData->dropColumn(columnID);
}
inline Column* getAdjColumn(common::RelDataDirection direction) {
return direction == common::RelDataDirection::FWD ? fwdRelTableData->getNbrIDColumn() :
bwdRelTableData->getNbrIDColumn();
}
inline Column* getCSROffsetColumn(common::RelDataDirection direction) {
return direction == common::RelDataDirection::FWD ? fwdRelTableData->getCSROffsetColumn() :
bwdRelTableData->getCSROffsetColumn();
Expand Down
2 changes: 1 addition & 1 deletion src/processor/map/map_copy_from.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ physical_op_vector_t PlanMapper::mapCopyRelFrom(LogicalOperator* logicalOperator
storageManager.getNodeTable(relTableEntry->getDstTableID());
// TODO(Xiyang): Move binding of column types to binder.
std::vector<std::unique_ptr<LogicalType>> columnTypes;
columnTypes.push_back(LogicalType::INTERNAL_ID()); // ADJ COLUMN.
columnTypes.push_back(LogicalType::INTERNAL_ID()); // NBR_ID COLUMN.
for (auto& property : relTableEntry->getPropertiesRef()) {
columnTypes.push_back(property.getDataType()->copy());
}
Expand Down
4 changes: 2 additions & 2 deletions src/processor/operator/persistent/delete_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ void MultiLabelNodeDeleteExecutor::delete_(ExecutionContext* context) {
detachDeleteState.get());
}
for (auto& relTable : bwdRelTables) {
// TODO: FIX-ME. For detach delete, there can possibly be a case where the same relTable is
// TODO(Guodong): For detach delete, there can possibly be a case where the same relTable is
// in both fwd and bwd rel tables set. the rels can be deleted twice. This is a temporary
// fix.
// hack.
if (deleteType == DeleteNodeType::DETACH_DELETE && fwdRelTables.contains(relTable)) {
continue;
}
Expand Down
12 changes: 7 additions & 5 deletions src/storage/local_storage/local_rel_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ LocalRelNG::LocalRelNG(offset_t nodeGroupStartOffset, std::vector<LogicalType*>
row_idx_t LocalRelNG::scanCSR(offset_t srcOffsetInChunk, offset_t posToReadForOffset,
const std::vector<column_id_t>& columnIDs, const std::vector<ValueVector*>& outputVectors) {
KU_ASSERT(columnIDs.size() == outputVectors.size());
auto iteratorIdx = 0u;
std::vector<row_idx_t> rowIdxesToRead;
rowIdxesToRead.reserve(DEFAULT_VECTOR_CAPACITY);
auto& insertedRelOffsets = insertChunks.getRelOffsetsFromSrcOffset(srcOffsetInChunk);
Expand Down Expand Up @@ -120,17 +119,17 @@ bool LocalRelNG::update(
KU_ASSERT(srcNodeIDVector->state->selVector->selectedSize == 1 &&
relIDVector->state->selVector->selectedSize == 1);
auto srcNodeIDPos = srcNodeIDVector->state->selVector->selectedPositions[0];
if (srcNodeIDVector->isNull(srcNodeIDPos)) {
auto relIDPos = relIDVector->state->selVector->selectedPositions[0];
if (srcNodeIDVector->isNull(srcNodeIDPos) || relIDVector->isNull(relIDPos)) {
return false;
}
auto srcNodeOffset =
srcNodeIDVector->getValue<nodeID_t>(srcNodeIDPos).offset - nodeGroupStartOffset;
KU_ASSERT(srcNodeOffset < StorageConstants::NODE_GROUP_SIZE && columnID < updateChunks.size());
auto relIDPos = relIDVector->state->selVector->selectedPositions[0];
auto relOffset = relIDVector->getValue<relID_t>(relIDPos).offset;
// Check if the rel is newly inserted or in persistent storage.
if (insertChunks.hasOffset(relOffset)) {
insertChunks.update(srcNodeOffset, relOffset, columnID, propertyVector);
insertChunks.update(relOffset, columnID, propertyVector);
} else {
updateChunks[columnID].append(srcNodeOffset, relOffset, {propertyVector});
}
Expand All @@ -141,9 +140,12 @@ bool LocalRelNG::delete_(ValueVector* srcNodeVector, ValueVector* relIDVector) {
KU_ASSERT(srcNodeVector->state->selVector->selectedSize == 1 &&
relIDVector->state->selVector->selectedSize == 1);
auto srcNodePos = srcNodeVector->state->selVector->selectedPositions[0];
auto relIDPos = relIDVector->state->selVector->selectedPositions[0];
if (srcNodeVector->isNull(srcNodePos) || relIDVector->isNull(relIDPos)) {
return false;
}
auto srcNodeOffset =
srcNodeVector->getValue<nodeID_t>(srcNodePos).offset - nodeGroupStartOffset;
auto relIDPos = relIDVector->state->selVector->selectedPositions[0];
auto relOffset = relIDVector->getValue<relID_t>(relIDPos).offset;
// If the rel is newly inserted, remove the rel from insertChunks.
if (insertChunks.hasOffset(relOffset)) {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/stats/property_statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::unique_ptr<PropertyStatistics> PropertyStatistics::deserialize(
bool RWPropertyStats::mayHaveNull(const transaction::Transaction& transaction) {
// Columns internal to the storage, i.e., not mapping to a property in table schema, are not
// tracked in statistics. For example, offset of var list column, csr offset column, etc.
// TODO(Guodong): INVALID_PROPERTY_ID is used here because we have a column, i.e., adjColumn,
// TODO(Guodong): INVALID_PROPERTY_ID is used here because we have a column, i.e., nbrIDColumn,
// not exposed as property in table schema, but still have nullColumn. Should be fixed once we
// properly align properties and chunks.
if (propertyID == common::INVALID_PROPERTY_ID) {
Expand All @@ -40,7 +40,7 @@ bool RWPropertyStats::mayHaveNull(const transaction::Transaction& transaction) {
}

void RWPropertyStats::setHasNull(const transaction::Transaction& transaction) {
// TODO(Guodong): INVALID_PROPERTY_ID is used here because we have a column, i.e., adjColumn,
// TODO(Guodong): INVALID_PROPERTY_ID is used here because we have a column, i.e., nbrIDColumn,
// not exposed as property in table schema, but still have nullColumn. Should be fixed once we
// properly align properties and chunks.
if (propertyID != common::INVALID_PROPERTY_ID) {
Expand Down
6 changes: 4 additions & 2 deletions src/storage/storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ static void setCommonTableIDToRdfRelTable(
for (auto rdfEntry : rdfEntries) {
if (rdfEntry->isParent(relTable->getTableID())) {
std::vector<Column*> columns;
columns.push_back(relTable->getDirectedTableData(RelDataDirection::FWD)->getColumn(1));
columns.push_back(relTable->getDirectedTableData(RelDataDirection::BWD)->getColumn(1));
// TODO(Guodong): This is a hack. We should not use constant 2 and should move the
// setting logic inside RelTableData.
columns.push_back(relTable->getDirectedTableData(RelDataDirection::FWD)->getColumn(2));
columns.push_back(relTable->getDirectedTableData(RelDataDirection::BWD)->getColumn(2));
for (auto& column : columns) {
ku_dynamic_cast<storage::Column*, storage::InternalIDColumn*>(column)
->setCommonTableID(rdfEntry->getResourceTableID());
Expand Down
3 changes: 0 additions & 3 deletions src/storage/storage_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ std::string StorageUtils::getColumnName(
case StorageUtils::ColumnType::CSR_LENGTH: {
return stringFormat("{}_csr_length", prefix);
}
case StorageUtils::ColumnType::ADJ: {
return stringFormat("{}_adj", prefix);
}
case StorageUtils::ColumnType::STRUCT_CHILD: {
return stringFormat("{}_{}_child", propertyName, prefix);
}
Expand Down
20 changes: 8 additions & 12 deletions src/storage/store/rel_table_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ RelTableData::RelTableData(BMFileHandle* dataFH, BMFileHandle* metadataFH,
// Columns (nbrID + properties).
auto& properties = tableEntry->getPropertiesRef();
columns.reserve(properties.size() + 1);
auto adjMetadataDAHInfo = relsStoreStats->getColumnMetadataDAHInfo(
auto nbrIDMetadataDAHInfo = relsStoreStats->getColumnMetadataDAHInfo(
&DUMMY_WRITE_TRANSACTION, tableID, NBR_ID_COLUMN_ID, direction);
auto adjColName = StorageUtils::getColumnName(
"", StorageUtils::ColumnType::ADJ, RelDataDirectionUtils::relDirectionToString(direction));
auto adjColumn = ColumnFactory::createColumn(adjColName, *LogicalType::INTERNAL_ID(),
*adjMetadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_WRITE_TRANSACTION,
auto nbrIDColName = StorageUtils::getColumnName("NBR_ID", StorageUtils::ColumnType::DEFAULT,
RelDataDirectionUtils::relDirectionToString(direction));
auto nbrIDColumn = ColumnFactory::createColumn(nbrIDColName, *LogicalType::INTERNAL_ID(),
*nbrIDMetadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_WRITE_TRANSACTION,
RWPropertyStats::empty(), enableCompression);
columns.push_back(std::move(adjColumn));
columns.push_back(std::move(nbrIDColumn));
// Property columns.
for (auto i = 0u; i < properties.size(); i++) {
auto& property = properties[i];
Expand All @@ -165,7 +165,7 @@ RelTableData::RelTableData(BMFileHandle* dataFH, BMFileHandle* metadataFH,
*metadataDAHInfo, dataFH, metadataFH, bufferManager, wal, &DUMMY_WRITE_TRANSACTION,
RWPropertyStats(relsStoreStats, tableID, property.getPropertyID()), enableCompression));
}
// Set common tableID for adjColumn and relIDColumn.
// Set common tableID for nbrIDColumn and relIDColumn.
auto nbrTableID = ku_dynamic_cast<TableCatalogEntry*, RelTableCatalogEntry*>(tableEntry)
->getNbrTableID(direction);
ku_dynamic_cast<Column*, InternalIDColumn*>(columns[NBR_ID_COLUMN_ID].get())
Expand Down Expand Up @@ -222,14 +222,10 @@ void RelTableData::scan(Transaction* transaction, TableReadState& readState,
outputVectors[0]->state->selVector->resetSelectorToUnselectedWithSize(numRowsToRead);
outputVectors[0]->state->setOriginalSize(numRowsToRead);
auto nodeGroupIdx = StorageUtils::getNodeGroupIdx(relReadState.currentNodeOffset);
// getColumn(NBR_ID_COLUMN_ID)
// ->scan(transaction, nodeGroupIdx, startOffset, endOffset, outputVectors[0],
// 0 /* offsetInVector */);
auto relIDVectorIdx = INVALID_VECTOR_IDX;
for (auto i = 0u; i < relReadState.columnIDs.size(); i++) {
auto columnID = relReadState.columnIDs[i];
// KU_ASSERT(columnID != 0);
auto outputVectorId = i; // Skip output from adj column.
auto outputVectorId = i; // Skip output from nbrID column.
if (columnID == INVALID_COLUMN_ID) {
outputVectors[outputVectorId]->setAllNull();
continue;
Expand Down
6 changes: 3 additions & 3 deletions test/test_files/tinysnb/call/call.test
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Binder exception: Cannot evaluate a.fName as a literal.
37
-STATEMENT CALL storage_info('knows') RETURN COUNT(*)
---- 1
82
-STATEMENT CALL storage_info('workAt') RETURN COUNT(*)
84
-STATEMENT CALL storage_info('workAt') RETURN *
---- 1
22
24

0 comments on commit dac8b8d

Please sign in to comment.