Skip to content

Commit 24176f6

Browse files
authored
feat: define table properties with default values (#212)
Just copied everything from the TableProperties.java as of today
1 parent b85477b commit 24176f6

File tree

6 files changed

+368
-11
lines changed

6 files changed

+368
-11
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(ICEBERG_SOURCES
4141
statistics_file.cc
4242
table.cc
4343
table_metadata.cc
44+
table_properties.cc
4445
table_scan.cc
4546
transform.cc
4647
transform_function.cc

src/iceberg/table.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,24 @@
2626
#include "iceberg/schema.h"
2727
#include "iceberg/sort_order.h"
2828
#include "iceberg/table_metadata.h"
29+
#include "iceberg/table_properties.h"
2930
#include "iceberg/table_scan.h"
3031
#include "iceberg/util/macros.h"
3132

3233
namespace iceberg {
3334

35+
Table::~Table() = default;
36+
37+
Table::Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
38+
std::string metadata_location, std::shared_ptr<FileIO> io,
39+
std::shared_ptr<Catalog> catalog)
40+
: identifier_(std::move(identifier)),
41+
metadata_(std::move(metadata)),
42+
metadata_location_(std::move(metadata_location)),
43+
io_(std::move(io)),
44+
catalog_(std::move(catalog)),
45+
properties_(TableProperties::FromMap(metadata_->properties)) {}
46+
3447
const std::string& Table::uuid() const { return metadata_->table_uuid; }
3548

3649
Status Table::Refresh() {
@@ -43,6 +56,7 @@ Status Table::Refresh() {
4356
metadata_ = std::move(refreshed_table->metadata_);
4457
metadata_location_ = std::move(refreshed_table->metadata_location_);
4558
io_ = std::move(refreshed_table->io_);
59+
properties_ = std::move(refreshed_table->properties_);
4660

4761
schemas_map_.reset();
4862
partition_spec_map_.reset();
@@ -99,9 +113,7 @@ Table::sort_orders() const {
99113
return sort_orders_map_;
100114
}
101115

102-
const std::unordered_map<std::string, std::string>& Table::properties() const {
103-
return metadata_->properties;
104-
}
116+
const TableProperties& Table::properties() const { return *properties_; }
105117

106118
const std::string& Table::location() const { return metadata_->location; }
107119

src/iceberg/table.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace iceberg {
3333
/// \brief Represents an Iceberg table
3434
class ICEBERG_EXPORT Table {
3535
public:
36-
virtual ~Table() = default;
36+
~Table();
3737

3838
/// \brief Construct a table.
3939
/// \param[in] identifier The identifier of the table.
@@ -44,12 +44,7 @@ class ICEBERG_EXPORT Table {
4444
/// be read-only.
4545
Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
4646
std::string metadata_location, std::shared_ptr<FileIO> io,
47-
std::shared_ptr<Catalog> catalog)
48-
: identifier_(std::move(identifier)),
49-
metadata_(std::move(metadata)),
50-
metadata_location_(std::move(metadata_location)),
51-
io_(std::move(io)),
52-
catalog_(std::move(catalog)) {};
47+
std::shared_ptr<Catalog> catalog);
5348

5449
/// \brief Return the identifier of this table
5550
const TableIdentifier& name() const { return identifier_; }
@@ -85,7 +80,7 @@ class ICEBERG_EXPORT Table {
8580
sort_orders() const;
8681

8782
/// \brief Return a map of string properties for this table
88-
const std::unordered_map<std::string, std::string>& properties() const;
83+
const TableProperties& properties() const;
8984

9085
/// \brief Return the table's base location
9186
const std::string& location() const;
@@ -122,6 +117,7 @@ class ICEBERG_EXPORT Table {
122117
std::string metadata_location_;
123118
std::shared_ptr<FileIO> io_;
124119
std::shared_ptr<Catalog> catalog_;
120+
std::unique_ptr<TableProperties> properties_;
125121

126122
// Cache lazy-initialized maps.
127123
mutable std::shared_ptr<std::unordered_map<int32_t, std::shared_ptr<Schema>>>

src/iceberg/table_properties.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
#include "iceberg/table_properties.h"
21+
22+
namespace iceberg {
23+
24+
const std::unordered_set<std::string>& TableProperties::reserved_properties() {
25+
static const std::unordered_set<std::string> kReservedProperties = {
26+
kFormatVersion.key(), kUuid.key(),
27+
kSnapshotCount.key(), kCurrentSnapshotId.key(),
28+
kCurrentSnapshotSummary.key(), kCurrentSnapshotTimestamp.key(),
29+
kCurrentSchema.key(), kDefaultPartitionSpec.key(),
30+
kDefaultSortOrder.key()};
31+
return kReservedProperties;
32+
}
33+
34+
std::unique_ptr<TableProperties> TableProperties::default_properties() {
35+
return std::make_unique<TableProperties>();
36+
}
37+
38+
std::unique_ptr<TableProperties> TableProperties::FromMap(
39+
const std::unordered_map<std::string, std::string>& properties) {
40+
auto table_properties = std::make_unique<TableProperties>();
41+
for (const auto& [key, value] : properties) { // NOLINT(modernize-type-traits)
42+
table_properties->configs_[key] = value;
43+
}
44+
return table_properties;
45+
}
46+
47+
} // namespace iceberg

0 commit comments

Comments
 (0)