-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[fix](iceberg)Bring field_id with parquet files And fix map type's key optional #44470
Changes from all commits
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,134 @@ | ||||||
// Licensed to the Apache Software Foundation (ASF) under one | ||||||
// or more contributor license agreements. See the NOTICE file | ||||||
// distributed with this work for additional information | ||||||
// regarding copyright ownership. The ASF licenses this file | ||||||
// to you 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 "vec/exec/format/table/iceberg/arrow_schema_util.h" | ||||||
|
||||||
#include <arrow/type.h> | ||||||
#include <arrow/util/key_value_metadata.h> | ||||||
|
||||||
namespace doris { | ||||||
namespace iceberg { | ||||||
|
||||||
const char* ArrowSchemaUtil::PARQUET_FIELD_ID = "PARQUET:field_id"; | ||||||
const char* ArrowSchemaUtil::ORIGINAL_TYPE = "originalType"; | ||||||
const char* ArrowSchemaUtil::MAP_TYPE_VALUE = "mapType"; | ||||||
|
||||||
Status ArrowSchemaUtil::convert(const Schema* schema, const std::string& timezone, | ||||||
std::vector<std::shared_ptr<arrow::Field>>& fields) { | ||||||
for (const auto& column : schema->columns()) { | ||||||
std::shared_ptr<arrow::Field> arrow_field; | ||||||
RETURN_IF_ERROR(convert_to(column, &arrow_field, timezone)); | ||||||
fields.push_back(arrow_field); | ||||||
} | ||||||
return Status::OK(); | ||||||
} | ||||||
|
||||||
Status ArrowSchemaUtil::convert_to(const iceberg::NestedField& field, | ||||||
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. warning: function 'convert_to' exceeds recommended size/complexity thresholds [readability-function-size] Status ArrowSchemaUtil::convert_to(const iceberg::NestedField& field,
^ Additional contextbe/src/vec/exec/format/table/iceberg/arrow_schema_util.cpp:39: 89 lines including whitespace and comments (threshold 80) Status ArrowSchemaUtil::convert_to(const iceberg::NestedField& field,
^ |
||||||
std::shared_ptr<arrow::Field>* arrow_field, | ||||||
const std::string& timezone) { | ||||||
std::shared_ptr<arrow::DataType> arrow_type; | ||||||
std::unordered_map<std::string, std::string> metadata; | ||||||
metadata[PARQUET_FIELD_ID] = std::to_string(field.field_id()); | ||||||
|
||||||
switch (field.field_type()->type_id()) { | ||||||
case iceberg::TypeID::BOOLEAN: | ||||||
arrow_type = arrow::boolean(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::INTEGER: | ||||||
arrow_type = arrow::int32(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::LONG: | ||||||
arrow_type = arrow::int64(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::FLOAT: | ||||||
arrow_type = arrow::float32(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::DOUBLE: | ||||||
arrow_type = arrow::float64(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::DATE: | ||||||
arrow_type = arrow::date32(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::TIMESTAMP: { | ||||||
arrow_type = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MICRO, timezone); | ||||||
break; | ||||||
} | ||||||
|
||||||
case iceberg::TypeID::BINARY: | ||||||
case iceberg::TypeID::STRING: | ||||||
case iceberg::TypeID::UUID: | ||||||
case iceberg::TypeID::FIXED: | ||||||
arrow_type = arrow::utf8(); | ||||||
break; | ||||||
|
||||||
case iceberg::TypeID::DECIMAL: { | ||||||
auto dt = dynamic_cast<DecimalType*>(field.field_type()); | ||||||
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. warning: 'auto dt' can be declared as 'auto *dt' [readability-qualified-auto]
Suggested change
|
||||||
arrow_type = arrow::decimal(dt->get_precision(), dt->get_scale()); | ||||||
break; | ||||||
} | ||||||
|
||||||
case iceberg::TypeID::STRUCT: { | ||||||
std::vector<std::shared_ptr<arrow::Field>> element_fields; | ||||||
StructType* st = field.field_type()->as_struct_type(); | ||||||
for (const auto& column : st->fields()) { | ||||||
std::shared_ptr<arrow::Field> element_field; | ||||||
RETURN_IF_ERROR(convert_to(column, &element_field, timezone)); | ||||||
element_fields.push_back(element_field); | ||||||
} | ||||||
arrow_type = arrow::struct_(element_fields); | ||||||
break; | ||||||
} | ||||||
|
||||||
case iceberg::TypeID::LIST: { | ||||||
std::shared_ptr<arrow::Field> item_field; | ||||||
ListType* list_type = field.field_type()->as_list_type(); | ||||||
RETURN_IF_ERROR(convert_to(list_type->element_field(), &item_field, timezone)); | ||||||
arrow_type = arrow::list(item_field); | ||||||
break; | ||||||
} | ||||||
|
||||||
case iceberg::TypeID::MAP: { | ||||||
std::shared_ptr<arrow::Field> key_field; | ||||||
std::shared_ptr<arrow::Field> value_field; | ||||||
MapType* map_type = field.field_type()->as_map_type(); | ||||||
RETURN_IF_ERROR(convert_to(map_type->key_field(), &key_field, timezone)); | ||||||
RETURN_IF_ERROR(convert_to(map_type->value_field(), &value_field, timezone)); | ||||||
metadata[ORIGINAL_TYPE] = MAP_TYPE_VALUE; | ||||||
arrow_type = std::make_shared<arrow::MapType>(key_field, value_field); | ||||||
break; | ||||||
} | ||||||
|
||||||
case iceberg::TypeID::TIME: | ||||||
default: | ||||||
return Status::InternalError("Unsupported field type:" + field.field_type()->to_string()); | ||||||
} | ||||||
|
||||||
std::shared_ptr<arrow::KeyValueMetadata> schema_metadata = | ||||||
std::make_shared<arrow::KeyValueMetadata>(metadata); | ||||||
*arrow_field = | ||||||
arrow::field(field.field_name(), arrow_type, field.is_optional(), schema_metadata); | ||||||
return Status::OK(); | ||||||
} | ||||||
|
||||||
} // namespace iceberg | ||||||
} // namespace doris |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,45 @@ | ||||||||||||||
// Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||
// or more contributor license agreements. See the NOTICE file | ||||||||||||||
// distributed with this work for additional information | ||||||||||||||
// regarding copyright ownership. The ASF licenses this file | ||||||||||||||
// to you 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 <arrow/type.h> | ||||||||||||||
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. warning: 'arrow/type.h' file not found [clang-diagnostic-error] #include <arrow/type.h>
^ |
||||||||||||||
|
||||||||||||||
#include <shared_mutex> | ||||||||||||||
|
||||||||||||||
#include "vec/exec/format/table/iceberg/schema.h" | ||||||||||||||
|
||||||||||||||
namespace doris { | ||||||||||||||
Comment on lines
+25
to
+26
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. warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Suggested change
be/src/vec/exec/format/table/iceberg/arrow_schema_util.h:47: - } // namespace iceberg
- } // namespace doris
+ } // namespace doris |
||||||||||||||
namespace iceberg { | ||||||||||||||
Comment on lines
+26
to
+27
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. warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Suggested change
be/src/vec/exec/format/table/iceberg/arrow_schema_util.h:48: - } // namespace iceberg
- } // namespace doris
+ } // namespace doris
Comment on lines
+26
to
+27
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. warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Suggested change
be/src/vec/exec/format/table/iceberg/arrow_schema_util.h:43: - } // namespace iceberg
- } // namespace doris
+ } // namespace doris |
||||||||||||||
|
||||||||||||||
class ArrowSchemaUtil { | ||||||||||||||
public: | ||||||||||||||
static Status convert(const Schema* schema, const std::string& timezone, | ||||||||||||||
std::vector<std::shared_ptr<arrow::Field>>& fields); | ||||||||||||||
|
||||||||||||||
private: | ||||||||||||||
static const char* PARQUET_FIELD_ID; | ||||||||||||||
static const char* ORIGINAL_TYPE; | ||||||||||||||
static const char* MAP_TYPE_VALUE; | ||||||||||||||
|
||||||||||||||
static Status convert_to(const iceberg::NestedField& field, | ||||||||||||||
std::shared_ptr<arrow::Field>* arrow_field, | ||||||||||||||
const std::string& timezone); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
} // namespace iceberg | ||||||||||||||
} // namespace doris |
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.
warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
be/src/vec/exec/format/table/iceberg/arrow_schema_util.cpp:132: