-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add support for CLP JSON string serialization. #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fb53c9f
71b26be
ca77cf3
e175675
f4632fd
3095fa0
ee38e83
4b26c7c
2c27605
f13eb81
9b56170
791f03e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ | |
| #include "clp_s/search/EvaluateTimestampIndex.hpp" | ||
| #include "clp_s/search/ast/EmptyExpr.hpp" | ||
| #include "clp_s/search/ast/SearchUtils.hpp" | ||
| #include "velox/connectors/clp/ClpColumnHandle.h" | ||
| #include "velox/connectors/clp/search_lib/archive/ClpArchiveCursor.h" | ||
| #include "velox/connectors/clp/search_lib/archive/ClpArchiveJsonStringVectorLoader.h" | ||
| #include "velox/connectors/clp/search_lib/archive/ClpArchiveVectorLoader.h" | ||
| #include "velox/connectors/clp/search_lib/archive/ClpQueryRunner.h" | ||
|
|
||
|
|
@@ -45,7 +47,8 @@ ClpArchiveCursor::~ClpArchiveCursor() { | |
|
|
||
| uint64_t ClpArchiveCursor::fetchNext(uint64_t numRows) { | ||
| filteredRowIndices_->clear(); | ||
| readerIndex_ = 0; | ||
| projectedColumnIndex_ = 0; | ||
| columnIndex_ = 0; | ||
|
|
||
| if (ErrorCode::Success != errorCode_) { | ||
| return 0; | ||
|
|
@@ -69,9 +72,9 @@ uint64_t ClpArchiveCursor::fetchNext(uint64_t numRows) { | |
| continue; | ||
| } | ||
|
|
||
| auto& reader = | ||
| archiveReader_->read_schema_table(currentSchemaId_, false, false); | ||
| reader.initialize_filter_with_column_map(queryRunner_.get()); | ||
| schemaReader_ = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're passing this pointer to the JSON string vector loader, and the result of Can we ever call
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question. I think the situation is similar to how we handle |
||
| &archiveReader_->read_schema_table(currentSchemaId_, false, false); | ||
| schemaReader_->initialize_filter_with_column_map(queryRunner_.get()); | ||
|
|
||
| errorCode_ = ErrorCode::Success; | ||
| currentSchemaTableLoaded_ = true; | ||
|
|
@@ -99,7 +102,7 @@ VectorPtr ClpArchiveCursor::createVector( | |
| size_t vectorSize) { | ||
| auto projectedColumns = getProjectedColumns(); | ||
| VELOX_CHECK_EQ( | ||
| projectedColumns.size(), | ||
| projectedColumns.size() + jsonStringColumnIndices_.size(), | ||
| outputColumns_.size(), | ||
| "Projected columns size {} does not match fields size {}", | ||
| projectedColumns.size(), | ||
|
|
@@ -149,7 +152,12 @@ ErrorCode ClpArchiveCursor::loadSplit() { | |
| projection_ = std::make_shared<Projection>( | ||
| outputColumns_.empty() ? ReturnAllColumns : ReturnSelectedColumns, true); | ||
| try { | ||
| for (auto const& column : outputColumns_) { | ||
| for (size_t i = 0; i < outputColumns_.size(); i++) { | ||
| auto const& column = outputColumns_[i]; | ||
| if (ClpColumnHandle::jsonStringColumnName_ == column.name) { | ||
| jsonStringColumnIndices_.insert(i); | ||
| continue; | ||
| } | ||
|
wraymo marked this conversation as resolved.
|
||
| std::vector<std::string> descriptorTokens; | ||
| std::string descriptorNamespace; | ||
| if (false == | ||
|
|
@@ -195,7 +203,6 @@ ErrorCode ClpArchiveCursor::loadSplit() { | |
| return ErrorCode::InternalError; | ||
| } | ||
| projection_->resolve_columns(schemaTree); | ||
| archiveReader_->set_projection(projection_); | ||
|
|
||
| archiveReader_->read_metadata(); | ||
|
|
||
|
|
@@ -237,9 +244,12 @@ VectorPtr ClpArchiveCursor::createVectorHelper( | |
| size_t vectorSize, | ||
| const std::vector<clp_s::BaseColumnReader*>& projectedColumns) { | ||
| if (vectorType->kind() == TypeKind::ROW) { | ||
| std::vector<VectorPtr> children; | ||
| auto& rowType = vectorType->as<TypeKind::ROW>(); | ||
| for (uint32_t i = 0; i < rowType.size(); ++i) { | ||
| const uint32_t numChildren = rowType.size(); | ||
| std::vector<VectorPtr> children; | ||
| children.reserve(numChildren); | ||
|
|
||
| for (uint32_t i = 0; i < numChildren; ++i) { | ||
| children.push_back(createVectorHelper( | ||
| pool, rowType.childAt(i), vectorSize, projectedColumns)); | ||
|
wraymo marked this conversation as resolved.
|
||
| } | ||
|
|
@@ -249,11 +259,25 @@ VectorPtr ClpArchiveCursor::createVectorHelper( | |
| auto vector = BaseVector::create(vectorType, vectorSize, pool); | ||
| vector->setNulls(allocateNulls(vectorSize, pool, bits::kNull)); | ||
|
|
||
| if (jsonStringColumnIndices_.contains(columnIndex_)) { | ||
| ++columnIndex_; | ||
| return std::make_shared<LazyVector>( | ||
| pool, | ||
| vectorType, | ||
| vectorSize, | ||
| std::make_unique<ClpArchiveJsonStringVectorLoader>( | ||
| schemaReader_, filteredRowIndices_), | ||
| std::move(vector)); | ||
| } | ||
|
|
||
| VELOX_CHECK_LT( | ||
| readerIndex_, projectedColumns.size(), "Reader index out of bounds"); | ||
| auto projectedColumn = projectedColumns[readerIndex_]; | ||
| auto projectedType = outputColumns_[readerIndex_].type; | ||
| readerIndex_++; | ||
| projectedColumnIndex_, | ||
| projectedColumns.size(), | ||
| "Projected column index out of bounds"); | ||
| auto* projectedColumn = projectedColumns[projectedColumnIndex_]; | ||
| auto projectedType = outputColumns_[columnIndex_].type; | ||
| projectedColumnIndex_++; | ||
| columnIndex_++; | ||
| return std::make_shared<LazyVector>( | ||
| pool, | ||
| vectorType, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| #include "clp_s/ColumnReader.hpp" | ||
| #include "velox/connectors/clp/search_lib/archive/ClpArchiveJsonStringVectorLoader.h" | ||
| #include "velox/vector/ComplexVector.h" | ||
|
|
||
| namespace facebook::velox::connector::clp::search_lib { | ||
|
|
||
| ClpArchiveJsonStringVectorLoader::ClpArchiveJsonStringVectorLoader( | ||
| clp_s::SchemaReader* schemaReader, | ||
| const std::shared_ptr<std::vector<uint64_t>>& filteredRowIndices) | ||
| : schemaReader_(schemaReader), filteredRowIndices_(filteredRowIndices) { | ||
| schemaReader_->initialize_serializer(); | ||
| } | ||
|
|
||
| void ClpArchiveJsonStringVectorLoader::loadInternal( | ||
| RowSet rows, | ||
| ValueHook* hook, | ||
| vector_size_t resultSize, | ||
| VectorPtr* result) { | ||
| VELOX_CHECK_NOT_NULL(result, "result vector must not be null"); | ||
| VELOX_CHECK_NULL( | ||
| hook, "ClpArchiveJsonStringVectorLoader doesn't support ValueHook"); | ||
|
|
||
| auto vector = *result; | ||
| auto* stringVector = vector->asFlatVector<StringView>(); | ||
| for (vector_size_t const vectorIndex : rows) { | ||
| auto messageIndex = filteredRowIndices_->at(vectorIndex); | ||
| auto jsonString = schemaReader_->generate_json_string(messageIndex); | ||
| stringVector->set(vectorIndex, StringView(jsonString)); | ||
| stringVector->setNull(vectorIndex, false); | ||
| } | ||
| } | ||
|
|
||
| } // namespace facebook::velox::connector::clp::search_lib |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) Facebook, Inc. and its affiliates. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "clp_s/SchemaReader.hpp" | ||
| #include "velox/vector/FlatVector.h" | ||
| #include "velox/vector/LazyVector.h" | ||
|
|
||
| namespace facebook::velox::connector::clp::search_lib { | ||
|
|
||
| /// A custom Velox VectorLoader that populates Velox vectors with serialized | ||
| /// JSON string from CLP column readers for the archive format. | ||
| class ClpArchiveJsonStringVectorLoader : public VectorLoader { | ||
| public: | ||
| ClpArchiveJsonStringVectorLoader( | ||
| clp_s::SchemaReader* schemaReader, | ||
| const std::shared_ptr<std::vector<uint64_t>>& filteredRowIndices); | ||
|
|
||
| private: | ||
| clp_s::SchemaReader* schemaReader_; | ||
| std::shared_ptr<std::vector<uint64_t>> filteredRowIndices_; | ||
|
|
||
| void loadInternal( | ||
| RowSet rows, | ||
| ValueHook* hook, | ||
| vector_size_t resultSize, | ||
| VectorPtr* result) override; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| } // namespace facebook::velox::connector::clp::search_lib | ||
Uh oh!
There was an error while loading. Please reload this page.