iceberg-cpp
Loading...
Searching...
No Matches
transform_function.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
23
24#include "iceberg/transform.h"
25
26namespace iceberg {
28class ICEBERG_EXPORT IdentityTransform : public TransformFunction {
29 public:
31 explicit IdentityTransform(std::shared_ptr<Type> const& source_type);
32
34 Result<Literal> Transform(const Literal& literal) override;
35
37 std::shared_ptr<Type> ResultType() const override;
38
43 std::shared_ptr<Type> const& source_type);
44};
45
47class ICEBERG_EXPORT BucketTransform : public TransformFunction {
48 public:
51 BucketTransform(std::shared_ptr<Type> const& source_type, int32_t num_buckets);
52
57 Result<Literal> Transform(const Literal& literal) override;
58
60 std::shared_ptr<Type> ResultType() const override;
61
63 int32_t num_buckets() const { return num_buckets_; }
64
70 std::shared_ptr<Type> const& source_type, int32_t num_buckets);
71
72 private:
73 [[nodiscard]] bool Equals(const TransformFunction& other) const override;
74
75 int32_t num_buckets_;
76};
77
79class ICEBERG_EXPORT TruncateTransform : public TransformFunction {
80 public:
83 TruncateTransform(std::shared_ptr<Type> const& source_type, int32_t width);
84
86 Result<Literal> Transform(const Literal& literal) override;
87
89 std::shared_ptr<Type> ResultType() const override;
90
92 int32_t width() const { return width_; }
93
99 std::shared_ptr<Type> const& source_type, int32_t width);
100
101 private:
102 [[nodiscard]] bool Equals(const TransformFunction& other) const override;
103
104 int32_t width_;
105};
106
109class ICEBERG_EXPORT YearTransform : public TransformFunction {
110 public:
112 explicit YearTransform(std::shared_ptr<Type> const& source_type);
113
115 Result<Literal> Transform(const Literal& literal) override;
116
118 std::shared_ptr<Type> ResultType() const override;
119
124 std::shared_ptr<Type> const& source_type);
125};
126
129class ICEBERG_EXPORT MonthTransform : public TransformFunction {
130 public:
132 explicit MonthTransform(std::shared_ptr<Type> const& source_type);
133
135 Result<Literal> Transform(const Literal& literal) override;
136
138 std::shared_ptr<Type> ResultType() const override;
139
144 std::shared_ptr<Type> const& source_type);
145};
146
149class ICEBERG_EXPORT DayTransform : public TransformFunction {
150 public:
152 explicit DayTransform(std::shared_ptr<Type> const& source_type);
153
155 Result<Literal> Transform(const Literal& literal) override;
156
162 std::shared_ptr<Type> ResultType() const override;
163
168 std::shared_ptr<Type> const& source_type);
169};
170
173class ICEBERG_EXPORT HourTransform : public TransformFunction {
174 public:
176 explicit HourTransform(std::shared_ptr<Type> const& source_type);
177
179 Result<Literal> Transform(const Literal& literal) override;
180
182 std::shared_ptr<Type> ResultType() const override;
183
188 std::shared_ptr<Type> const& source_type);
189};
190
192class ICEBERG_EXPORT VoidTransform : public TransformFunction {
193 public:
195 explicit VoidTransform(std::shared_ptr<Type> const& source_type);
196
198 Result<Literal> Transform(const Literal& literal) override;
199
201 std::shared_ptr<Type> ResultType() const override;
202
207 std::shared_ptr<Type> const& source_type);
208};
209
210} // namespace iceberg
Bucket transform that hashes input values into N buckets.
Definition transform_function.h:47
BucketTransform(std::shared_ptr< Type > const &source_type, int32_t num_buckets)
std::shared_ptr< Type > ResultType() const override
Returns INT32 as the output type.
int32_t num_buckets() const
Returns the number of buckets.
Definition transform_function.h:63
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type, int32_t num_buckets)
Create a BucketTransform.
Result< Literal > Transform(const Literal &literal) override
Applies the bucket hash function to the input Literal.
Day transform that extracts the number of days from timestamp inputs since the epoch.
Definition transform_function.h:149
std::shared_ptr< Type > ResultType() const override
Return the result type of a day transform.
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create a DayTransform.
DayTransform(std::shared_ptr< Type > const &source_type)
Result< Literal > Transform(const Literal &literal) override
Extract a date or timestamp day, as days from 1970-01-01.
Hour transform that extracts the number of hours from timestamp inputs since the epoch.
Definition transform_function.h:173
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create a HourTransform.
Result< Literal > Transform(const Literal &literal) override
Extract a timestamp hour, as hours from 1970-01-01 00:00:00.
std::shared_ptr< Type > ResultType() const override
Returns INT32 as the output type.
HourTransform(std::shared_ptr< Type > const &source_type)
Identity transform that returns the input unchanged.
Definition transform_function.h:28
Result< Literal > Transform(const Literal &literal) override
Returns the same Literal as the input.
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create an IdentityTransform.
IdentityTransform(std::shared_ptr< Type > const &source_type)
std::shared_ptr< Type > ResultType() const override
Returns the same type as source_type.
Literal is a literal value that is associated with a primitive type.
Definition literal.h:42
Month transform that extracts the number of months from timestamp inputs since the epoch.
Definition transform_function.h:129
Result< Literal > Transform(const Literal &literal) override
Extract a date or timestamp month, as months from 1970-01-01.
MonthTransform(std::shared_ptr< Type > const &source_type)
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create a MonthTransform.
std::shared_ptr< Type > ResultType() const override
Returns INT32 as the output type.
A transform function used for partitioning.
Definition transform.h:259
Truncate transform that truncates values to a specified width.
Definition transform_function.h:79
TruncateTransform(std::shared_ptr< Type > const &source_type, int32_t width)
Result< Literal > Transform(const Literal &literal) override
Truncates the input Literal to the specified width.
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type, int32_t width)
Create a TruncateTransform.
int32_t width() const
Returns the width to truncate to.
Definition transform_function.h:92
std::shared_ptr< Type > ResultType() const override
Returns the same type as source_type.
Void transform that discards the input and always returns null.
Definition transform_function.h:192
std::shared_ptr< Type > ResultType() const override
Returns the same type as source_type.
VoidTransform(std::shared_ptr< Type > const &source_type)
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create a VoidTransform.
Result< Literal > Transform(const Literal &literal) override
Returns a null literal.
Year transform that extracts the number of years from timestamp inputs since the epoch.
Definition transform_function.h:109
std::shared_ptr< Type > ResultType() const override
Returns INT32 as the output type.
static Result< std::unique_ptr< TransformFunction > > Make(std::shared_ptr< Type > const &source_type)
Create a YearTransform.
YearTransform(std::shared_ptr< Type > const &source_type)
Result< Literal > Transform(const Literal &literal) override
Extract a date or timestamp year, as years from 1970.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88