diff --git a/src/iceberg/expression/literal.cc b/src/iceberg/expression/literal.cc index 8392f34c..9ae39168 100644 --- a/src/iceberg/expression/literal.cc +++ b/src/iceberg/expression/literal.cc @@ -126,32 +126,22 @@ Literal::Literal(Value value, std::shared_ptr type) : value_(std::move(value)), type_(std::move(type)) {} // Factory methods -Literal Literal::Boolean(bool value) { - return {Value{value}, std::make_shared()}; -} +Literal Literal::Boolean(bool value) { return {Value{value}, iceberg::boolean()}; } -Literal Literal::Int(int32_t value) { - return {Value{value}, std::make_shared()}; -} +Literal Literal::Int(int32_t value) { return {Value{value}, iceberg::int32()}; } -Literal Literal::Long(int64_t value) { - return {Value{value}, std::make_shared()}; -} +Literal Literal::Long(int64_t value) { return {Value{value}, iceberg::int64()}; } -Literal Literal::Float(float value) { - return {Value{value}, std::make_shared()}; -} +Literal Literal::Float(float value) { return {Value{value}, iceberg::float32()}; } -Literal Literal::Double(double value) { - return {Value{value}, std::make_shared()}; -} +Literal Literal::Double(double value) { return {Value{value}, iceberg::float64()}; } Literal Literal::String(std::string value) { - return {Value{std::move(value)}, std::make_shared()}; + return {Value{std::move(value)}, iceberg::string()}; } Literal Literal::Binary(std::vector value) { - return {Value{std::move(value)}, std::make_shared()}; + return {Value{std::move(value)}, iceberg::binary()}; } Result Literal::Deserialize(std::span data, diff --git a/src/iceberg/manifest_entry.h b/src/iceberg/manifest_entry.h index 0b1355a7..8830d8e7 100644 --- a/src/iceberg/manifest_entry.h +++ b/src/iceberg/manifest_entry.h @@ -176,94 +176,90 @@ struct ICEBERG_EXPORT DataFile { std::optional content_size_in_bytes; inline static const SchemaField kContent = SchemaField::MakeRequired( - 134, "content", std::make_shared(), + 134, "content", iceberg::int32(), "Contents of the file: 0=data, 1=position deletes, 2=equality deletes"); inline static const SchemaField kFilePath = SchemaField::MakeRequired( - 100, "file_path", std::make_shared(), "Location URI with FS scheme"); - inline static const SchemaField kFileFormat = - SchemaField::MakeRequired(101, "file_format", std::make_shared(), - "File format name: avro, orc, or parquet"); + 100, "file_path", iceberg::string(), "Location URI with FS scheme"); + inline static const SchemaField kFileFormat = SchemaField::MakeRequired( + 101, "file_format", iceberg::int32(), "File format name: avro, orc, or parquet"); inline static const SchemaField kRecordCount = SchemaField::MakeRequired( - 103, "record_count", std::make_shared(), "Number of records in the file"); - inline static const SchemaField kFileSize = - SchemaField::MakeRequired(104, "file_size_in_bytes", std::make_shared(), - "Total file size in bytes"); + 103, "record_count", iceberg::int64(), "Number of records in the file"); + inline static const SchemaField kFileSize = SchemaField::MakeRequired( + 104, "file_size_in_bytes", iceberg::int64(), "Total file size in bytes"); inline static const SchemaField kColumnSizes = SchemaField::MakeOptional( 108, "column_sizes", std::make_shared( SchemaField::MakeRequired(117, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(118, std::string(MapType::kValueName), - std::make_shared())), + iceberg::int64())), "Map of column id to total size on disk"); inline static const SchemaField kValueCounts = SchemaField::MakeOptional( 109, "value_counts", std::make_shared( SchemaField::MakeRequired(119, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(120, std::string(MapType::kValueName), - std::make_shared())), + iceberg::int64())), "Map of column id to total count, including null and NaN"); inline static const SchemaField kNullValueCounts = SchemaField::MakeOptional( 110, "null_value_counts", std::make_shared( SchemaField::MakeRequired(121, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(122, std::string(MapType::kValueName), - std::make_shared())), + iceberg::int64())), "Map of column id to null value count"); inline static const SchemaField kNanValueCounts = SchemaField::MakeOptional( 137, "nan_value_counts", std::make_shared( SchemaField::MakeRequired(138, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(139, std::string(MapType::kValueName), - std::make_shared())), + iceberg::int64())), "Map of column id to number of NaN values in the column"); inline static const SchemaField kLowerBounds = SchemaField::MakeOptional( 125, "lower_bounds", std::make_shared( SchemaField::MakeRequired(126, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(127, std::string(MapType::kValueName), - std::make_shared())), + iceberg::binary())), "Map of column id to lower bound"); inline static const SchemaField kUpperBounds = SchemaField::MakeOptional( 128, "upper_bounds", std::make_shared( SchemaField::MakeRequired(129, std::string(MapType::kKeyName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeRequired(130, std::string(MapType::kValueName), - std::make_shared())), + iceberg::binary())), "Map of column id to upper bound"); - inline static const SchemaField kKeyMetadata = - SchemaField::MakeOptional(131, "key_metadata", std::make_shared(), - "Encryption key metadata blob"); + inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional( + 131, "key_metadata", iceberg::binary(), "Encryption key metadata blob"); inline static const SchemaField kSplitOffsets = SchemaField::MakeOptional( 132, "split_offsets", std::make_shared(SchemaField::MakeRequired( - 133, std::string(ListType::kElementName), std::make_shared())), + 133, std::string(ListType::kElementName), iceberg::int64())), "Splittable offsets"); inline static const SchemaField kEqualityIds = SchemaField::MakeOptional( 135, "equality_ids", std::make_shared(SchemaField::MakeRequired( - 136, std::string(ListType::kElementName), std::make_shared())), + 136, std::string(ListType::kElementName), iceberg::int32())), "Equality comparison field IDs"); - inline static const SchemaField kSortOrderId = SchemaField::MakeOptional( - 140, "sort_order_id", std::make_shared(), "Sort order ID"); - inline static const SchemaField kFirstRowId = - SchemaField::MakeOptional(142, "first_row_id", std::make_shared(), - "Starting row ID to assign to new rows"); + inline static const SchemaField kSortOrderId = + SchemaField::MakeOptional(140, "sort_order_id", iceberg::int32(), "Sort order ID"); + inline static const SchemaField kFirstRowId = SchemaField::MakeOptional( + 142, "first_row_id", iceberg::int64(), "Starting row ID to assign to new rows"); inline static const SchemaField kReferencedDataFile = SchemaField::MakeOptional( - 143, "referenced_data_file", std::make_shared(), + 143, "referenced_data_file", iceberg::string(), "Fully qualified location (URI with FS scheme) of a data file that all deletes " "reference"); inline static const SchemaField kContentOffset = - SchemaField::MakeOptional(144, "content_offset", std::make_shared(), + SchemaField::MakeOptional(144, "content_offset", iceberg::int64(), "The offset in the file where the content starts"); - inline static const SchemaField kContentSize = SchemaField::MakeOptional( - 145, "content_size_in_bytes", std::make_shared(), - "The length of referenced content stored in the file"); + inline static const SchemaField kContentSize = + SchemaField::MakeOptional(145, "content_size_in_bytes", iceberg::int64(), + "The length of referenced content stored in the file"); static std::shared_ptr Type(std::shared_ptr partition_type); }; @@ -293,13 +289,13 @@ struct ICEBERG_EXPORT ManifestEntry { DataFile data_file; inline static const SchemaField kStatus = - SchemaField::MakeRequired(0, "status", std::make_shared()); + SchemaField::MakeRequired(0, "status", iceberg::int32()); inline static const SchemaField kSnapshotId = - SchemaField::MakeOptional(1, "snapshot_id", std::make_shared()); + SchemaField::MakeOptional(1, "snapshot_id", iceberg::int64()); inline static const SchemaField kSequenceNumber = - SchemaField::MakeOptional(3, "sequence_number", std::make_shared()); + SchemaField::MakeOptional(3, "sequence_number", iceberg::int64()); inline static const SchemaField kFileSequenceNumber = - SchemaField::MakeOptional(4, "file_sequence_number", std::make_shared()); + SchemaField::MakeOptional(4, "file_sequence_number", iceberg::int64()); static std::shared_ptr TypeFromPartitionType( std::shared_ptr partition_type); diff --git a/src/iceberg/manifest_list.h b/src/iceberg/manifest_list.h index 432397ec..819f6a8f 100644 --- a/src/iceberg/manifest_list.h +++ b/src/iceberg/manifest_list.h @@ -54,17 +54,15 @@ struct ICEBERG_EXPORT PartitionFieldSummary { std::optional> upper_bound; inline static const SchemaField kContainsNull = - SchemaField::MakeRequired(509, "contains_null", std::make_shared(), + SchemaField::MakeRequired(509, "contains_null", iceberg::boolean(), "True if any file has a null partition value"); inline static const SchemaField kContainsNaN = - SchemaField::MakeOptional(518, "contains_nan", std::make_shared(), + SchemaField::MakeOptional(518, "contains_nan", iceberg::boolean(), "True if any file has a nan partition value"); - inline static const SchemaField kLowerBound = - SchemaField::MakeOptional(510, "lower_bound", std::make_shared(), - "Partition lower bound for all files"); - inline static const SchemaField kUpperBound = - SchemaField::MakeOptional(511, "upper_bound", std::make_shared(), - "Partition upper bound for all files"); + inline static const SchemaField kLowerBound = SchemaField::MakeOptional( + 510, "lower_bound", iceberg::binary(), "Partition lower bound for all files"); + inline static const SchemaField kUpperBound = SchemaField::MakeOptional( + 511, "upper_bound", iceberg::binary(), "Partition upper bound for all files"); static const StructType& Type(); }; @@ -150,48 +148,44 @@ struct ICEBERG_EXPORT ManifestFile { /// \brief Checks if this manifest file contains entries with DELETED status bool has_deleted_files() const { return deleted_files_count.value_or(1) > 0; } - inline static const SchemaField kManifestPath = - SchemaField::MakeRequired(500, "manifest_path", std::make_shared(), - "Location URI with FS scheme"); + inline static const SchemaField kManifestPath = SchemaField::MakeRequired( + 500, "manifest_path", iceberg::string(), "Location URI with FS scheme"); inline static const SchemaField kManifestLength = SchemaField::MakeRequired( - 501, "manifest_length", std::make_shared(), "Total file size in bytes"); + 501, "manifest_length", iceberg::int64(), "Total file size in bytes"); inline static const SchemaField kPartitionSpecId = SchemaField::MakeRequired( - 502, "partition_spec_id", std::make_shared(), "Spec ID used to write"); - inline static const SchemaField kContent = - SchemaField::MakeOptional(517, "content", std::make_shared(), - "Contents of the manifest: 0=data, 1=deletes"); + 502, "partition_spec_id", iceberg::int32(), "Spec ID used to write"); + inline static const SchemaField kContent = SchemaField::MakeOptional( + 517, "content", iceberg::int32(), "Contents of the manifest: 0=data, 1=deletes"); inline static const SchemaField kSequenceNumber = - SchemaField::MakeOptional(515, "sequence_number", std::make_shared(), + SchemaField::MakeOptional(515, "sequence_number", iceberg::int64(), "Sequence number when the manifest was added"); inline static const SchemaField kMinSequenceNumber = - SchemaField::MakeOptional(516, "min_sequence_number", std::make_shared(), + SchemaField::MakeOptional(516, "min_sequence_number", iceberg::int64(), "Lowest sequence number in the manifest"); - inline static const SchemaField kAddedSnapshotId = - SchemaField::MakeRequired(503, "added_snapshot_id", std::make_shared(), - "Snapshot ID that added the manifest"); + inline static const SchemaField kAddedSnapshotId = SchemaField::MakeRequired( + 503, "added_snapshot_id", iceberg::int64(), "Snapshot ID that added the manifest"); inline static const SchemaField kAddedFilesCount = SchemaField::MakeOptional( - 504, "added_files_count", std::make_shared(), "Added entry count"); + 504, "added_files_count", iceberg::int32(), "Added entry count"); inline static const SchemaField kExistingFilesCount = SchemaField::MakeOptional( - 505, "existing_files_count", std::make_shared(), "Existing entry count"); + 505, "existing_files_count", iceberg::int32(), "Existing entry count"); inline static const SchemaField kDeletedFilesCount = SchemaField::MakeOptional( - 506, "deleted_files_count", std::make_shared(), "Deleted entry count"); + 506, "deleted_files_count", iceberg::int32(), "Deleted entry count"); inline static const SchemaField kAddedRowsCount = SchemaField::MakeOptional( - 512, "added_rows_count", std::make_shared(), "Added rows count"); + 512, "added_rows_count", iceberg::int64(), "Added rows count"); inline static const SchemaField kExistingRowsCount = SchemaField::MakeOptional( - 513, "existing_rows_count", std::make_shared(), "Existing rows count"); + 513, "existing_rows_count", iceberg::int64(), "Existing rows count"); inline static const SchemaField kDeletedRowsCount = SchemaField::MakeOptional( - 514, "deleted_rows_count", std::make_shared(), "Deleted rows count"); + 514, "deleted_rows_count", iceberg::int64(), "Deleted rows count"); inline static const SchemaField kPartitions = SchemaField::MakeOptional( 507, "partitions", std::make_shared(SchemaField::MakeRequired( 508, std::string(ListType::kElementName), std::make_shared(PartitionFieldSummary::Type()))), "Summary for each partition"); - inline static const SchemaField kKeyMetadata = - SchemaField::MakeOptional(519, "key_metadata", std::make_shared(), - "Encryption key metadata blob"); + inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional( + 519, "key_metadata", iceberg::binary(), "Encryption key metadata blob"); inline static const SchemaField kFirstRowId = SchemaField::MakeOptional( - 520, "first_row_id", std::make_shared(), + 520, "first_row_id", iceberg::int64(), "Starting row ID to assign to new rows in ADDED data files"); static const StructType& Type(); diff --git a/src/iceberg/metadata_columns.h b/src/iceberg/metadata_columns.h index a12aa5ed..18aeb2b8 100644 --- a/src/iceberg/metadata_columns.h +++ b/src/iceberg/metadata_columns.h @@ -40,19 +40,18 @@ struct ICEBERG_EXPORT MetadataColumns { // IDs kInt32Max - (1-100) are used for metadata columns inline static const SchemaField kFilePath = - SchemaField::MakeRequired(kInt32Max - 1, "_file", std::make_shared(), + SchemaField::MakeRequired(kInt32Max - 1, "_file", iceberg::string(), "Path of the file in which a row is stored"); inline static const SchemaField kRowPosition = - SchemaField::MakeRequired(kInt32Max - 2, "_pos", std::make_shared(), + SchemaField::MakeRequired(kInt32Max - 2, "_pos", iceberg::int64(), "Ordinal position of a row in the source data file"); inline static const SchemaField kIsDeleted = SchemaField::MakeRequired( - kInt32Max - 3, "_deleted", std::make_shared(), - "Whether the row has been deleted"); + kInt32Max - 3, "_deleted", iceberg::binary(), "Whether the row has been deleted"); inline static const SchemaField kSpecId = - SchemaField::MakeRequired(kInt32Max - 4, "_spec_id", std::make_shared(), + SchemaField::MakeRequired(kInt32Max - 4, "_spec_id", iceberg::int32(), "Spec ID used to track the file containing a row"); // The partition column type depends on all specs in the table @@ -65,12 +64,12 @@ struct ICEBERG_EXPORT MetadataColumns { constexpr static int32_t kContentSizeInBytesColumnId = kInt32Max - 7; // IDs kInt32Max - (101-200) are used for reserved columns - inline static const SchemaField kDeleteFilePath = SchemaField::MakeRequired( - kInt32Max - 101, "file_path", std::make_shared(), - "Path of a file in which a deleted row is stored"); + inline static const SchemaField kDeleteFilePath = + SchemaField::MakeRequired(kInt32Max - 101, "file_path", iceberg::string(), + "Path of a file in which a deleted row is stored"); inline static const SchemaField kDeleteFilePos = - SchemaField::MakeRequired(kInt32Max - 102, "pos", std::make_shared(), + SchemaField::MakeRequired(kInt32Max - 102, "pos", iceberg::int64(), "Ordinal position of a deleted row in the data file"); // The row column type depends on the table schema @@ -79,23 +78,21 @@ struct ICEBERG_EXPORT MetadataColumns { constexpr static std::string_view kDeleteFileRowDoc = "Deleted row values"; inline static const SchemaField kChangeType = SchemaField::MakeRequired( - kInt32Max - 104, "_change_type", std::make_shared(), - "Record type in changelog"); + kInt32Max - 104, "_change_type", iceberg::string(), "Record type in changelog"); - inline static const SchemaField kChangeOrdinal = SchemaField::MakeOptional( - kInt32Max - 105, "_change_ordinal", std::make_shared(), - "Change ordinal in changelog"); + inline static const SchemaField kChangeOrdinal = + SchemaField::MakeOptional(kInt32Max - 105, "_change_ordinal", iceberg::int32(), + "Change ordinal in changelog"); - inline static const SchemaField kCommitSnapshotId = - SchemaField::MakeOptional(kInt32Max - 106, "_commit_snapshot_id", - std::make_shared(), "Commit snapshot ID"); + inline static const SchemaField kCommitSnapshotId = SchemaField::MakeOptional( + kInt32Max - 106, "_commit_snapshot_id", iceberg::int64(), "Commit snapshot ID"); inline static const SchemaField kRowId = - SchemaField::MakeOptional(kInt32Max - 107, "_row_id", std::make_shared(), + SchemaField::MakeOptional(kInt32Max - 107, "_row_id", iceberg::int64(), "Implicit row ID that is automatically assigned"); inline static const SchemaField kLastUpdatedSequenceNumber = SchemaField::MakeOptional( - kInt32Max - 108, "_last_updated_sequence_number", std::make_shared(), + kInt32Max - 108, "_last_updated_sequence_number", iceberg::int64(), "Sequence number when the row was last updated"); /// \brief Get the set of metadata field IDs. diff --git a/src/iceberg/schema_internal.cc b/src/iceberg/schema_internal.cc index 1ce279f7..fca6f01e 100644 --- a/src/iceberg/schema_internal.cc +++ b/src/iceberg/schema_internal.cc @@ -242,26 +242,25 @@ Result> FromArrowSchema(const ArrowSchema& schema) { return std::make_shared(std::move(*key_field), std::move(*value_field)); } case NANOARROW_TYPE_BOOL: - return std::make_shared(); + return iceberg::boolean(); case NANOARROW_TYPE_INT32: - return std::make_shared(); + return iceberg::int32(); case NANOARROW_TYPE_INT64: - return std::make_shared(); + return iceberg::int64(); case NANOARROW_TYPE_FLOAT: - return std::make_shared(); + return iceberg::float32(); case NANOARROW_TYPE_DOUBLE: - return std::make_shared(); + return iceberg::float64(); case NANOARROW_TYPE_DECIMAL128: - return std::make_shared(schema_view.decimal_precision, - schema_view.decimal_scale); + return iceberg::decimal(schema_view.decimal_precision, schema_view.decimal_scale); case NANOARROW_TYPE_DATE32: - return std::make_shared(); + return iceberg::date(); case NANOARROW_TYPE_TIME64: if (schema_view.time_unit != NANOARROW_TIME_UNIT_MICRO) { return InvalidSchema("Unsupported time unit for Arrow time type: {}", static_cast(schema_view.time_unit)); } - return std::make_shared(); + return iceberg::time(); case NANOARROW_TYPE_TIMESTAMP: { bool with_timezone = schema_view.timezone != nullptr && std::strlen(schema_view.timezone) > 0; @@ -270,15 +269,15 @@ Result> FromArrowSchema(const ArrowSchema& schema) { static_cast(schema_view.time_unit)); } if (with_timezone) { - return std::make_shared(); + return iceberg::timestamp_tz(); } else { - return std::make_shared(); + return iceberg::timestamp(); } } case NANOARROW_TYPE_STRING: - return std::make_shared(); + return iceberg::string(); case NANOARROW_TYPE_BINARY: - return std::make_shared(); + return iceberg::binary(); case NANOARROW_TYPE_FIXED_SIZE_BINARY: { if (auto extension_name = std::string_view(schema_view.extension_name.data, schema_view.extension_name.size_bytes); @@ -286,9 +285,9 @@ Result> FromArrowSchema(const ArrowSchema& schema) { if (schema_view.fixed_size != 16) { return InvalidSchema("UUID type must have a fixed size of 16"); } - return std::make_shared(); + return iceberg::uuid(); } - return std::make_shared(schema_view.fixed_size); + return iceberg::fixed(schema_view.fixed_size); } default: return InvalidSchema("Unsupported Arrow type: {}", diff --git a/src/iceberg/type.cc b/src/iceberg/type.cc index 5186e9c1..e66f96da 100644 --- a/src/iceberg/type.cc +++ b/src/iceberg/type.cc @@ -21,6 +21,7 @@ #include #include +#include #include "iceberg/exception.h" #include "iceberg/util/formatter.h" // IWYU pragma: keep @@ -286,4 +287,36 @@ TypeId BinaryType::type_id() const { return kTypeId; } std::string BinaryType::ToString() const { return "binary"; } bool BinaryType::Equals(const Type& other) const { return other.type_id() == kTypeId; } +// ---------------------------------------------------------------------- +// Factory functions for creating primitive data types + +#define TYPE_FACTORY(NAME, KLASS) \ + const std::shared_ptr& NAME() { \ + static std::shared_ptr result = std::make_shared(); \ + return result; \ + } + +TYPE_FACTORY(boolean, BooleanType) +TYPE_FACTORY(int32, IntType) +TYPE_FACTORY(int64, LongType) +TYPE_FACTORY(float32, FloatType) +TYPE_FACTORY(float64, DoubleType) +TYPE_FACTORY(date, DateType) +TYPE_FACTORY(time, TimeType) +TYPE_FACTORY(timestamp, TimestampType) +TYPE_FACTORY(timestamp_tz, TimestampTzType) +TYPE_FACTORY(binary, BinaryType) +TYPE_FACTORY(string, StringType) +TYPE_FACTORY(uuid, UuidType) + +#undef TYPE_FACTORY + +std::shared_ptr decimal(int32_t precision, int32_t scale) { + return std::make_shared(precision, scale); +} + +std::shared_ptr fixed(int32_t length) { + return std::make_shared(length); +} + } // namespace iceberg diff --git a/src/iceberg/type.h b/src/iceberg/type.h index 09e088f7..78c0141b 100644 --- a/src/iceberg/type.h +++ b/src/iceberg/type.h @@ -446,4 +446,47 @@ class ICEBERG_EXPORT UuidType : public PrimitiveType { /// @} +/// \defgroup type-factories Factory functions for creating primitive data types +/// +/// Factory functions for creating primitive data types +/// @{ + +/// \brief Return a BooleanType instance. +ICEBERG_EXPORT const std::shared_ptr& boolean(); +/// \brief Return an IntType instance. +ICEBERG_EXPORT const std::shared_ptr& int32(); +/// \brief Return a LongType instance. +ICEBERG_EXPORT const std::shared_ptr& int64(); +/// \brief Return a FloatType instance. +ICEBERG_EXPORT const std::shared_ptr& float32(); +/// \brief Return a DoubleType instance. +ICEBERG_EXPORT const std::shared_ptr& float64(); +/// \brief Return a DateType instance. +ICEBERG_EXPORT const std::shared_ptr& date(); +/// \brief Return a TimeType instance. +ICEBERG_EXPORT const std::shared_ptr& time(); +/// \brief Return a TimestampType instance. +ICEBERG_EXPORT const std::shared_ptr& timestamp(); +/// \brief Return a TimestampTzType instance. +ICEBERG_EXPORT const std::shared_ptr& timestamp_tz(); +/// \brief Return a BinaryType instance. +ICEBERG_EXPORT const std::shared_ptr& binary(); +/// \brief Return a StringType instance. +ICEBERG_EXPORT const std::shared_ptr& string(); +/// \brief Return a UuidType instance. +ICEBERG_EXPORT const std::shared_ptr& uuid(); + +/// \brief Create a DecimalType with the given precision and scale. +/// \param precision The number of decimal digits (max 38). +/// \param scale The number of decimal digits after the decimal point. +/// \return A shared pointer to the DecimalType instance. +ICEBERG_EXPORT std::shared_ptr decimal(int32_t precision, int32_t scale); + +/// \brief Create a FixedType with the given length. +/// \param length The number of bytes to store (must be >= 0). +/// \return A shared pointer to the FixedType instance. +ICEBERG_EXPORT std::shared_ptr fixed(int32_t length); + +/// @} + } // namespace iceberg diff --git a/test/arrow_test.cc b/test/arrow_test.cc index e8714e9e..1f13cb6d 100644 --- a/test/arrow_test.cc +++ b/test/arrow_test.cc @@ -105,35 +105,35 @@ TEST_P(ToArrowSchemaTest, PrimitiveType) { INSTANTIATE_TEST_SUITE_P( SchemaConversion, ToArrowSchemaTest, ::testing::Values( - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::boolean(), .optional = false, .arrow_type = ::arrow::boolean()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::int32(), .optional = true, .arrow_type = ::arrow::int32()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::int64(), .arrow_type = ::arrow::int64()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::float32(), .arrow_type = ::arrow::float32()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::float64(), .arrow_type = ::arrow::float64()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(10, 2), + ToArrowSchemaParam{.iceberg_type = iceberg::decimal(10, 2), .arrow_type = ::arrow::decimal128(10, 2)}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::date(), .arrow_type = ::arrow::date32()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::time(), .arrow_type = ::arrow::time64(arrow::TimeUnit::MICRO)}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::timestamp(), .arrow_type = ::arrow::timestamp(arrow::TimeUnit::MICRO)}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::timestamp(), .arrow_type = ::arrow::timestamp(arrow::TimeUnit::MICRO)}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::string(), .arrow_type = ::arrow::utf8()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::binary(), .arrow_type = ::arrow::binary()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(), + ToArrowSchemaParam{.iceberg_type = iceberg::uuid(), .arrow_type = ::arrow::extension::uuid()}, - ToArrowSchemaParam{.iceberg_type = std::make_shared(20), + ToArrowSchemaParam{.iceberg_type = iceberg::fixed(20), .arrow_type = ::arrow::fixed_size_binary(20)})); namespace { @@ -163,9 +163,9 @@ TEST(ToArrowSchemaTest, StructType) { auto struct_type = std::make_shared(std::vector{ SchemaField::MakeRequired(kIntFieldId, std::string(kIntFieldName), - std::make_shared()), + iceberg::int32()), SchemaField::MakeOptional(kStrFieldId, std::string(kStrFieldName), - std::make_shared())}); + iceberg::string())}); Schema schema({SchemaField::MakeRequired(kStructFieldId, std::string(kStructFieldName), struct_type)}, /*schema_id=*/0); @@ -197,7 +197,7 @@ TEST(ToArrowSchemaTest, ListType) { constexpr int32_t kElemFieldId = 2; auto list_type = std::make_shared(SchemaField::MakeOptional( - kElemFieldId, std::string(kElemFieldName), std::make_shared())); + kElemFieldId, std::string(kElemFieldName), iceberg::int64())); Schema schema( {SchemaField::MakeRequired(kListFieldId, std::string(kListFieldName), list_type)}, /*schema_id=*/0); @@ -229,9 +229,9 @@ TEST(ToArrowSchemaTest, MapType) { auto map_type = std::make_shared( SchemaField::MakeRequired(kKeyFieldId, std::string(kKeyFieldName), - std::make_shared()), + iceberg::string()), SchemaField::MakeOptional(kValueFieldId, std::string(kValueFieldName), - std::make_shared())); + iceberg::int32())); Schema schema( {SchemaField::MakeRequired(kFieldId, std::string(kMapFieldName), map_type)}, @@ -301,35 +301,35 @@ INSTANTIATE_TEST_SUITE_P( ::testing::Values( FromArrowSchemaParam{.arrow_type = ::arrow::boolean(), .optional = false, - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::boolean()}, FromArrowSchemaParam{.arrow_type = ::arrow::int32(), .optional = true, - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::int32()}, FromArrowSchemaParam{.arrow_type = ::arrow::int64(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::int64()}, FromArrowSchemaParam{.arrow_type = ::arrow::float32(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::float32()}, FromArrowSchemaParam{.arrow_type = ::arrow::float64(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::float64()}, FromArrowSchemaParam{.arrow_type = ::arrow::decimal128(10, 2), - .iceberg_type = std::make_shared(10, 2)}, + .iceberg_type = iceberg::decimal(10, 2)}, FromArrowSchemaParam{.arrow_type = ::arrow::date32(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::date()}, FromArrowSchemaParam{.arrow_type = ::arrow::time64(arrow::TimeUnit::MICRO), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::time()}, FromArrowSchemaParam{.arrow_type = ::arrow::timestamp(arrow::TimeUnit::MICRO), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::timestamp()}, FromArrowSchemaParam{ .arrow_type = ::arrow::timestamp(arrow::TimeUnit::MICRO, "UTC"), .iceberg_type = std::make_shared()}, FromArrowSchemaParam{.arrow_type = ::arrow::utf8(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::string()}, FromArrowSchemaParam{.arrow_type = ::arrow::binary(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::binary()}, FromArrowSchemaParam{.arrow_type = ::arrow::extension::uuid(), - .iceberg_type = std::make_shared()}, + .iceberg_type = iceberg::uuid()}, FromArrowSchemaParam{.arrow_type = ::arrow::fixed_size_binary(20), - .iceberg_type = std::make_shared(20)})); + .iceberg_type = iceberg::fixed(20)})); TEST(FromArrowSchemaTest, StructType) { constexpr int32_t kStructFieldId = 1; diff --git a/test/avro_data_test.cc b/test/avro_data_test.cc index 33b41773..45811ff5 100644 --- a/test/avro_data_test.cc +++ b/test/avro_data_test.cc @@ -117,8 +117,8 @@ TEST_P(AppendDatumToBuilderTest, PrimitiveType) { const std::vector kPrimitiveTestCases = { { .name = "Boolean", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::boolean(), + .source_type = iceberg::boolean(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = @@ -128,8 +128,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Int", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::int32(), + .source_type = iceberg::int32(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = i * 100; @@ -138,8 +138,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Long", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::int64(), + .source_type = iceberg::int64(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = @@ -149,8 +149,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Float", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::float32(), + .source_type = iceberg::float32(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = i * 3.14f; @@ -159,8 +159,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Double", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::float64(), + .source_type = iceberg::float64(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = @@ -170,8 +170,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "String", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::string(), + .source_type = iceberg::string(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = @@ -182,8 +182,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Binary", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::binary(), + .source_type = iceberg::binary(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>() @@ -196,8 +196,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Fixed", - .projected_type = std::make_shared(4), - .source_type = std::make_shared(4), + .projected_type = iceberg::fixed(4), + .source_type = iceberg::fixed(4), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>() @@ -213,8 +213,8 @@ const std::vector kPrimitiveTestCases = { /// extension. Need to fix this in the upstream Arrow. // { // .name = "UUID", - // .projected_type = std::make_shared(), - // .source_type = std::make_shared(), + // .projected_type = iceberg::uuid(), + // .source_type = iceberg::uuid(), // .value_setter = // [](::avro::GenericDatum& datum, int i) { // datum.value<::avro::GenericRecord>() @@ -229,8 +229,8 @@ const std::vector kPrimitiveTestCases = { // }, { .name = "Decimal", - .projected_type = std::make_shared(10, 2), - .source_type = std::make_shared(10, 2), + .projected_type = iceberg::decimal(10, 2), + .source_type = iceberg::decimal(10, 2), .value_setter = [](::avro::GenericDatum& datum, int i) { int32_t decimal_value = i * 1000 + i; @@ -249,8 +249,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Date", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::date(), + .source_type = iceberg::date(), .value_setter = [](::avro::GenericDatum& datum, int i) { // Date as days since epoch (1970-01-01) @@ -262,8 +262,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Time", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::time(), + .source_type = iceberg::time(), .value_setter = [](::avro::GenericDatum& datum, int i) { // Time as microseconds since midnight @@ -276,8 +276,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "Timestamp", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::timestamp(), + .source_type = iceberg::timestamp(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = @@ -299,8 +299,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "IntToLongPromotion", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::int64(), + .source_type = iceberg::int32(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = i * 100; @@ -309,8 +309,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "FloatToDoublePromotion", - .projected_type = std::make_shared(), - .source_type = std::make_shared(), + .projected_type = iceberg::float64(), + .source_type = iceberg::float32(), .value_setter = [](::avro::GenericDatum& datum, int i) { datum.value<::avro::GenericRecord>().fieldAt(0).value() = i * 1.0f; @@ -319,8 +319,8 @@ const std::vector kPrimitiveTestCases = { }, { .name = "DecimalPrecisionPromotion", - .projected_type = std::make_shared(10, 2), - .source_type = std::make_shared(6, 2), + .projected_type = iceberg::decimal(10, 2), + .source_type = iceberg::decimal(6, 2), .value_setter = [](::avro::GenericDatum& datum, int i) { int32_t decimal_value = i * 1000 + i; @@ -345,8 +345,8 @@ INSTANTIATE_TEST_SUITE_P(AllPrimitiveTypes, AppendDatumToBuilderTest, TEST(AppendDatumToBuilderTest, StructWithTwoFields) { Schema iceberg_schema({ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "name", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int32()), + SchemaField::MakeRequired(2, "name", iceberg::string()), }); ::avro::NodePtr avro_node; ASSERT_THAT(ToAvroNodeVisitor{}.Visit(iceberg_schema, &avro_node), IsOk()); @@ -364,12 +364,12 @@ TEST(AppendDatumToBuilderTest, StructWithTwoFields) { TEST(AppendDatumToBuilderTest, NestedStruct) { Schema iceberg_schema({ - SchemaField::MakeRequired(1, "id", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int32()), SchemaField::MakeRequired( 2, "person", std::make_shared(std::vector{ - SchemaField::MakeRequired(3, "name", std::make_shared()), - SchemaField::MakeRequired(4, "age", std::make_shared()), + SchemaField::MakeRequired(3, "name", iceberg::string()), + SchemaField::MakeRequired(4, "age", iceberg::int32()), })), }); @@ -404,7 +404,7 @@ TEST(AppendDatumToBuilderTest, ListOfIntegers) { Schema iceberg_schema({ SchemaField::MakeRequired(1, "numbers", std::make_shared(SchemaField::MakeRequired( - 2, "element", std::make_shared()))), + 2, "element", iceberg::int32()))), }); ::avro::NodePtr avro_node; @@ -441,8 +441,8 @@ TEST(AppendDatumToBuilderTest, ListOfStructs) { std::make_shared(SchemaField::MakeRequired( 2, "element", std::make_shared(std::vector{ - SchemaField::MakeRequired(3, "name", std::make_shared()), - SchemaField::MakeRequired(4, "age", std::make_shared()), + SchemaField::MakeRequired(3, "name", iceberg::string()), + SchemaField::MakeRequired(4, "age", iceberg::int32()), })))), }); @@ -486,8 +486,8 @@ TEST(AppendDatumToBuilderTest, MapStringToInt) { SchemaField::MakeRequired( 1, "scores", std::make_shared( - SchemaField::MakeRequired(2, "key", std::make_shared()), - SchemaField::MakeRequired(3, "value", std::make_shared()))), + SchemaField::MakeRequired(2, "key", iceberg::string()), + SchemaField::MakeRequired(3, "value", iceberg::int32()))), }); ::avro::NodePtr avro_node; @@ -523,8 +523,8 @@ TEST(AppendDatumToBuilderTest, MapIntToStringAsArray) { SchemaField::MakeRequired( 1, "names", std::make_shared( - SchemaField::MakeRequired(2, "key", std::make_shared()), - SchemaField::MakeRequired(3, "value", std::make_shared()))), + SchemaField::MakeRequired(2, "key", iceberg::int32()), + SchemaField::MakeRequired(3, "value", iceberg::string()))), }); ::avro::NodePtr avro_node; @@ -560,13 +560,12 @@ TEST(AppendDatumToBuilderTest, MapStringToStruct) { SchemaField::MakeRequired( 1, "users", std::make_shared( - SchemaField::MakeRequired(2, "key", std::make_shared()), + SchemaField::MakeRequired(2, "key", iceberg::string()), SchemaField::MakeRequired( 3, "value", std::make_shared(std::vector{ - SchemaField::MakeRequired(4, "id", std::make_shared()), - SchemaField::MakeRequired(5, "email", - std::make_shared()), + SchemaField::MakeRequired(4, "id", iceberg::int32()), + SchemaField::MakeRequired(5, "email", iceberg::string()), })))), }); @@ -602,12 +601,12 @@ TEST(AppendDatumToBuilderTest, MapStringToStruct) { TEST(AppendDatumToBuilderTest, StructWithMissingOptionalField) { Schema iceberg_schema({ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "name", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int32()), + SchemaField::MakeRequired(2, "name", iceberg::string()), SchemaField::MakeOptional(3, "age", - std::make_shared()), // Missing in Avro + iceberg::int32()), // Missing in Avro SchemaField::MakeOptional(4, "email", - std::make_shared()), // Missing in Avro + iceberg::string()), // Missing in Avro }); // Create Avro schema that only has id and name fields (missing age and email) @@ -640,18 +639,18 @@ TEST(AppendDatumToBuilderTest, StructWithMissingOptionalField) { TEST(AppendDatumToBuilderTest, NestedStructWithMissingOptionalFields) { Schema iceberg_schema({ - SchemaField::MakeRequired(1, "id", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int32()), SchemaField::MakeRequired( 2, "person", std::make_shared(std::vector{ - SchemaField::MakeRequired(3, "name", std::make_shared()), + SchemaField::MakeRequired(3, "name", iceberg::string()), SchemaField::MakeOptional(4, "age", - std::make_shared()), // Missing + iceberg::int32()), // Missing SchemaField::MakeOptional(5, "phone", - std::make_shared()), // Missing + iceberg::string()), // Missing })), SchemaField::MakeOptional(6, "department", - std::make_shared()), // Missing + iceberg::string()), // Missing }); // Create Avro schema with only id, person.name fields @@ -699,13 +698,11 @@ TEST(AppendDatumToBuilderTest, ListWithMissingOptionalElementFields) { std::make_shared(SchemaField::MakeRequired( 2, "element", std::make_shared(std::vector{ - SchemaField::MakeRequired(3, "name", std::make_shared()), - SchemaField::MakeOptional( - 4, "age", - std::make_shared()), // Missing in Avro - SchemaField::MakeOptional( - 5, "email", - std::make_shared()), // Missing in Avro + SchemaField::MakeRequired(3, "name", iceberg::string()), + SchemaField::MakeOptional(4, "age", + iceberg::int32()), // Missing in Avro + SchemaField::MakeOptional(5, "email", + iceberg::string()), // Missing in Avro })))), }); diff --git a/test/avro_schema_test.cc b/test/avro_schema_test.cc index 7d18ae81..875bfe95 100644 --- a/test/avro_schema_test.cc +++ b/test/avro_schema_test.cc @@ -155,11 +155,10 @@ TEST(ToAvroNodeVisitorTest, BinaryType) { } TEST(ToAvroNodeVisitorTest, StructType) { - StructType struct_type{ - {SchemaField{/*field_id=*/1, "bool_field", std::make_shared(), - /*optional=*/false}, - SchemaField{/*field_id=*/2, "int_field", std::make_shared(), - /*optional=*/true}}}; + StructType struct_type{{SchemaField{/*field_id=*/1, "bool_field", iceberg::boolean(), + /*optional=*/false}, + SchemaField{/*field_id=*/2, "int_field", iceberg::int32(), + /*optional=*/true}}}; ::avro::NodePtr node; EXPECT_THAT(ToAvroNodeVisitor{}.Visit(struct_type, &node), IsOk()); @@ -182,8 +181,7 @@ TEST(ToAvroNodeVisitorTest, StructType) { } TEST(ToAvroNodeVisitorTest, ListType) { - ListType list_type{SchemaField{/*field_id=*/5, "element", - std::make_shared(), + ListType list_type{SchemaField{/*field_id=*/5, "element", iceberg::string(), /*optional=*/true}}; ::avro::NodePtr node; @@ -202,9 +200,9 @@ TEST(ToAvroNodeVisitorTest, ListType) { } TEST(ToAvroNodeVisitorTest, MapTypeWithStringKey) { - MapType map_type{SchemaField{/*field_id=*/10, "key", std::make_shared(), + MapType map_type{SchemaField{/*field_id=*/10, "key", iceberg::string(), /*optional=*/false}, - SchemaField{/*field_id=*/11, "value", std::make_shared(), + SchemaField{/*field_id=*/11, "value", iceberg::int32(), /*optional=*/false}}; ::avro::NodePtr node; @@ -223,9 +221,9 @@ TEST(ToAvroNodeVisitorTest, MapTypeWithStringKey) { } TEST(ToAvroNodeVisitorTest, MapTypeWithNonStringKey) { - MapType map_type{SchemaField{/*field_id=*/10, "key", std::make_shared(), + MapType map_type{SchemaField{/*field_id=*/10, "key", iceberg::int32(), /*optional=*/false}, - SchemaField{/*field_id=*/11, "value", std::make_shared(), + SchemaField{/*field_id=*/11, "value", iceberg::string(), /*optional=*/false}}; ::avro::NodePtr node; @@ -252,9 +250,9 @@ TEST(ToAvroNodeVisitorTest, MapTypeWithNonStringKey) { } TEST(ToAvroNodeVisitorTest, InvalidMapKeyType) { - MapType map_type{SchemaField{/*field_id=*/1, "key", std::make_shared(), + MapType map_type{SchemaField{/*field_id=*/1, "key", iceberg::string(), /*optional=*/true}, - SchemaField{/*field_id=*/2, "value", std::make_shared(), + SchemaField{/*field_id=*/2, "value", iceberg::string(), /*optional=*/false}}; ::avro::NodePtr node; @@ -265,12 +263,12 @@ TEST(ToAvroNodeVisitorTest, InvalidMapKeyType) { TEST(ToAvroNodeVisitorTest, NestedTypes) { auto inner_struct = std::make_shared(std::vector{ - SchemaField{/*field_id=*/2, "string_field", std::make_shared(), + SchemaField{/*field_id=*/2, "string_field", iceberg::string(), /*optional=*/false}, - SchemaField{/*field_id=*/3, "int_field", std::make_shared(), + SchemaField{/*field_id=*/3, "int_field", iceberg::int32(), /*optional=*/true}}); auto inner_list = std::make_shared(SchemaField{/*field_id=*/5, "element", - std::make_shared(), + iceberg::float64(), /*optional=*/false}); StructType root_struct{{SchemaField{/*field_id=*/1, "struct_field", inner_struct, /*optional=*/false}, @@ -520,10 +518,10 @@ TEST(HasIdVisitorTest, ArrayBackedMapWithPartialIds) { TEST(AvroSchemaProjectionTest, ProjectIdenticalSchemas) { // Create an iceberg schema Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/4, "data", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), + SchemaField::MakeRequired(/*field_id=*/4, "data", iceberg::float64()), }); // Create equivalent avro schema @@ -554,8 +552,8 @@ TEST(AvroSchemaProjectionTest, ProjectIdenticalSchemas) { TEST(AvroSchemaProjectionTest, ProjectSubsetSchema) { // Create a subset iceberg schema Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), }); // Create full avro schema @@ -586,8 +584,8 @@ TEST(AvroSchemaProjectionTest, ProjectSubsetSchema) { TEST(AvroSchemaProjectionTest, ProjectWithPruning) { // Create a subset iceberg schema Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), }); // Create full avro schema @@ -618,9 +616,9 @@ TEST(AvroSchemaProjectionTest, ProjectWithPruning) { TEST(AvroSchemaProjectionTest, ProjectMissingOptionalField) { // Create iceberg schema with an extra optional field Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/10, "extra", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/10, "extra", iceberg::string()), }); // Create avro schema without the extra field @@ -650,9 +648,9 @@ TEST(AvroSchemaProjectionTest, ProjectMissingOptionalField) { TEST(AvroSchemaProjectionTest, ProjectMissingRequiredField) { // Create iceberg schema with a required field that's missing from the avro schema Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/10, "extra", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeRequired(/*field_id=*/10, "extra", iceberg::string()), }); std::string avro_schema_json = R"({ @@ -674,7 +672,7 @@ TEST(AvroSchemaProjectionTest, ProjectMissingRequiredField) { TEST(AvroSchemaProjectionTest, ProjectMetadataColumn) { // Create iceberg schema with a metadata column Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), MetadataColumns::kFilePath, }); @@ -701,7 +699,7 @@ TEST(AvroSchemaProjectionTest, ProjectMetadataColumn) { TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionIntToLong) { // Create iceberg schema expecting a long Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), }); // Create avro schema with an int @@ -727,7 +725,7 @@ TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionIntToLong) { TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionFloatToDouble) { // Create iceberg schema expecting a double Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "value", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "value", iceberg::float64()), }); // Create avro schema with a float @@ -753,7 +751,7 @@ TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionFloatToDouble) { TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionIncompatibleTypes) { // Create iceberg schema expecting an int Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "value", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "value", iceberg::int32()), }); // Create avro schema with a string @@ -775,14 +773,12 @@ TEST(AvroSchemaProjectionTest, ProjectSchemaEvolutionIncompatibleTypes) { TEST(AvroSchemaProjectionTest, ProjectNestedStructures) { // Create iceberg schema with nested struct Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional( /*field_id=*/3, "address", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/101, "street", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/102, "city", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/101, "street", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/102, "city", iceberg::string()), })), }); @@ -826,11 +822,11 @@ TEST(AvroSchemaProjectionTest, ProjectNestedStructures) { TEST(AvroSchemaProjectionTest, ProjectListType) { // Create iceberg schema with a list Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional( /*field_id=*/2, "numbers", std::make_shared(SchemaField::MakeOptional( - /*field_id=*/101, "element", std::make_shared()))), + /*field_id=*/101, "element", iceberg::int32()))), }); // Create equivalent avro schema @@ -866,10 +862,8 @@ TEST(AvroSchemaProjectionTest, ProjectMapType) { SchemaField::MakeOptional( /*field_id=*/1, "counts", std::make_shared( - SchemaField::MakeRequired(/*field_id=*/101, "key", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/102, "value", - std::make_shared()))), + SchemaField::MakeRequired(/*field_id=*/101, "key", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/102, "value", iceberg::int32()))), }); // Create equivalent avro schema @@ -904,10 +898,8 @@ TEST(AvroSchemaProjectionTest, ProjectMapTypeWithNonStringKey) { SchemaField::MakeOptional( /*field_id=*/1, "counts", std::make_shared( - SchemaField::MakeRequired(/*field_id=*/101, "key", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/102, "value", - std::make_shared()))), + SchemaField::MakeRequired(/*field_id=*/101, "key", iceberg::int32()), + SchemaField::MakeOptional(/*field_id=*/102, "value", iceberg::string()))), }); // Create equivalent avro schema (using array-backed map for non-string keys) @@ -950,10 +942,8 @@ TEST(AvroSchemaProjectionTest, ProjectListOfStruct) { std::make_shared(SchemaField::MakeOptional( /*field_id=*/101, "element", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/102, "x", - std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/103, "y", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/102, "x", iceberg::int32()), + SchemaField::MakeRequired(/*field_id=*/103, "y", iceberg::string()), })))), }); @@ -1000,8 +990,7 @@ TEST(AvroSchemaProjectionTest, ProjectListOfStruct) { TEST(AvroSchemaProjectionTest, ProjectDecimalType) { // Create iceberg schema with decimal Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "value", - std::make_shared(18, 2)), + SchemaField::MakeRequired(/*field_id=*/1, "value", iceberg::decimal(18, 2)), }); // Create avro schema with decimal @@ -1038,8 +1027,7 @@ TEST(AvroSchemaProjectionTest, ProjectDecimalType) { TEST(AvroSchemaProjectionTest, ProjectDecimalIncompatible) { // Create iceberg schema with decimal having different scale Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "value", - std::make_shared(18, 3)), + SchemaField::MakeRequired(/*field_id=*/1, "value", iceberg::decimal(18, 3)), }); // Create avro schema with decimal diff --git a/test/json_internal_test.cc b/test/json_internal_test.cc index 75d14224..69ed10bb 100644 --- a/test/json_internal_test.cc +++ b/test/json_internal_test.cc @@ -141,9 +141,8 @@ TEST(JsonPartitionTest, PartitionFieldFromJsonMissingField) { TEST(JsonPartitionTest, PartitionSpec) { auto schema = std::make_shared( - std::vector{ - SchemaField(3, "region", std::make_shared(), false), - SchemaField(5, "ts", std::make_shared(), false)}, + std::vector{SchemaField(3, "region", iceberg::string(), false), + SchemaField(5, "ts", iceberg::int64(), false)}, /*schema_id=*/100); auto identity_transform = Transform::Identity(); diff --git a/test/literal_test.cc b/test/literal_test.cc index 6821c569..e9ddd47a 100644 --- a/test/literal_test.cc +++ b/test/literal_test.cc @@ -78,18 +78,18 @@ TEST(LiteralTest, IntCastTo) { auto int_literal = Literal::Int(42); // Cast to Long - auto long_result = int_literal.CastTo(std::make_shared()); + auto long_result = int_literal.CastTo(iceberg::int64()); ASSERT_THAT(long_result, IsOk()); EXPECT_EQ(long_result->type()->type_id(), TypeId::kLong); EXPECT_EQ(long_result->ToString(), "42"); // Cast to Float - auto float_result = int_literal.CastTo(std::make_shared()); + auto float_result = int_literal.CastTo(iceberg::float32()); ASSERT_THAT(float_result, IsOk()); EXPECT_EQ(float_result->type()->type_id(), TypeId::kFloat); // Cast to Double - auto double_result = int_literal.CastTo(std::make_shared()); + auto double_result = int_literal.CastTo(iceberg::float64()); ASSERT_THAT(double_result, IsOk()); EXPECT_EQ(double_result->type()->type_id(), TypeId::kDouble); } @@ -120,18 +120,18 @@ TEST(LiteralTest, LongCastTo) { auto long_literal = Literal::Long(42L); // Cast to Int (within range) - auto int_result = long_literal.CastTo(std::make_shared()); + auto int_result = long_literal.CastTo(iceberg::int32()); ASSERT_THAT(int_result, IsOk()); EXPECT_EQ(int_result->type()->type_id(), TypeId::kInt); EXPECT_EQ(int_result->ToString(), "42"); // Cast to Float - auto float_result = long_literal.CastTo(std::make_shared()); + auto float_result = long_literal.CastTo(iceberg::float32()); ASSERT_THAT(float_result, IsOk()); EXPECT_EQ(float_result->type()->type_id(), TypeId::kFloat); // Cast to Double - auto double_result = long_literal.CastTo(std::make_shared()); + auto double_result = long_literal.CastTo(iceberg::float64()); ASSERT_THAT(double_result, IsOk()); EXPECT_EQ(double_result->type()->type_id(), TypeId::kDouble); } @@ -143,11 +143,11 @@ TEST(LiteralTest, LongCastToIntOverflow) { auto min_long = Literal::Long(static_cast(std::numeric_limits::min()) - 1); - auto max_result = max_long.CastTo(std::make_shared()); + auto max_result = max_long.CastTo(iceberg::int32()); ASSERT_THAT(max_result, IsOk()); EXPECT_TRUE(max_result->IsAboveMax()); - auto min_result = min_long.CastTo(std::make_shared()); + auto min_result = min_long.CastTo(iceberg::int32()); ASSERT_THAT(min_result, IsOk()); EXPECT_TRUE(min_result->IsBelowMin()); } @@ -178,7 +178,7 @@ TEST(LiteralTest, FloatCastTo) { auto float_literal = Literal::Float(3.14f); // Cast to Double - auto double_result = float_literal.CastTo(std::make_shared()); + auto double_result = float_literal.CastTo(iceberg::float64()); ASSERT_THAT(double_result, IsOk()); EXPECT_EQ(double_result->type()->type_id(), TypeId::kDouble); } @@ -275,7 +275,7 @@ TEST(LiteralTest, SpecialValues) { TEST(LiteralTest, SameTypeCast) { auto int_literal = Literal::Int(42); - auto same_type_result = int_literal.CastTo(std::make_shared()); + auto same_type_result = int_literal.CastTo(iceberg::int32()); ASSERT_THAT(same_type_result, IsOk()); EXPECT_EQ(same_type_result->type()->type_id(), TypeId::kInt); EXPECT_EQ(same_type_result->ToString(), "42"); diff --git a/test/metadata_io_test.cc b/test/metadata_io_test.cc index 432101b0..c50f6a10 100644 --- a/test/metadata_io_test.cc +++ b/test/metadata_io_test.cc @@ -46,7 +46,7 @@ class MetadataIOTest : public TempFileTestBase { TableMetadata PrepareMetadata() { std::vector schema_fields; - schema_fields.emplace_back(/*field_id=*/1, "x", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/1, "x", iceberg::int64(), /*optional=*/false); auto schema = std::make_shared(std::move(schema_fields), /*schema_id=*/1); diff --git a/test/metadata_serde_test.cc b/test/metadata_serde_test.cc index 4c78f652..9070503c 100644 --- a/test/metadata_serde_test.cc +++ b/test/metadata_serde_test.cc @@ -62,11 +62,11 @@ TEST_F(MetadataSerdeTest, DeserializeV1Valid) { // Compare schema EXPECT_EQ(metadata->current_schema_id, std::nullopt); std::vector schema_fields; - schema_fields.emplace_back(/*field_id=*/1, "x", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/1, "x", iceberg::int64(), /*optional=*/false); - schema_fields.emplace_back(/*field_id=*/2, "y", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/2, "y", iceberg::int64(), /*optional=*/false); - schema_fields.emplace_back(/*field_id=*/3, "z", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/3, "z", iceberg::int64(), /*optional=*/false); auto expected_schema = std::make_shared(schema_fields, /*schema_id=*/std::nullopt); @@ -100,11 +100,11 @@ TEST_F(MetadataSerdeTest, DeserializeV2Valid) { // Compare schema EXPECT_EQ(metadata->current_schema_id, 1); std::vector schema_fields; - schema_fields.emplace_back(/*field_id=*/1, "x", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/1, "x", iceberg::int64(), /*optional=*/false); - schema_fields.emplace_back(/*field_id=*/2, "y", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/2, "y", iceberg::int64(), /*optional=*/false); - schema_fields.emplace_back(/*field_id=*/3, "z", std::make_shared(), + schema_fields.emplace_back(/*field_id=*/3, "z", iceberg::int64(), /*optional=*/false); auto expected_schema = std::make_shared(std::move(schema_fields), /*schema_id=*/1); diff --git a/test/name_mapping_test.cc b/test/name_mapping_test.cc index 8896212a..53c9fe00 100644 --- a/test/name_mapping_test.cc +++ b/test/name_mapping_test.cc @@ -205,8 +205,8 @@ TEST_F(NameMappingTest, ToString) { TEST(CreateMappingTest, FlatSchemaToMapping) { Schema schema(std::vector{ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "data", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int64()), + SchemaField::MakeRequired(2, "data", iceberg::string()), }); auto expected = MappedFields::Make({ @@ -221,13 +221,13 @@ TEST(CreateMappingTest, FlatSchemaToMapping) { TEST(CreateMappingTest, NestedStructSchemaToMapping) { Schema schema(std::vector{ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "data", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int64()), + SchemaField::MakeRequired(2, "data", iceberg::string()), SchemaField::MakeRequired( 3, "location", std::make_shared(std::vector{ - SchemaField::MakeRequired(4, "latitude", std::make_shared()), - SchemaField::MakeRequired(5, "longitude", std::make_shared()), + SchemaField::MakeRequired(4, "latitude", iceberg::float32()), + SchemaField::MakeRequired(5, "longitude", iceberg::float32()), })), }); @@ -249,13 +249,13 @@ TEST(CreateMappingTest, NestedStructSchemaToMapping) { TEST(CreateMappingTest, MapSchemaToMapping) { Schema schema(std::vector{ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "data", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int64()), + SchemaField::MakeRequired(2, "data", iceberg::string()), SchemaField::MakeRequired( 3, "map", std::make_shared( - SchemaField::MakeRequired(4, "key", std::make_shared()), - SchemaField::MakeRequired(5, "value", std::make_shared()))), + SchemaField::MakeRequired(4, "key", iceberg::string()), + SchemaField::MakeRequired(5, "value", iceberg::float64()))), }); auto expected = MappedFields::Make({ @@ -276,11 +276,11 @@ TEST(CreateMappingTest, MapSchemaToMapping) { TEST(CreateMappingTest, ListSchemaToMapping) { Schema schema(std::vector{ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeRequired(2, "data", std::make_shared()), + SchemaField::MakeRequired(1, "id", iceberg::int64()), + SchemaField::MakeRequired(2, "data", iceberg::string()), SchemaField::MakeRequired(3, "list", std::make_shared(SchemaField::MakeRequired( - 4, "element", std::make_shared()))), + 4, "element", iceberg::string()))), }); auto expected = MappedFields::Make({ diff --git a/test/partition_spec_test.cc b/test/partition_spec_test.cc index c9f4d3ac..d4a3f46d 100644 --- a/test/partition_spec_test.cc +++ b/test/partition_spec_test.cc @@ -35,8 +35,8 @@ namespace iceberg { TEST(PartitionSpecTest, Basics) { { - SchemaField field1(5, "ts", std::make_shared(), true); - SchemaField field2(7, "bar", std::make_shared(), true); + SchemaField field1(5, "ts", iceberg::timestamp(), true); + SchemaField field2(7, "bar", iceberg::string(), true); auto const schema = std::make_shared(std::vector{field1, field2}, 100); @@ -60,8 +60,8 @@ TEST(PartitionSpecTest, Basics) { } TEST(PartitionSpecTest, Equality) { - SchemaField field1(5, "ts", std::make_shared(), true); - SchemaField field2(7, "bar", std::make_shared(), true); + SchemaField field1(5, "ts", iceberg::timestamp(), true); + SchemaField field2(7, "bar", iceberg::string(), true); auto const schema = std::make_shared(std::vector{field1, field2}, 100); auto identity_transform = Transform::Identity(); diff --git a/test/schema_field_test.cc b/test/schema_field_test.cc index a03cc531..bc0dbbdf 100644 --- a/test/schema_field_test.cc +++ b/test/schema_field_test.cc @@ -29,7 +29,7 @@ TEST(SchemaFieldTest, Basics) { { - iceberg::SchemaField field(1, "foo", std::make_shared(), false); + iceberg::SchemaField field(1, "foo", iceberg::int32(), false); EXPECT_EQ(1, field.field_id()); EXPECT_EQ("foo", field.name()); EXPECT_EQ(iceberg::TypeId::kInt, field.type()->type_id()); @@ -60,12 +60,12 @@ TEST(SchemaFieldTest, Basics) { } TEST(SchemaFieldTest, Equality) { - iceberg::SchemaField field1(1, "foo", std::make_shared(), false); - iceberg::SchemaField field2(2, "foo", std::make_shared(), false); - iceberg::SchemaField field3(1, "bar", std::make_shared(), false); + iceberg::SchemaField field1(1, "foo", iceberg::int32(), false); + iceberg::SchemaField field2(2, "foo", iceberg::int32(), false); + iceberg::SchemaField field3(1, "bar", iceberg::int32(), false); iceberg::SchemaField field4(1, "foo", std::make_shared(), false); - iceberg::SchemaField field5(1, "foo", std::make_shared(), true); - iceberg::SchemaField field6(1, "foo", std::make_shared(), false); + iceberg::SchemaField field5(1, "foo", iceberg::int32(), true); + iceberg::SchemaField field6(1, "foo", iceberg::int32(), false); ASSERT_EQ(field1, field1); ASSERT_NE(field1, field2); @@ -82,8 +82,7 @@ TEST(SchemaFieldTest, Equality) { TEST(SchemaFieldTest, WithDoc) { { - iceberg::SchemaField field(/*field_id=*/1, /*name=*/"foo", - std::make_shared(), + iceberg::SchemaField field(/*field_id=*/1, /*name=*/"foo", iceberg::int32(), /*optional=*/false, /*doc=*/"Field documentation"); EXPECT_EQ(1, field.field_id()); EXPECT_EQ("foo", field.name()); diff --git a/test/schema_json_test.cc b/test/schema_json_test.cc index c6549ab2..1e934cce 100644 --- a/test/schema_json_test.cc +++ b/test/schema_json_test.cc @@ -55,40 +55,38 @@ TEST_P(TypeJsonTest, SingleTypeRoundTrip) { INSTANTIATE_TEST_SUITE_P( JsonSerailization, TypeJsonTest, ::testing::Values( - SchemaJsonParam{.json = "\"boolean\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"int\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"long\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"float\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"double\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"string\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"binary\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"uuid\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"fixed[8]\"", .type = std::make_shared(8)}, - SchemaJsonParam{.json = "\"decimal(10,2)\"", - .type = std::make_shared(10, 2)}, - SchemaJsonParam{.json = "\"date\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"time\"", .type = std::make_shared()}, - SchemaJsonParam{.json = "\"timestamp\"", - .type = std::make_shared()}, + SchemaJsonParam{.json = "\"boolean\"", .type = iceberg::boolean()}, + SchemaJsonParam{.json = "\"int\"", .type = iceberg::int32()}, + SchemaJsonParam{.json = "\"long\"", .type = iceberg::int64()}, + SchemaJsonParam{.json = "\"float\"", .type = iceberg::float32()}, + SchemaJsonParam{.json = "\"double\"", .type = iceberg::float64()}, + SchemaJsonParam{.json = "\"string\"", .type = iceberg::string()}, + SchemaJsonParam{.json = "\"binary\"", .type = iceberg::binary()}, + SchemaJsonParam{.json = "\"uuid\"", .type = iceberg::uuid()}, + SchemaJsonParam{.json = "\"fixed[8]\"", .type = iceberg::fixed(8)}, + SchemaJsonParam{.json = "\"decimal(10,2)\"", .type = iceberg::decimal(10, 2)}, + SchemaJsonParam{.json = "\"date\"", .type = iceberg::date()}, + SchemaJsonParam{.json = "\"time\"", .type = iceberg::time()}, + SchemaJsonParam{.json = "\"timestamp\"", .type = iceberg::timestamp()}, SchemaJsonParam{.json = "\"timestamptz\"", .type = std::make_shared()}, SchemaJsonParam{ .json = R"({"element":"string","element-id":3,"element-required":true,"type":"list"})", .type = std::make_shared( - SchemaField::MakeRequired(3, "element", std::make_shared()))}, + SchemaField::MakeRequired(3, "element", iceberg::string()))}, SchemaJsonParam{ .json = R"({"key":"string","key-id":4,"type":"map","value":"double","value-id":5,"value-required":false})", .type = std::make_shared( - SchemaField::MakeRequired(4, "key", std::make_shared()), - SchemaField::MakeOptional(5, "value", std::make_shared()))}, + SchemaField::MakeRequired(4, "key", iceberg::string()), + SchemaField::MakeOptional(5, "value", iceberg::float64()))}, SchemaJsonParam{ .json = R"({"fields":[{"id":1,"name":"id","required":true,"type":"int"},{"id":2,"name":"name","required":false,"type":"string"}],"type":"struct"})", .type = std::make_shared(std::vector{ - SchemaField::MakeRequired(1, "id", std::make_shared()), - SchemaField::MakeOptional(2, "name", std::make_shared())})})); + SchemaField::MakeRequired(1, "id", iceberg::int32()), + SchemaField::MakeOptional(2, "name", iceberg::string())})})); TEST(TypeJsonTest, FromJsonWithSpaces) { auto fixed_json = R"("fixed[ 8 ]")"; diff --git a/test/schema_test.cc b/test/schema_test.cc index 1017f17a..93239597 100644 --- a/test/schema_test.cc +++ b/test/schema_test.cc @@ -30,8 +30,8 @@ TEST(SchemaTest, Basics) { { - iceberg::SchemaField field1(5, "foo", std::make_shared(), true); - iceberg::SchemaField field2(7, "bar", std::make_shared(), true); + iceberg::SchemaField field1(5, "foo", iceberg::int32(), true); + iceberg::SchemaField field2(7, "bar", iceberg::string(), true); iceberg::Schema schema({field1, field2}, 100); ASSERT_EQ(schema, schema); ASSERT_EQ(100, schema.schema_id()); @@ -53,9 +53,8 @@ TEST(SchemaTest, Basics) { } ASSERT_THAT( []() { - iceberg::SchemaField field1(5, "foo", std::make_shared(), true); - iceberg::SchemaField field2(5, "bar", std::make_shared(), - true); + iceberg::SchemaField field1(5, "foo", iceberg::int32(), true); + iceberg::SchemaField field2(5, "bar", iceberg::string(), true); iceberg::Schema schema({field1, field2}, 100); }, ::testing::ThrowsMessage( @@ -63,9 +62,9 @@ TEST(SchemaTest, Basics) { } TEST(SchemaTest, Equality) { - iceberg::SchemaField field1(5, "foo", std::make_shared(), true); - iceberg::SchemaField field2(7, "bar", std::make_shared(), true); - iceberg::SchemaField field3(5, "foobar", std::make_shared(), true); + iceberg::SchemaField field1(5, "foo", iceberg::int32(), true); + iceberg::SchemaField field2(7, "bar", iceberg::string(), true); + iceberg::SchemaField field3(5, "foobar", iceberg::int32(), true); iceberg::Schema schema1({field1, field2}, 100); iceberg::Schema schema2({field1, field2}, 101); iceberg::Schema schema3({field1}, 101); diff --git a/test/schema_util_test.cc b/test/schema_util_test.cc index 3d8e0acb..e124061d 100644 --- a/test/schema_util_test.cc +++ b/test/schema_util_test.cc @@ -42,10 +42,10 @@ void AssertProjectedField(const FieldProjection& projection, size_t expected_ind Schema CreateFlatSchema() { return Schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/4, "data", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), + SchemaField::MakeRequired(/*field_id=*/4, "data", iceberg::float64()), }); } @@ -53,36 +53,31 @@ std::shared_ptr CreateListOfStruct() { return std::make_shared(SchemaField::MakeOptional( /*field_id=*/101, "element", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/102, "x", std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/103, "y", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/102, "x", iceberg::int32()), + SchemaField::MakeRequired(/*field_id=*/103, "y", iceberg::string()), }))); } std::shared_ptr CreateMapWithStructValue() { return std::make_shared( - SchemaField::MakeRequired(/*field_id=*/201, "key", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/201, "key", iceberg::string()), SchemaField::MakeRequired( /*field_id=*/202, "value", std::make_shared(std::vector{ - SchemaField::MakeRequired(/*field_id=*/203, "id", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/204, "name", - std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/203, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/204, "name", iceberg::string()), }))); } std::shared_ptr CreateNestedStruct() { return std::make_shared(std::vector{ - SchemaField::MakeRequired(/*field_id=*/301, "outer_id", - std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/301, "outer_id", iceberg::int64()), SchemaField::MakeRequired( /*field_id=*/302, "nested", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/303, "inner_id", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/303, "inner_id", iceberg::int32()), SchemaField::MakeRequired(/*field_id=*/304, "inner_name", - std::make_shared()), + iceberg::string()), })), }); } @@ -91,16 +86,16 @@ std::shared_ptr CreateListOfList() { return std::make_shared(SchemaField::MakeRequired( /*field_id=*/401, "element", std::make_shared(SchemaField::MakeOptional( - /*field_id=*/402, "element", std::make_shared())))); + /*field_id=*/402, "element", iceberg::float64())))); } std::shared_ptr CreateMapOfList() { return std::make_shared( - SchemaField::MakeRequired(/*field_id=*/501, "key", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/501, "key", iceberg::string()), SchemaField::MakeRequired( /*field_id=*/502, "value", std::make_shared(SchemaField::MakeOptional( - /*field_id=*/503, "element", std::make_shared())))); + /*field_id=*/503, "element", iceberg::int32())))); } } // namespace @@ -121,8 +116,8 @@ TEST(SchemaUtilTest, ProjectIdenticalSchemas) { TEST(SchemaUtilTest, ProjectSubsetSchema) { Schema source_schema = CreateFlatSchema(); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), }); auto projection_result = @@ -138,8 +133,8 @@ TEST(SchemaUtilTest, ProjectSubsetSchema) { TEST(SchemaUtilTest, ProjectWithPruning) { Schema source_schema = CreateFlatSchema(); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/3, "age", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/3, "age", iceberg::int32()), }); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/true); @@ -154,9 +149,9 @@ TEST(SchemaUtilTest, ProjectWithPruning) { TEST(SchemaUtilTest, ProjectMissingOptionalField) { Schema source_schema = CreateFlatSchema(); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/10, "extra", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/10, "extra", iceberg::string()), }); auto projection_result = Project(expected_schema, source_schema, false); @@ -173,9 +168,9 @@ TEST(SchemaUtilTest, ProjectMissingOptionalField) { TEST(SchemaUtilTest, ProjectMissingRequiredField) { Schema source_schema = CreateFlatSchema(); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), - SchemaField::MakeRequired(/*field_id=*/10, "extra", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), + SchemaField::MakeRequired(/*field_id=*/10, "extra", iceberg::string()), }); auto projection_result = @@ -187,7 +182,7 @@ TEST(SchemaUtilTest, ProjectMissingRequiredField) { TEST(SchemaUtilTest, ProjectMetadataColumn) { Schema source_schema = CreateFlatSchema(); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), MetadataColumns::kFilePath, }); @@ -203,9 +198,9 @@ TEST(SchemaUtilTest, ProjectMetadataColumn) { TEST(SchemaUtilTest, ProjectSchemaEvolutionIntToLong) { Schema source_schema( - {SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared())}); + {SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int32())}); Schema expected_schema( - {SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared())}); + {SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64())}); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/false); @@ -217,10 +212,10 @@ TEST(SchemaUtilTest, ProjectSchemaEvolutionIntToLong) { } TEST(SchemaUtilTest, ProjectSchemaEvolutionFloatToDouble) { - Schema source_schema({SchemaField::MakeOptional(/*field_id=*/2, "value", - std::make_shared())}); - Schema expected_schema({SchemaField::MakeOptional(/*field_id=*/2, "value", - std::make_shared())}); + Schema source_schema( + {SchemaField::MakeOptional(/*field_id=*/2, "value", iceberg::float32())}); + Schema expected_schema( + {SchemaField::MakeOptional(/*field_id=*/2, "value", iceberg::float64())}); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/false); @@ -232,10 +227,10 @@ TEST(SchemaUtilTest, ProjectSchemaEvolutionFloatToDouble) { } TEST(SchemaUtilTest, ProjectSchemaEvolutionDecimalCompatible) { - Schema source_schema({SchemaField::MakeOptional(/*field_id=*/2, "value", - std::make_shared(9, 2))}); + Schema source_schema( + {SchemaField::MakeOptional(/*field_id=*/2, "value", iceberg::decimal(9, 2))}); Schema expected_schema({SchemaField::MakeOptional( - /*field_id=*/2, "value", std::make_shared(18, 2))}); + /*field_id=*/2, "value", iceberg::decimal(18, 2))}); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/false); @@ -247,10 +242,10 @@ TEST(SchemaUtilTest, ProjectSchemaEvolutionDecimalCompatible) { } TEST(SchemaUtilTest, ProjectSchemaEvolutionDecimalIncompatible) { - Schema source_schema({SchemaField::MakeOptional(/*field_id=*/2, "value", - std::make_shared(9, 2))}); + Schema source_schema( + {SchemaField::MakeOptional(/*field_id=*/2, "value", iceberg::decimal(9, 2))}); Schema expected_schema({SchemaField::MakeOptional( - /*field_id=*/2, "value", std::make_shared(18, 3))}); + /*field_id=*/2, "value", iceberg::decimal(18, 3))}); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/false); @@ -259,10 +254,10 @@ TEST(SchemaUtilTest, ProjectSchemaEvolutionDecimalIncompatible) { } TEST(SchemaUtilTest, ProjectSchemaEvolutionIncompatibleTypes) { - Schema source_schema({SchemaField::MakeOptional(/*field_id=*/1, "value", - std::make_shared())}); + Schema source_schema( + {SchemaField::MakeOptional(/*field_id=*/1, "value", iceberg::string())}); Schema expected_schema( - {SchemaField::MakeOptional(/*field_id=*/1, "value", std::make_shared())}); + {SchemaField::MakeOptional(/*field_id=*/1, "value", iceberg::int32())}); auto projection_result = Project(expected_schema, source_schema, /*prune_source=*/false); @@ -272,15 +267,13 @@ TEST(SchemaUtilTest, ProjectSchemaEvolutionIncompatibleTypes) { TEST(SchemaUtilTest, ProjectNestedStructures) { Schema schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), SchemaField::MakeOptional( /*field_id=*/3, "address", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/101, "street", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/102, "city", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/101, "street", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/102, "city", iceberg::string()), })), }); @@ -303,29 +296,24 @@ TEST(SchemaUtilTest, ProjectNestedStructures) { TEST(SchemaUtilTest, ProjectSubsetNestedFields) { Schema source_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/2, "name", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), + SchemaField::MakeOptional(/*field_id=*/2, "name", iceberg::string()), SchemaField::MakeOptional( /*field_id=*/3, "address", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/101, "street", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/102, "city", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/103, "zip", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/101, "street", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/102, "city", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/103, "zip", iceberg::string()), })), }); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional( /*field_id=*/3, "address", std::make_shared(std::vector{ - SchemaField::MakeOptional(/*field_id=*/102, "city", - std::make_shared()), - SchemaField::MakeOptional(/*field_id=*/101, "street", - std::make_shared()), + SchemaField::MakeOptional(/*field_id=*/102, "city", iceberg::string()), + SchemaField::MakeOptional(/*field_id=*/101, "street", iceberg::string()), })), }); @@ -347,7 +335,7 @@ TEST(SchemaUtilTest, ProjectSubsetNestedFields) { TEST(SchemaUtilTest, ProjectListOfStruct) { Schema source_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional(/*field_id=*/2, "items", CreateListOfStruct()), }); @@ -378,7 +366,7 @@ TEST(SchemaUtilTest, ProjectListOfStruct) { /*field_id=*/101, "element", std::make_shared( std::vector{SchemaField::MakeRequired( - /*field_id=*/103, "y", std::make_shared())})))), + /*field_id=*/103, "y", iceberg::string())})))), }); auto projection_result = @@ -399,7 +387,7 @@ TEST(SchemaUtilTest, ProjectListOfStruct) { TEST(SchemaUtilTest, ProjectMapWithStructValue) { Schema source_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional(/*field_id=*/2, "attributes", CreateMapWithStructValue()), }); Schema expected_schema({ @@ -420,13 +408,13 @@ TEST(SchemaUtilTest, ProjectMapWithStructValue) { TEST(SchemaUtilTest, ProjectComplexMixedTypes) { Schema source_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeOptional(/*field_id=*/2, "lists", CreateListOfStruct()), SchemaField::MakeRequired(/*field_id=*/3, "mappings", CreateMapWithStructValue()), SchemaField::MakeOptional(/*field_id=*/4, "nested", CreateNestedStruct()), }); Schema expected_schema({ - SchemaField::MakeRequired(/*field_id=*/1, "id", std::make_shared()), + SchemaField::MakeRequired(/*field_id=*/1, "id", iceberg::int64()), SchemaField::MakeRequired(/*field_id=*/3, "mappings", CreateMapWithStructValue()), }); diff --git a/test/sort_order_test.cc b/test/sort_order_test.cc index c759e921..590f30bb 100644 --- a/test/sort_order_test.cc +++ b/test/sort_order_test.cc @@ -33,8 +33,8 @@ namespace iceberg { TEST(SortOrderTest, Basics) { { - SchemaField field1(5, "ts", std::make_shared(), true); - SchemaField field2(7, "bar", std::make_shared(), true); + SchemaField field1(5, "ts", iceberg::timestamp(), true); + SchemaField field2(7, "bar", iceberg::string(), true); auto identity_transform = Transform::Identity(); SortField st_field1(5, identity_transform, SortDirection::kAscending, @@ -59,8 +59,8 @@ TEST(SortOrderTest, Basics) { } TEST(SortOrderTest, Equality) { - SchemaField field1(5, "ts", std::make_shared(), true); - SchemaField field2(7, "bar", std::make_shared(), true); + SchemaField field1(5, "ts", iceberg::timestamp(), true); + SchemaField field2(7, "bar", iceberg::string(), true); auto bucket_transform = Transform::Bucket(8); auto identity_transform = Transform::Identity(); SortField st_field1(5, identity_transform, SortDirection::kAscending, diff --git a/test/transform_test.cc b/test/transform_test.cc index f4c68a69..2f06eb7a 100644 --- a/test/transform_test.cc +++ b/test/transform_test.cc @@ -37,7 +37,7 @@ TEST(TransformTest, Transform) { EXPECT_EQ("identity", transform->ToString()); EXPECT_EQ("identity", std::format("{}", *transform)); - auto source_type = std::make_shared(); + auto source_type = iceberg::string(); auto identity_transform = transform->Bind(source_type); ASSERT_TRUE(identity_transform); @@ -54,7 +54,7 @@ TEST(TransformFunctionTest, CreateBucketTransform) { EXPECT_EQ("bucket[8]", transform->ToString()); EXPECT_EQ("bucket[8]", std::format("{}", *transform)); - const auto transformPtr = transform->Bind(std::make_shared()); + const auto transformPtr = transform->Bind(iceberg::string()); ASSERT_TRUE(transformPtr); EXPECT_EQ(transformPtr.value()->transform_type(), TransformType::kBucket); } @@ -65,7 +65,7 @@ TEST(TransformFunctionTest, CreateTruncateTransform) { EXPECT_EQ("truncate[16]", transform->ToString()); EXPECT_EQ("truncate[16]", std::format("{}", *transform)); - auto transformPtr = transform->Bind(std::make_shared()); + auto transformPtr = transform->Bind(iceberg::string()); EXPECT_EQ(transformPtr.value()->transform_type(), TransformType::kTruncate); } TEST(TransformFromStringTest, PositiveCases) { diff --git a/test/type_test.cc b/test/type_test.cc index c3717537..fca88692 100644 --- a/test/type_test.cc +++ b/test/type_test.cc @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -91,112 +90,112 @@ TEST_P(TypeTest, StdFormat) { const static std::array kPrimitiveTypes = {{ { .name = "boolean", - .type = std::make_shared(), + .type = iceberg::boolean(), .type_id = iceberg::TypeId::kBoolean, .primitive = true, .repr = "boolean", }, { .name = "int", - .type = std::make_shared(), + .type = iceberg::int32(), .type_id = iceberg::TypeId::kInt, .primitive = true, .repr = "int", }, { .name = "long", - .type = std::make_shared(), + .type = iceberg::int64(), .type_id = iceberg::TypeId::kLong, .primitive = true, .repr = "long", }, { .name = "float", - .type = std::make_shared(), + .type = iceberg::float32(), .type_id = iceberg::TypeId::kFloat, .primitive = true, .repr = "float", }, { .name = "double", - .type = std::make_shared(), + .type = iceberg::float64(), .type_id = iceberg::TypeId::kDouble, .primitive = true, .repr = "double", }, { .name = "decimal9_2", - .type = std::make_shared(9, 2), + .type = iceberg::decimal(9, 2), .type_id = iceberg::TypeId::kDecimal, .primitive = true, .repr = "decimal(9, 2)", }, { .name = "decimal38_10", - .type = std::make_shared(38, 10), + .type = iceberg::decimal(38, 10), .type_id = iceberg::TypeId::kDecimal, .primitive = true, .repr = "decimal(38, 10)", }, { .name = "date", - .type = std::make_shared(), + .type = iceberg::date(), .type_id = iceberg::TypeId::kDate, .primitive = true, .repr = "date", }, { .name = "time", - .type = std::make_shared(), + .type = iceberg::time(), .type_id = iceberg::TypeId::kTime, .primitive = true, .repr = "time", }, { .name = "timestamp", - .type = std::make_shared(), + .type = iceberg::timestamp(), .type_id = iceberg::TypeId::kTimestamp, .primitive = true, .repr = "timestamp", }, { .name = "timestamptz", - .type = std::make_shared(), + .type = iceberg::timestamp_tz(), .type_id = iceberg::TypeId::kTimestampTz, .primitive = true, .repr = "timestamptz", }, { .name = "binary", - .type = std::make_shared(), + .type = iceberg::binary(), .type_id = iceberg::TypeId::kBinary, .primitive = true, .repr = "binary", }, { .name = "string", - .type = std::make_shared(), + .type = iceberg::string(), .type_id = iceberg::TypeId::kString, .primitive = true, .repr = "string", }, { .name = "fixed10", - .type = std::make_shared(10), + .type = iceberg::fixed(10), .type_id = iceberg::TypeId::kFixed, .primitive = true, .repr = "fixed(10)", }, { .name = "fixed255", - .type = std::make_shared(255), + .type = iceberg::fixed(255), .type_id = iceberg::TypeId::kFixed, .primitive = true, .repr = "fixed(255)", }, { .name = "uuid", - .type = std::make_shared(), + .type = iceberg::uuid(), .type_id = iceberg::TypeId::kUuid, .primitive = true, .repr = "uuid", @@ -206,8 +205,7 @@ const static std::array kPrimitiveTypes = {{ const static std::array kNestedTypes = {{ { .name = "list_int", - .type = std::make_shared( - 1, std::make_shared(), true), + .type = std::make_shared(1, iceberg::int32(), true), .type_id = iceberg::TypeId::kList, .primitive = false, .repr = "list", @@ -215,10 +213,7 @@ const static std::array kNestedTypes = {{ { .name = "list_list_int", .type = std::make_shared( - 1, - std::make_shared(2, std::make_shared(), - true), - false), + 1, std::make_shared(2, iceberg::int32(), true), false), .type_id = iceberg::TypeId::kList, .primitive = false, .repr = "list (required)>", @@ -226,10 +221,8 @@ const static std::array kNestedTypes = {{ { .name = "map_int_string", .type = std::make_shared( - iceberg::SchemaField::MakeRequired(1, "key", - std::make_shared()), - iceberg::SchemaField::MakeRequired(2, "value", - std::make_shared())), + iceberg::SchemaField::MakeRequired(1, "key", iceberg::int64()), + iceberg::SchemaField::MakeRequired(2, "value", iceberg::string())), .type_id = iceberg::TypeId::kMap, .primitive = false, .repr = "map", @@ -237,10 +230,8 @@ const static std::array kNestedTypes = {{ { .name = "struct", .type = std::make_shared(std::vector{ - iceberg::SchemaField::MakeRequired(1, "foo", - std::make_shared()), - iceberg::SchemaField::MakeOptional(2, "bar", - std::make_shared()), + iceberg::SchemaField::MakeRequired(1, "foo", iceberg::int64()), + iceberg::SchemaField::MakeOptional(2, "bar", iceberg::string()), }), .type_id = iceberg::TypeId::kStruct, .primitive = false, @@ -319,7 +310,7 @@ TEST(TypeTest, Fixed) { TEST(TypeTest, List) { { - iceberg::SchemaField field(5, "element", std::make_shared(), true); + iceberg::SchemaField field(5, "element", iceberg::int32(), true); iceberg::ListType list(field); std::span fields = list.fields(); ASSERT_EQ(1, fields.size()); @@ -335,8 +326,8 @@ TEST(TypeTest, List) { } ASSERT_THAT( []() { - iceberg::ListType list(iceberg::SchemaField( - 1, "wrongname", std::make_shared(), true)); + iceberg::ListType list( + iceberg::SchemaField(1, "wrongname", iceberg::boolean(), true)); }, ::testing::ThrowsMessage( ::testing::HasSubstr("child field name should be 'element', was 'wrongname'"))); @@ -344,8 +335,8 @@ TEST(TypeTest, List) { TEST(TypeTest, Map) { { - iceberg::SchemaField key(5, "key", std::make_shared(), true); - iceberg::SchemaField value(7, "value", std::make_shared(), true); + iceberg::SchemaField key(5, "key", iceberg::int32(), true); + iceberg::SchemaField value(7, "value", iceberg::string(), true); iceberg::MapType map(key, value); std::span fields = map.fields(); ASSERT_EQ(2, fields.size()); @@ -365,18 +356,16 @@ TEST(TypeTest, Map) { } ASSERT_THAT( []() { - iceberg::SchemaField key(5, "notkey", std::make_shared(), true); - iceberg::SchemaField value(7, "value", std::make_shared(), - true); + iceberg::SchemaField key(5, "notkey", iceberg::int32(), true); + iceberg::SchemaField value(7, "value", iceberg::string(), true); iceberg::MapType map(key, value); }, ::testing::ThrowsMessage( ::testing::HasSubstr("key field name should be 'key', was 'notkey'"))); ASSERT_THAT( []() { - iceberg::SchemaField key(5, "key", std::make_shared(), true); - iceberg::SchemaField value(7, "notvalue", std::make_shared(), - true); + iceberg::SchemaField key(5, "key", iceberg::int32(), true); + iceberg::SchemaField value(7, "notvalue", iceberg::string(), true); iceberg::MapType map(key, value); }, ::testing::ThrowsMessage( @@ -385,8 +374,8 @@ TEST(TypeTest, Map) { TEST(TypeTest, Struct) { { - iceberg::SchemaField field1(5, "foo", std::make_shared(), true); - iceberg::SchemaField field2(7, "bar", std::make_shared(), true); + iceberg::SchemaField field1(5, "foo", iceberg::int32(), true); + iceberg::SchemaField field2(7, "bar", iceberg::string(), true); iceberg::StructType struct_({field1, field2}); std::span fields = struct_.fields(); ASSERT_EQ(2, fields.size()); @@ -406,9 +395,8 @@ TEST(TypeTest, Struct) { } ASSERT_THAT( []() { - iceberg::SchemaField field1(5, "foo", std::make_shared(), true); - iceberg::SchemaField field2(5, "bar", std::make_shared(), - true); + iceberg::SchemaField field1(5, "foo", iceberg::int32(), true); + iceberg::SchemaField field2(5, "bar", iceberg::string(), true); iceberg::StructType struct_({field1, field2}); }, ::testing::ThrowsMessage( diff --git a/test/visit_type_test.cc b/test/visit_type_test.cc index afd5bf01..6eb0aafc 100644 --- a/test/visit_type_test.cc +++ b/test/visit_type_test.cc @@ -56,112 +56,112 @@ std::string TypeTestCaseToString(const ::testing::TestParamInfo& i const static std::array kPrimitiveTypes = {{ { .name = "boolean", - .type = std::make_shared(), + .type = iceberg::boolean(), .type_id = iceberg::TypeId::kBoolean, .primitive = true, .repr = "boolean", }, { .name = "int", - .type = std::make_shared(), + .type = iceberg::int32(), .type_id = iceberg::TypeId::kInt, .primitive = true, .repr = "int", }, { .name = "long", - .type = std::make_shared(), + .type = iceberg::int64(), .type_id = iceberg::TypeId::kLong, .primitive = true, .repr = "long", }, { .name = "float", - .type = std::make_shared(), + .type = iceberg::float32(), .type_id = iceberg::TypeId::kFloat, .primitive = true, .repr = "float", }, { .name = "double", - .type = std::make_shared(), + .type = iceberg::float64(), .type_id = iceberg::TypeId::kDouble, .primitive = true, .repr = "double", }, { .name = "decimal9_2", - .type = std::make_shared(9, 2), + .type = iceberg::decimal(9, 2), .type_id = iceberg::TypeId::kDecimal, .primitive = true, .repr = "decimal(9, 2)", }, { .name = "decimal38_10", - .type = std::make_shared(38, 10), + .type = iceberg::decimal(38, 10), .type_id = iceberg::TypeId::kDecimal, .primitive = true, .repr = "decimal(38, 10)", }, { .name = "date", - .type = std::make_shared(), + .type = iceberg::date(), .type_id = iceberg::TypeId::kDate, .primitive = true, .repr = "date", }, { .name = "time", - .type = std::make_shared(), + .type = iceberg::time(), .type_id = iceberg::TypeId::kTime, .primitive = true, .repr = "time", }, { .name = "timestamp", - .type = std::make_shared(), + .type = iceberg::timestamp(), .type_id = iceberg::TypeId::kTimestamp, .primitive = true, .repr = "timestamp", }, { .name = "timestamptz", - .type = std::make_shared(), + .type = iceberg::timestamp_tz(), .type_id = iceberg::TypeId::kTimestampTz, .primitive = true, .repr = "timestamptz", }, { .name = "binary", - .type = std::make_shared(), + .type = iceberg::binary(), .type_id = iceberg::TypeId::kBinary, .primitive = true, .repr = "binary", }, { .name = "string", - .type = std::make_shared(), + .type = iceberg::string(), .type_id = iceberg::TypeId::kString, .primitive = true, .repr = "string", }, { .name = "fixed10", - .type = std::make_shared(10), + .type = iceberg::fixed(10), .type_id = iceberg::TypeId::kFixed, .primitive = true, .repr = "fixed(10)", }, { .name = "fixed255", - .type = std::make_shared(255), + .type = iceberg::fixed(255), .type_id = iceberg::TypeId::kFixed, .primitive = true, .repr = "fixed(255)", }, { .name = "uuid", - .type = std::make_shared(), + .type = iceberg::uuid(), .type_id = iceberg::TypeId::kUuid, .primitive = true, .repr = "uuid", @@ -171,8 +171,7 @@ const static std::array kPrimitiveTypes = {{ const static std::array kNestedTypes = {{ { .name = "list_int", - .type = std::make_shared( - 1, std::make_shared(), true), + .type = std::make_shared(1, iceberg::int32(), true), .type_id = iceberg::TypeId::kList, .primitive = false, .repr = "list", @@ -180,10 +179,7 @@ const static std::array kNestedTypes = {{ { .name = "list_list_int", .type = std::make_shared( - 1, - std::make_shared(2, std::make_shared(), - true), - false), + 1, std::make_shared(2, iceberg::int32(), true), false), .type_id = iceberg::TypeId::kList, .primitive = false, .repr = "list (required)>", @@ -191,10 +187,8 @@ const static std::array kNestedTypes = {{ { .name = "map_int_string", .type = std::make_shared( - iceberg::SchemaField::MakeRequired(1, "key", - std::make_shared()), - iceberg::SchemaField::MakeRequired(2, "value", - std::make_shared())), + iceberg::SchemaField::MakeRequired(1, "key", iceberg::int64()), + iceberg::SchemaField::MakeRequired(2, "value", iceberg::string())), .type_id = iceberg::TypeId::kMap, .primitive = false, .repr = "map", @@ -202,10 +196,8 @@ const static std::array kNestedTypes = {{ { .name = "struct", .type = std::make_shared(std::vector{ - iceberg::SchemaField::MakeRequired(1, "foo", - std::make_shared()), - iceberg::SchemaField::MakeOptional(2, "bar", - std::make_shared()), + iceberg::SchemaField::MakeRequired(1, "foo", iceberg::int64()), + iceberg::SchemaField::MakeOptional(2, "bar", iceberg::string()), }), .type_id = iceberg::TypeId::kStruct, .primitive = false,