-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[Feature] support iceberg metadata table #33186
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
be/src/exec/schema_scanner/schema_iceberg_files_scanner.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// https://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 "exec/schema_scanner/schema_iceberg_files_scanner.h" | ||
|
||
#include "exec/schema_scanner/schema_helper.h" | ||
#include "runtime/runtime_state.h" | ||
#include "runtime/string_value.h" | ||
|
||
namespace starrocks { | ||
|
||
SchemaScanner::ColumnDesc SchemaIcebergFilesScanner::_iceberg_files_columns[] = { | ||
// name, type, size, is_null | ||
{"content", TYPE_INT, sizeof(int32_t), false}, | ||
{"file_path", TYPE_VARCHAR, sizeof(StringValue), false}, | ||
{"file_format", TYPE_VARCHAR, sizeof(StringValue), false}, | ||
{"spec_id", TYPE_INT, sizeof(int32_t), false}, | ||
{"record_count", TYPE_BIGINT, sizeof(int64_t), false}, | ||
{"file_size_in_bytes", TYPE_BIGINT, sizeof(int64_t), false}, | ||
{"column_sizes", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"value_counts", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"null_value_counts", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"nan_value_counts", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"lower_bounds", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"upper_bounds", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"split_offsets", TYPE_VARCHAR, sizeof(StringValue), true}, | ||
{"equality_ids", TYPE_VARCHAR, sizeof(StringValue), true}}; | ||
|
||
SchemaIcebergFilesScanner::SchemaIcebergFilesScanner() | ||
: SchemaScanner(_iceberg_files_columns, sizeof(_iceberg_files_columns) / sizeof(SchemaScanner::ColumnDesc)) {} | ||
|
||
SchemaIcebergFilesScanner::~SchemaIcebergFilesScanner() = default; | ||
|
||
Status SchemaIcebergFilesScanner::start(RuntimeState* state) { | ||
RETURN_IF_ERROR(SchemaScanner::start(state)); | ||
TGetIcebergFilesRequest request; | ||
if (nullptr != _param->catalog) { | ||
request.__set_catalog_name(*(_param->catalog)); | ||
} | ||
if (nullptr != _param->origin_db) { | ||
request.__set_db_name(*(_param->origin_db)); | ||
} | ||
if (nullptr != _param->origin_table) { | ||
request.__set_table_name(*(_param->origin_table)); | ||
} | ||
request.__set_limit(_param->limit); | ||
if (nullptr != _param->ip && 0 != _param->port) { | ||
RETURN_IF_ERROR(SchemaHelper::get_iceberg_files(*(_param->ip), _param->port, request, &_files_res)); | ||
} else { | ||
return Status::InternalError("IP or port doesn't exists"); | ||
} | ||
_files_index = 0; | ||
return Status::OK(); | ||
} | ||
|
||
Status SchemaIcebergFilesScanner::fill_chunk(ChunkPtr* chunk) { | ||
const TIcebergFile& file = _files_res.iceberg_files[_files_index]; | ||
const auto& slot_id_to_index_map = (*chunk)->get_slot_id_to_index_map(); | ||
for (const auto& [slot_id, index] : slot_id_to_index_map) { | ||
ColumnPtr column = (*chunk)->get_column_by_slot_id(slot_id); | ||
switch (slot_id) { | ||
case 1: { | ||
// content | ||
{ fill_column_with_slot<TYPE_INT>(column.get(), (void*)&file.content); } | ||
break; | ||
} | ||
case 2: { | ||
// file_path | ||
{ | ||
const std::string* str = &file.file_path; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 3: { | ||
// file_format | ||
{ | ||
const std::string* str = &file.file_format; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 4: { | ||
// spec_id | ||
{ fill_column_with_slot<TYPE_INT>(column.get(), (void*)&file.spec_id); } | ||
break; | ||
} | ||
case 5: { | ||
// record_count | ||
{ fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&file.record_count); } | ||
break; | ||
} | ||
case 6: { | ||
// file_size_in_bytes | ||
{ fill_column_with_slot<TYPE_BIGINT>(column.get(), (void*)&file.file_size_in_bytes); } | ||
break; | ||
} | ||
case 7: { | ||
// column_sizes | ||
{ | ||
const std::string* str = &file.column_sizes; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 8: { | ||
// value_counts | ||
{ | ||
const std::string* str = &file.value_counts; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 9: { | ||
// null_value_counts | ||
{ | ||
const std::string* str = &file.null_value_counts; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 10: { | ||
// nan_value_counts | ||
{ | ||
const std::string* str = &file.nan_value_counts; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 11: { | ||
// lower_bounds | ||
{ | ||
const std::string* str = &file.lower_bounds; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 12: { | ||
// upper_bounds | ||
{ | ||
const std::string* str = &file.upper_bounds; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 13: { | ||
// split_offsets | ||
{ | ||
const std::string* str = &file.split_offsets; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
case 14: { | ||
// equality_ids | ||
{ | ||
const std::string* str = &file.equality_ids; | ||
Slice value(str->c_str(), str->length()); | ||
fill_column_with_slot<TYPE_VARCHAR>(column.get(), (void*)&value); | ||
} | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
_files_index++; | ||
return Status::OK(); | ||
} | ||
|
||
Status SchemaIcebergFilesScanner::get_next(ChunkPtr* chunk, bool* eos) { | ||
if (!_is_init) { | ||
return Status::InternalError("Used before initialized."); | ||
} | ||
if (_files_index >= _files_res.iceberg_files.size()) { | ||
*eos = true; | ||
return Status::OK(); | ||
} | ||
if (nullptr == chunk || nullptr == eos) { | ||
return Status::InternalError("input pointer is nullptr."); | ||
} | ||
*eos = false; | ||
return fill_chunk(chunk); | ||
} | ||
|
||
} // namespace starrocks | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2021-present StarRocks, Inc. All rights reserved. | ||
// | ||
// 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 | ||
// | ||
// https://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 <string> | ||
|
||
#include "exec/schema_scanner.h" | ||
#include "gen_cpp/FrontendService_types.h" | ||
|
||
namespace starrocks { | ||
|
||
class SchemaIcebergFilesScanner : public SchemaScanner { | ||
public: | ||
SchemaIcebergFilesScanner(); | ||
~SchemaIcebergFilesScanner() override; | ||
Status start(RuntimeState* state) override; | ||
Status get_next(ChunkPtr* chunk, bool* eos) override; | ||
|
||
private: | ||
Status fill_chunk(ChunkPtr* chunk); | ||
|
||
int _files_index{0}; | ||
TGetIcebergFilesResponse _files_res; | ||
static SchemaScanner::ColumnDesc _iceberg_files_columns[]; | ||
}; | ||
|
||
} // namespace starrocks |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems generally well-structured and follows good practices. I do have a few suggestions, however:
Error messages could be more descriptive: In functions like
get_next()
orstart()
, instead of just mentioning'Used before initialized'
or'input pointer is null'
you can provide the function name as well to make debugging easier.Avoid magic numbers: You might consider defining constants for each case in
fill_chunk(ChunkPtr* chunk)
. Magic numbers like 1, 2, 3...14 are not immediately clear on what they signify.Repeated Code: Inside your
fill_chunk
function's switch statement, the cases where you're dealing with string fields look repetitive. Consider creating a helper method to handle varchar types where you just pass the file attribute.Addressing possible empty strings: For varchar fields, it's a common practice to first check if the string is not empty before proceeding with other operations. Consider adding this logic to further bullet-proof your code.
Variable Naming, Explicitness: In the
start()
function,_files_index = 0;
would make better sense just after_files_res
has been loaded. Also, using meaningful naming (likecurrent_file_index
) could improve readability.Exception Handling: Consider adding exception handling or checking where
RETURN_IF_ERROR
macro is used. You may want to handle exceptions depending on the seriousness of the business impact.Again, these are slight improvements that can be made over already good quality code.