Skip to content

Commit 8600cb2

Browse files
committed
use const ref and unique_ptr where possible
1 parent 4399cb2 commit 8600cb2

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/iceberg/catalog.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ICEBERG_EXPORT Catalog {
4343
/// \param ns a namespace
4444
/// \return a list of identifiers for tables or Error::kNoSuchNamespace
4545
/// if the namespace does not exist
46-
virtual expected<std::vector<TableIdentifier>, Error> ListTables(
46+
virtual expected<std::vector<TableIdentifier>, ErrorKind> ListTables(
4747
const Namespace& ns) const = 0;
4848

4949
/// \brief Create a table
@@ -54,7 +54,7 @@ class ICEBERG_EXPORT Catalog {
5454
/// \param location a location for the table; leave empty if unspecified
5555
/// \param properties a string map of table properties
5656
/// \return a Table instance or Error::kAlreadyExists if the table already exists
57-
virtual expected<std::unique_ptr<Table>, Error> CreateTable(
57+
virtual expected<std::unique_ptr<Table>, ErrorKind> CreateTable(
5858
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
5959
const std::string& location,
6060
const std::map<std::string, std::string>& properties) = 0;
@@ -68,7 +68,7 @@ class ICEBERG_EXPORT Catalog {
6868
/// \param properties a string map of table properties
6969
/// \return a Transaction to create the table or Error::kAlreadyExists if the table
7070
/// already exists
71-
virtual expected<std::shared_ptr<Transaction>, Error> NewCreateTableTransaction(
71+
virtual expected<std::shared_ptr<Transaction>, ErrorKind> NewCreateTableTransaction(
7272
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
7373
const std::string& location,
7474
const std::map<std::string, std::string>& properties) = 0;
@@ -94,15 +94,15 @@ class ICEBERG_EXPORT Catalog {
9494
/// \param identifier a table identifier
9595
/// \return instance of Table implementation referred to by identifier or
9696
/// Error::kNoSuchTable if the table does not exist
97-
virtual expected<std::shared_ptr<Table>, Error> LoadTable(
97+
virtual expected<std::shared_ptr<Table>, ErrorKind> LoadTable(
9898
const TableIdentifier& identifier) const = 0;
9999

100100
/// \brief Register a table with the catalog if it does not exist
101101
///
102102
/// \param identifier a table identifier
103103
/// \param metadata_file_location the location of a metadata file
104104
/// \return a Table instance or Error::kAlreadyExists if the table already exists
105-
virtual expected<std::shared_ptr<Table>, Error> RegisterTable(
105+
virtual expected<std::shared_ptr<Table>, ErrorKind> RegisterTable(
106106
const TableIdentifier& identifier, const std::string& metadata_file_location) = 0;
107107

108108
/// \brief Initialize a catalog given a custom name and a map of catalog properties

src/iceberg/table.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma once
2121

2222
#include <map>
23+
#include <memory>
2324
#include <string>
2425
#include <vector>
2526

@@ -35,10 +36,10 @@ class ICEBERG_EXPORT Table {
3536
virtual ~Table() = default;
3637

3738
/// \brief Return the full name for this table
38-
virtual std::string name() const = 0;
39+
virtual const std::string& name() const = 0;
3940

4041
/// \brief Returns the UUID of the table
41-
virtual std::string uuid() const = 0;
42+
virtual const std::string& uuid() const = 0;
4243

4344
/// \brief Refresh the current table metadata
4445
virtual void Refresh() = 0;
@@ -47,25 +48,25 @@ class ICEBERG_EXPORT Table {
4748
virtual const std::shared_ptr<Schema>& schema() const = 0;
4849

4950
/// \brief Return a map of schema for this table
50-
virtual std::map<int32_t, std::shared_ptr<Schema>> schemas() const = 0;
51+
virtual const std::map<int32_t, std::shared_ptr<Schema>>& schemas() const = 0;
5152

5253
/// \brief Return the partition spec for this table
5354
virtual const std::shared_ptr<PartitionSpec>& spec() const = 0;
5455

5556
/// \brief Return a map of partition specs for this table
56-
virtual std::map<int32_t, std::shared_ptr<PartitionSpec>> specs() const = 0;
57+
virtual const std::map<int32_t, std::shared_ptr<PartitionSpec>>& specs() const = 0;
5758

5859
/// \brief Return the sort order for this table
5960
virtual const std::shared_ptr<SortOrder>& sort_order() const = 0;
6061

6162
/// \brief Return a map of sort order IDs to sort orders for this table
62-
virtual std::map<int32_t, std::shared_ptr<SortOrder>> sort_orders() const = 0;
63+
virtual const std::map<int32_t, std::shared_ptr<SortOrder>>& sort_orders() const = 0;
6364

6465
/// \brief Return a map of string properties for this table
65-
virtual std::map<std::string, std::string> properties() const = 0;
66+
virtual const std::map<std::string, std::string>& properties() const = 0;
6667

6768
/// \brief Return the table's base location
68-
virtual std::string location() const = 0;
69+
virtual const std::string& location() const = 0;
6970

7071
/// \brief Return the table's current snapshot
7172
virtual const std::shared_ptr<Snapshot>& current_snapshot() const = 0;
@@ -75,21 +76,21 @@ class ICEBERG_EXPORT Table {
7576
///
7677
/// \param snapshot_id the ID of the snapshot to get
7778
/// \return the Snapshot with the given id
78-
virtual expected<std::shared_ptr<Snapshot>, Error> snapshot(
79+
virtual expected<std::shared_ptr<Snapshot>, ErrorKind> snapshot(
7980
int64_t snapshot_id) const = 0;
8081

8182
/// \brief Get the snapshots of this table
82-
virtual std::vector<std::shared_ptr<Snapshot>> snapshots() const = 0;
83+
virtual const std::vector<std::shared_ptr<Snapshot>>& snapshots() const = 0;
8384

8485
/// \brief Get the snapshot history of this table
8586
///
8687
/// \return a vector of history entries
87-
virtual std::vector<std::shared_ptr<HistoryEntry>> history() const = 0;
88+
virtual const std::vector<std::shared_ptr<HistoryEntry>>& history() const = 0;
8889

8990
/// \brief Create a new table scan for this table
9091
///
9192
/// Once a table scan is created, it can be refined to project columns and filter data.
92-
virtual std::shared_ptr<TableScan> NewScan() const = 0;
93+
virtual std::unique_ptr<TableScan> NewScan() const = 0;
9394

9495
/// \brief Create a new append API to add files to this table and commit
9596
virtual std::shared_ptr<AppendFiles> NewAppend() = 0;

src/iceberg/table_operations.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class ICEBERG_EXPORT TableOperations {
5757
///
5858
/// \param base table metadata on which changes were based
5959
/// \param metadata new table metadata with updates
60-
virtual expected<void, Error> Commit(const TableMetadata& base,
61-
const TableMetadata& metadata) = 0;
60+
virtual expected<void, ErrorKind> Commit(const TableMetadata& base,
61+
const TableMetadata& metadata) = 0;
6262

6363
/// \brief Returns an FileIO to read and write table data and metadata files.
6464
// virtual std::shared_ptr<FileIO> io() const = 0;
@@ -70,7 +70,7 @@ class ICEBERG_EXPORT TableOperations {
7070
/// \brief Returns a LocationProvider that supplies locations for new new data files.
7171
///
7272
/// \return a location provider configured for the current table state
73-
virtual std::shared_ptr<LocationProvider> location_provider() const = 0;
73+
virtual std::unique_ptr<LocationProvider> location_provider() const = 0;
7474

7575
/// \brief Return a temporary TableOperations instance that uses configuration from
7676
/// uncommitted metadata.

src/iceberg/type_fwd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class UuidType;
8383

8484
/// \brief Error types for iceberg.
8585
/// TODO: add more and sort them based on some rules.
86-
enum class Error {
86+
enum class ErrorKind {
8787
kNoSuchNamespace,
8888
kAlreadyExists,
8989
kNoSuchTable,

0 commit comments

Comments
 (0)