Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(ICEBERG_SOURCES
statistics_file.cc
table.cc
table_metadata.cc
table_properties.cc
table_scan.cc
transform.cc
transform_function.cc
Expand Down
18 changes: 15 additions & 3 deletions src/iceberg/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@
#include "iceberg/schema.h"
#include "iceberg/sort_order.h"
#include "iceberg/table_metadata.h"
#include "iceberg/table_properties.h"
#include "iceberg/table_scan.h"
#include "iceberg/util/macros.h"

namespace iceberg {

Table::~Table() = default;

Table::Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
std::string metadata_location, std::shared_ptr<FileIO> io,
std::shared_ptr<Catalog> catalog)
: identifier_(std::move(identifier)),
metadata_(std::move(metadata)),
metadata_location_(std::move(metadata_location)),
io_(std::move(io)),
catalog_(std::move(catalog)),
properties_(TableProperties::FromMap(metadata_->properties)) {}

const std::string& Table::uuid() const { return metadata_->table_uuid; }

Status Table::Refresh() {
Expand All @@ -43,6 +56,7 @@ Status Table::Refresh() {
metadata_ = std::move(refreshed_table->metadata_);
metadata_location_ = std::move(refreshed_table->metadata_location_);
io_ = std::move(refreshed_table->io_);
properties_ = std::move(refreshed_table->properties_);

schemas_map_.reset();
partition_spec_map_.reset();
Expand Down Expand Up @@ -99,9 +113,7 @@ Table::sort_orders() const {
return sort_orders_map_;
}

const std::unordered_map<std::string, std::string>& Table::properties() const {
return metadata_->properties;
}
const TableProperties& Table::properties() const { return *properties_; }

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

Expand Down
12 changes: 4 additions & 8 deletions src/iceberg/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace iceberg {
/// \brief Represents an Iceberg table
class ICEBERG_EXPORT Table {
public:
virtual ~Table() = default;
~Table();

/// \brief Construct a table.
/// \param[in] identifier The identifier of the table.
Expand All @@ -44,12 +44,7 @@ class ICEBERG_EXPORT Table {
/// be read-only.
Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
std::string metadata_location, std::shared_ptr<FileIO> io,
std::shared_ptr<Catalog> catalog)
: identifier_(std::move(identifier)),
metadata_(std::move(metadata)),
metadata_location_(std::move(metadata_location)),
io_(std::move(io)),
catalog_(std::move(catalog)) {};
std::shared_ptr<Catalog> catalog);

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

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

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

// Cache lazy-initialized maps.
mutable std::shared_ptr<std::unordered_map<int32_t, std::shared_ptr<Schema>>>
Expand Down
47 changes: 47 additions & 0 deletions src/iceberg/table_properties.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "iceberg/table_properties.h"

namespace iceberg {

const std::unordered_set<std::string>& TableProperties::reserved_properties() {
static const std::unordered_set<std::string> kReservedProperties = {
kFormatVersion.key(), kUuid.key(),
kSnapshotCount.key(), kCurrentSnapshotId.key(),
kCurrentSnapshotSummary.key(), kCurrentSnapshotTimestamp.key(),
kCurrentSchema.key(), kDefaultPartitionSpec.key(),
kDefaultSortOrder.key()};
return kReservedProperties;
}

std::unique_ptr<TableProperties> TableProperties::default_properties() {
return std::make_unique<TableProperties>();
}

std::unique_ptr<TableProperties> TableProperties::FromMap(
const std::unordered_map<std::string, std::string>& properties) {
auto table_properties = std::make_unique<TableProperties>();
for (const auto& [key, value] : properties) { // NOLINT(modernize-type-traits)
table_properties->configs_[key] = value;
}
return table_properties;
}

} // namespace iceberg
Loading
Loading