25#include <initializer_list>
31#include "iceberg/expression/literal.h"
34#include "iceberg/iceberg_export.h"
35#include "iceberg/util/macros.h"
47 template <
typename... Args>
48 static std::shared_ptr<Expression>
And(std::shared_ptr<Expression> left,
49 std::shared_ptr<Expression> right,
51 requires std::conjunction_v<std::is_same<Args, std::shared_ptr<Expression>>...>
53 ICEBERG_ASSIGN_OR_THROW(
auto and_expr,
55 std::forward<Args>(args)...));
60 template <
typename... Args>
61 static std::shared_ptr<Expression>
Or(std::shared_ptr<Expression> left,
62 std::shared_ptr<Expression> right, Args&&... args)
63 requires std::conjunction_v<std::is_same<Args, std::shared_ptr<Expression>>...>
65 ICEBERG_ASSIGN_OR_THROW(
auto or_expr,
67 std::forward<Args>(args)...));
78 static std::shared_ptr<Expression>
Not(std::shared_ptr<Expression> child);
83 static std::shared_ptr<UnboundTransform> Bucket(std::string name, int32_t num_buckets);
86 static std::shared_ptr<UnboundTransform> Year(std::string name);
89 static std::shared_ptr<UnboundTransform> Month(std::string name);
92 static std::shared_ptr<UnboundTransform> Day(std::string name);
95 static std::shared_ptr<UnboundTransform> Hour(std::string name);
98 static std::shared_ptr<UnboundTransform> Truncate(std::string name, int32_t width);
101 static std::shared_ptr<UnboundTransform>
Transform(
102 std::string name, std::shared_ptr<Transform> transform);
107 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Count(std::string name);
110 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Count(
111 std::shared_ptr<UnboundTerm<BoundReference>> expr);
114 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> CountNull(
118 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> CountNull(
119 std::shared_ptr<UnboundTerm<BoundReference>> expr);
122 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> CountNotNull(
126 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> CountNotNull(
127 std::shared_ptr<UnboundTerm<BoundReference>> expr);
130 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> CountStar();
133 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Max(std::string name);
136 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Max(
137 std::shared_ptr<UnboundTerm<BoundReference>> expr);
139 static std::shared_ptr<UnboundAggregateImpl<BoundTransform>> Max(
140 std::shared_ptr<UnboundTerm<BoundTransform>> expr);
143 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Min(std::string name);
146 static std::shared_ptr<UnboundAggregateImpl<BoundReference>> Min(
147 std::shared_ptr<UnboundTerm<BoundReference>> expr);
149 static std::shared_ptr<UnboundAggregateImpl<BoundTransform>> Min(
150 std::shared_ptr<UnboundTerm<BoundTransform>> expr);
155 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> IsNull(std::string name);
158 template <
typename B>
159 static std::shared_ptr<UnboundPredicateImpl<B>>
IsNull(
160 std::shared_ptr<UnboundTerm<B>> expr) {
161 ICEBERG_ASSIGN_OR_THROW(
168 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotNull(std::string name);
171 template <
typename B>
172 static std::shared_ptr<UnboundPredicateImpl<B>>
NotNull(
173 std::shared_ptr<UnboundTerm<B>> expr) {
174 ICEBERG_ASSIGN_OR_THROW(
181 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> IsNaN(std::string name);
184 template <
typename B>
185 static std::shared_ptr<UnboundPredicateImpl<B>>
IsNaN(
186 std::shared_ptr<UnboundTerm<B>> expr) {
187 ICEBERG_ASSIGN_OR_THROW(
194 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotNaN(std::string name);
197 template <
typename B>
198 static std::shared_ptr<UnboundPredicateImpl<B>>
NotNaN(
199 std::shared_ptr<UnboundTerm<B>> expr) {
200 ICEBERG_ASSIGN_OR_THROW(
209 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> LessThan(std::string name,
213 template <
typename B>
214 static std::shared_ptr<UnboundPredicateImpl<B>>
LessThan(
215 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
216 ICEBERG_ASSIGN_OR_THROW(
218 std::move(expr), std::move(value)));
223 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> LessThanOrEqual(
224 std::string name,
Literal value);
227 template <
typename B>
229 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
230 ICEBERG_ASSIGN_OR_THROW(
232 std::move(expr), std::move(value)));
237 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> GreaterThan(
238 std::string name,
Literal value);
241 template <
typename B>
243 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
244 ICEBERG_ASSIGN_OR_THROW(
246 std::move(expr), std::move(value)));
251 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> GreaterThanOrEqual(
252 std::string name,
Literal value);
255 template <
typename B>
257 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
258 ICEBERG_ASSIGN_OR_THROW(
260 std::move(expr), std::move(value)));
265 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> Equal(std::string name,
269 template <
typename B>
270 static std::shared_ptr<UnboundPredicateImpl<B>>
Equal(
271 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
272 ICEBERG_ASSIGN_OR_THROW(
274 std::move(expr), std::move(value)));
279 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotEqual(std::string name,
283 template <
typename B>
284 static std::shared_ptr<UnboundPredicateImpl<B>>
NotEqual(
285 std::shared_ptr<UnboundTerm<B>> expr,
Literal value) {
286 ICEBERG_ASSIGN_OR_THROW(
288 std::move(expr), std::move(value)));
295 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> StartsWith(
296 std::string name, std::string value);
299 template <
typename B>
301 std::shared_ptr<UnboundTerm<B>> expr, std::string value) {
302 ICEBERG_ASSIGN_OR_THROW(
305 Literal::String(std::move(value))));
310 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotStartsWith(
311 std::string name, std::string value);
314 template <
typename B>
316 std::shared_ptr<UnboundTerm<B>> expr, std::string value) {
317 ICEBERG_ASSIGN_OR_THROW(
320 Literal::String(std::move(value))));
327 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> In(
328 std::string name, std::vector<Literal> values);
331 template <
typename B>
332 static std::shared_ptr<UnboundPredicateImpl<B>>
In(std::shared_ptr<UnboundTerm<B>> expr,
333 std::vector<Literal> values) {
334 ICEBERG_ASSIGN_OR_THROW(
336 std::move(expr), std::move(values)));
341 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> In(
342 std::string name, std::initializer_list<Literal> values);
345 template <
typename B>
346 static std::shared_ptr<UnboundPredicateImpl<B>>
In(
347 std::shared_ptr<UnboundTerm<B>> expr, std::initializer_list<Literal> values) {
348 return In<B>(std::move(expr), std::vector<Literal>(values));
352 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotIn(
353 std::string name, std::vector<Literal> values);
356 template <
typename B>
357 static std::shared_ptr<UnboundPredicateImpl<B>>
NotIn(
358 std::shared_ptr<UnboundTerm<B>> expr, std::vector<Literal> values) {
359 ICEBERG_ASSIGN_OR_THROW(
361 std::move(expr), std::move(values)));
366 static std::shared_ptr<UnboundPredicateImpl<BoundReference>> NotIn(
367 std::string name, std::initializer_list<Literal> values);
370 template <
typename B>
371 static std::shared_ptr<UnboundPredicateImpl<B>>
NotIn(
372 std::shared_ptr<UnboundTerm<B>> expr, std::initializer_list<Literal> values) {
373 return NotIn<B>(expr, std::vector<Literal>(values));
379 static std::shared_ptr<UnboundPredicateImpl<BoundReference>>
Predicate(
383 static std::shared_ptr<UnboundPredicateImpl<BoundReference>>
Predicate(
387 static std::shared_ptr<UnboundPredicateImpl<BoundReference>>
Predicate(
391 static std::shared_ptr<UnboundPredicateImpl<BoundReference>>
Predicate(
395 template <
typename B>
396 static std::shared_ptr<UnboundPredicateImpl<B>>
Predicate(
398 std::vector<Literal> values) {
399 ICEBERG_ASSIGN_OR_THROW(
405 template <
typename B>
406 static std::shared_ptr<UnboundPredicateImpl<B>>
Predicate(
408 std::initializer_list<Literal> values) {
409 return Predicate<B>(op, std::move(expr), std::vector<Literal>(values));
413 template <
typename B>
414 static std::shared_ptr<UnboundPredicateImpl<B>>
Predicate(
416 ICEBERG_ASSIGN_OR_THROW(
auto pred,
424 static std::shared_ptr<True> AlwaysTrue();
427 static std::shared_ptr<False> AlwaysFalse();
432 static std::shared_ptr<NamedReference> Ref(std::string name);
435 static Literal Lit(Literal::Value value, std::shared_ptr<PrimitiveType> type);
static Result< std::shared_ptr< Expression > > MakeFolded(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Creates a folded And expression from two sub-expressions.
Definition expression.h:158
Operation
Operation types for expressions.
Definition expression.h:40
Fluent APIs to create expressions.
Definition expressions.h:42
static std::shared_ptr< UnboundPredicateImpl< B > > GreaterThan(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create a greater than predicate for an unbound term.
Definition expressions.h:242
static std::shared_ptr< UnboundPredicateImpl< B > > NotIn(std::shared_ptr< UnboundTerm< B > > expr, std::initializer_list< Literal > values)
Create a NOT IN predicate for an unbound term with initializer list.
Definition expressions.h:371
static std::shared_ptr< UnboundPredicateImpl< B > > NotNull(std::shared_ptr< UnboundTerm< B > > expr)
Create a NOT NULL predicate for an unbound term.
Definition expressions.h:172
static std::shared_ptr< UnboundPredicateImpl< B > > NotIn(std::shared_ptr< UnboundTerm< B > > expr, std::vector< Literal > values)
Create a NOT IN predicate for an unbound term.
Definition expressions.h:357
static std::shared_ptr< UnboundPredicateImpl< B > > LessThanOrEqual(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create a less than or equal predicate for an unbound term.
Definition expressions.h:228
static std::shared_ptr< UnboundPredicateImpl< B > > NotEqual(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create a not equal predicate for an unbound term.
Definition expressions.h:284
static std::shared_ptr< UnboundPredicateImpl< B > > Predicate(Expression::Operation op, std::shared_ptr< UnboundTerm< B > > expr)
Create a unary predicate for unbound term.
Definition expressions.h:414
static std::shared_ptr< UnboundPredicateImpl< B > > NotNaN(std::shared_ptr< UnboundTerm< B > > expr)
Create a NOT NaN predicate for an unbound term.
Definition expressions.h:198
static std::shared_ptr< UnboundPredicateImpl< B > > In(std::shared_ptr< UnboundTerm< B > > expr, std::vector< Literal > values)
Create an IN predicate for an unbound term.
Definition expressions.h:332
static std::shared_ptr< UnboundPredicateImpl< B > > Predicate(Expression::Operation op, std::shared_ptr< UnboundTerm< B > > expr, std::initializer_list< Literal > values)
Create a predicate with operation and multiple values.
Definition expressions.h:406
static std::shared_ptr< UnboundPredicateImpl< B > > GreaterThanOrEqual(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create a greater than or equal predicate for an unbound term.
Definition expressions.h:256
static std::shared_ptr< UnboundPredicateImpl< B > > IsNaN(std::shared_ptr< UnboundTerm< B > > expr)
Create an IS NaN predicate for an unbound term.
Definition expressions.h:185
static std::shared_ptr< UnboundPredicateImpl< B > > In(std::shared_ptr< UnboundTerm< B > > expr, std::initializer_list< Literal > values)
Create an IN predicate for an unbound term with initializer list.
Definition expressions.h:346
static std::shared_ptr< Expression > Or(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Create an OR expression.
Definition expressions.h:61
static std::shared_ptr< UnboundPredicateImpl< B > > Predicate(Expression::Operation op, std::shared_ptr< UnboundTerm< B > > expr, std::vector< Literal > values)
Create a predicate for unbound term with multiple values.
Definition expressions.h:396
static std::shared_ptr< UnboundPredicateImpl< B > > NotStartsWith(std::shared_ptr< UnboundTerm< B > > expr, std::string value)
Create a not starts with predicate for an unbound term.
Definition expressions.h:315
static std::shared_ptr< UnboundPredicateImpl< B > > LessThan(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create a less than predicate for an unbound term.
Definition expressions.h:214
static std::shared_ptr< Expression > And(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Create an AND expression.
Definition expressions.h:48
static std::shared_ptr< UnboundPredicateImpl< B > > IsNull(std::shared_ptr< UnboundTerm< B > > expr)
Create an IS NULL predicate for an unbound term.
Definition expressions.h:159
static std::shared_ptr< UnboundPredicateImpl< B > > StartsWith(std::shared_ptr< UnboundTerm< B > > expr, std::string value)
Create a starts with predicate for an unbound term.
Definition expressions.h:300
static std::shared_ptr< UnboundPredicateImpl< B > > Equal(std::shared_ptr< UnboundTerm< B > > expr, Literal value)
Create an equal predicate for an unbound term.
Definition expressions.h:270
Literal is a literal value that is associated with a primitive type.
Definition literal.h:39
An Expression that represents logical NOT operation.
Definition expression.h:289
static Result< std::shared_ptr< Expression > > MakeFolded(std::shared_ptr< Expression > left, std::shared_ptr< Expression > right, Args &&... args)
Creates a folded Or expression from two sub-expressions.
Definition expression.h:234
A predicate is a boolean expression that tests a term against some criteria.
Definition predicate.h:38
Unbound predicates contain unbound terms and must be bound to a concrete schema before they can be ev...
Definition predicate.h:95