-
Notifications
You must be signed in to change notification settings - Fork 115
fix: validate transform parameters in metadata #757
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
| #include "iceberg/expression/term.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/transform_function.h" | ||
| #include "iceberg/transform_internal.h" | ||
| #include "iceberg/type.h" | ||
| #include "iceberg/util/base64.h" | ||
| #include "iceberg/util/checked_cast.h" | ||
|
|
@@ -232,6 +233,19 @@ bool Transform::CanTransform(const Type& source_type) const { | |
| std::unreachable(); | ||
| } | ||
|
|
||
| Status Transform::Validate(const std::shared_ptr<Type>& source_type) const { | ||
| if (!source_type) { | ||
| return InvalidArgument("Source type cannot be null for transform {}", ToString()); | ||
| } | ||
| // Keep type mismatches as InvalidArgument; Bind reports them as NotSupported. | ||
| if (!CanTransform(*source_type)) { | ||
| return InvalidArgument("Invalid source type {} for transform {}", | ||
| source_type->ToString(), ToString()); | ||
| } | ||
| ICEBERG_RETURN_UNEXPECTED(Bind(source_type)); | ||
|
Contributor
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. Worth a one-line comment on why both
Member
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. +1 |
||
| return {}; | ||
| } | ||
|
|
||
| bool Transform::PreservesOrder() const { | ||
| switch (transform_type_) { | ||
| case TransformType::kUnknown: | ||
|
|
@@ -554,9 +568,11 @@ Result<std::shared_ptr<Transform>> TransformFromString(std::string_view transfor | |
| StringUtils::ParseNumber<int32_t>(match[2].str())); | ||
|
|
||
| if (type_str == kBucketName) { | ||
| ICEBERG_RETURN_UNEXPECTED(internal::ValidateBucketTransformParameter(param)); | ||
| return Transform::Bucket(param); | ||
| } | ||
| if (type_str == kTruncateName) { | ||
| ICEBERG_RETURN_UNEXPECTED(internal::ValidateTruncateTransformParameter(param)); | ||
| return Transform::Truncate(param); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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 <cstdint> | ||
|
|
||
| #include "iceberg/result.h" | ||
|
|
||
| namespace iceberg::internal { | ||
|
|
||
| inline Status ValidateBucketTransformParameter(int32_t num_buckets) { | ||
|
Member
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. Can we avoid adding this new file? We can put these functions into |
||
| if (num_buckets <= 0) { | ||
| return InvalidArgument("Number of buckets must be positive, got {}", num_buckets); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| inline Status ValidateTruncateTransformParameter(int32_t width) { | ||
| if (width <= 0) { | ||
| return InvalidArgument("Width must be positive, got {}", width); | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| } // namespace iceberg::internal | ||
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.
Why not just use
const Type&as the input to save this check?