WZhuo commented on code in PR #1173: URL: https://github.com/apache/iceberg-cpp/pull/1173#discussion_r4794876611
########## src/iceberg/test/verification/partition_transforms_verification_test.cc: ########## @@ -0,0 +1,198 @@ +/* + * 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. + */ + +// Runs the `table-spec/partition-transforms` surface: binding `input.transform` to +// `input.source_type` yields one of `decoded.result_types`, and applying it to each +// of `input.values` yields the value at the same index of `decoded.values`. + +#include <algorithm> +#include <array> +#include <cstdint> +#include <exception> +#include <format> +#include <memory> +#include <string> +#include <string_view> +#include <vector> + +#include <gtest/gtest.h> +#include <nlohmann/json.hpp> + +#include "iceberg/expression/json_serde_internal.h" +#include "iceberg/expression/literal.h" +#include "iceberg/json_serde_internal.h" +#include "iceberg/result.h" +#include "iceberg/test/verification/verification_util.h" +#include "iceberg/transform.h" +#include "iceberg/type.h" +#include "iceberg/util/string_util.h" + +namespace iceberg::verification { + +namespace { + +constexpr std::array<std::string_view, 8> kSubdirs = { + "identity", "bucket", "truncate", "year", "month", "day", "hour", "void"}; + +constexpr std::string_view kTransform = "transform"; +constexpr std::string_view kSourceType = "source_type"; +constexpr std::string_view kValues = "values"; +constexpr std::string_view kResultTypes = "result_types"; + +/// \brief Decode a language-neutral value of this surface into a literal of `type`. +Result<Literal> DecodeValue(const nlohmann::json& json, + const std::shared_ptr<PrimitiveType>& type) { + if (json.is_null()) { + return Literal::Null(type); + } + switch (type->type_id()) { + case TypeId::kLong: { + // partition-transforms/README.md: "`long` values are decimal strings so JSON + // number handling cannot lose 64-bit precision." + if (!json.is_string()) { + return JsonParseError("long value {} is not a decimal string", json.dump()); + } + ICEBERG_ASSIGN_OR_RAISE(auto value, + StringUtils::ParseNumber<int64_t>(json.get<std::string>())); + return Literal::Long(value); + } + default: Review Comment: Thanks. These two failures are intentional. The spec defines float/double as a JSON number, so rejecting `0` is a bug in `LiteralFromJson`, not something the test should work around. Java has the same check and it is being fixed in apache/iceberg#19279 (dev@ thread: https://lists.apache.org/thread/1dn6c2ytq0qpwgvv2tqr9wvyswdxhh2t). I'll fix `LiteralFromJson` in a separate PR, and these cases will pass once it lands. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
