Skip to content

Commit dd166d3

Browse files
committed
updates
1 parent ce37966 commit dd166d3

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/iceberg/type.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,16 @@ bool DateType::Equals(const Type& other) const {
9191
return other.type_id() == TypeId::kDate;
9292
}
9393

94+
bool TimestampType::is_zoned() const { return false; }
95+
TimeUnit TimestampType::time_unit() const { return TimeUnit::kMicrosecond; }
9496
TypeId TimestampType::type_id() const { return TypeId::kTimestamp; }
9597
std::string TimestampType::ToString() const { return "timestamp"; }
9698
bool TimestampType::Equals(const Type& other) const {
9799
return other.type_id() == TypeId::kTimestamp;
98100
}
99101

102+
bool TimestampTzType::is_zoned() const { return true; }
103+
TimeUnit TimestampTzType::time_unit() const { return TimeUnit::kMicrosecond; }
100104
TypeId TimestampTzType::type_id() const { return TypeId::kTimestampTz; }
101105
std::string TimestampTzType::ToString() const { return "timestamptz"; }
102106
bool TimestampTzType::Equals(const Type& other) const {
@@ -226,7 +230,7 @@ std::optional<std::reference_wrapper<const SchemaField>> MapType::GetFieldById(
226230
return std::nullopt;
227231
}
228232
std::optional<std::reference_wrapper<const SchemaField>> MapType::GetFieldByIndex(
229-
int index) const {
233+
int32_t index) const {
230234
if (index == 0) {
231235
return key();
232236
} else if (index == 0) {
@@ -282,7 +286,7 @@ std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByI
282286
return fields_[it->second];
283287
}
284288
std::optional<std::reference_wrapper<const SchemaField>> StructType::GetFieldByIndex(
285-
int index) const {
289+
int32_t index) const {
286290
if (index < 0 || index >= static_cast<int>(fields_.size())) {
287291
return std::nullopt;
288292
}

src/iceberg/type.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ICEBERG_EXPORT NestedType : public Type {
8383
GetFieldById(int32_t field_id) const = 0;
8484
/// \brief Get a field by index.
8585
[[nodiscard]] virtual std::optional<std::reference_wrapper<const SchemaField>>
86-
GetFieldByIndex(int i) const = 0;
86+
GetFieldByIndex(int32_t index) const = 0;
8787
/// \brief Get a field by name.
8888
[[nodiscard]] virtual std::optional<std::reference_wrapper<const SchemaField>>
8989
GetFieldByName(std::string_view name) const = 0;
@@ -212,27 +212,43 @@ class ICEBERG_EXPORT TimeType : public PrimitiveType {
212212
bool Equals(const Type& other) const override;
213213
};
214214

215+
/// \brief A base class for any timestamp time (irrespective of unit or
216+
/// timezone).
217+
class ICEBERG_EXPORT TimestampBase : public PrimitiveType {
218+
public:
219+
/// \brief Is this type zoned or naive?
220+
[[nodiscard]] virtual bool is_zoned() const = 0;
221+
/// \brief The time resolution.
222+
[[nodiscard]] virtual TimeUnit time_unit() const = 0;
223+
};
224+
215225
/// \brief A data type representing a timestamp in microseconds without
216226
/// reference to a timezone.
217-
class ICEBERG_EXPORT TimestampType : public PrimitiveType {
227+
class ICEBERG_EXPORT TimestampType : public TimestampBase {
218228
public:
219229
TimestampType() = default;
220230
~TimestampType() = default;
221231

232+
bool is_zoned() const override;
233+
TimeUnit time_unit() const override;
234+
222235
TypeId type_id() const override;
223236
std::string ToString() const override;
224237

225238
protected:
226239
bool Equals(const Type& other) const override;
227240
};
228241

229-
/// \brief A data type representing a timestamp in microseconds in a
230-
/// particular timezone.
231-
class ICEBERG_EXPORT TimestampTzType : public PrimitiveType {
242+
/// \brief A data type representing a timestamp as microseconds since the
243+
/// epoch in UTC.
244+
class ICEBERG_EXPORT TimestampTzType : public TimestampBase {
232245
public:
233246
TimestampTzType() = default;
234247
~TimestampTzType() = default;
235248

249+
bool is_zoned() const override;
250+
TimeUnit time_unit() const override;
251+
236252
TypeId type_id() const override;
237253
std::string ToString() const override;
238254

@@ -325,7 +341,7 @@ class ICEBERG_EXPORT ListType : public NestedType {
325341
std::optional<std::reference_wrapper<const SchemaField>> GetFieldById(
326342
int32_t field_id) const override;
327343
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex(
328-
int i) const override;
344+
int32_t index) const override;
329345
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName(
330346
std::string_view name) const override;
331347

@@ -356,7 +372,7 @@ class ICEBERG_EXPORT MapType : public NestedType {
356372
std::optional<std::reference_wrapper<const SchemaField>> GetFieldById(
357373
int32_t field_id) const override;
358374
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex(
359-
int i) const override;
375+
int32_t index) const override;
360376
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName(
361377
std::string_view name) const override;
362378

@@ -379,7 +395,7 @@ class ICEBERG_EXPORT StructType : public NestedType {
379395
std::optional<std::reference_wrapper<const SchemaField>> GetFieldById(
380396
int32_t field_id) const override;
381397
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByIndex(
382-
int i) const override;
398+
int32_t index) const override;
383399
std::optional<std::reference_wrapper<const SchemaField>> GetFieldByName(
384400
std::string_view name) const override;
385401

src/iceberg/type_fwd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ enum class TypeId {
5252
kMap,
5353
};
5454

55+
/// \brief The time unit. In Iceberg V3 nanoseconds are also supported.
56+
enum class TimeUnit {
57+
kMicrosecond,
58+
};
59+
5560
class BooleanType;
5661
class SchemaField;
5762
class NestedType;

0 commit comments

Comments
 (0)