Skip to content

Commit 4399cb2

Browse files
committed
Add pure virtual classes for Catalog, Table, etc.
1 parent cd82335 commit 4399cb2

File tree

15 files changed

+557
-21
lines changed

15 files changed

+557
-21
lines changed

example/demo_example.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
#include "iceberg/arrow/demo_arrow.h"
2323
#include "iceberg/avro/demo_avro.h"
24-
#include "iceberg/demo_table.h"
24+
#include "iceberg/demo.h"
2525
#include "iceberg/puffin/demo_puffin.h"
2626

2727
int main() {
28-
std::cout << iceberg::DemoTable().print() << std::endl;
28+
std::cout << iceberg::Demo().print() << std::endl;
2929
std::cout << iceberg::puffin::DemoPuffin().print() << std::endl;
3030
std::cout << iceberg::arrow::DemoArrow().print() << std::endl;
3131
std::cout << iceberg::avro::DemoAvro().print() << std::endl;

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
set(ICEBERG_SOURCES demo_table.cc schema.cc schema_field.cc type.cc)
18+
set(ICEBERG_SOURCES demo.cc schema.cc schema_field.cc type.cc)
1919

2020
add_iceberg_lib(iceberg
2121
SOURCES

src/iceberg/arrow/demo_arrow.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
#include <arrow/config.h>
2323

24-
#include "iceberg/demo_table.h"
24+
#include "iceberg/demo.h"
2525

2626
namespace iceberg::arrow {
2727

2828
std::string DemoArrow::print() const {
29-
return DemoTable().print() +
30-
", Arrow version: " + ::arrow::GetBuildInfo().version_string;
29+
return Demo().print() + ", Arrow version: " + ::arrow::GetBuildInfo().version_string;
3130
}
3231

3332
} // namespace iceberg::arrow

src/iceberg/arrow/demo_arrow.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
#include <string>
2323

2424
#include "iceberg/arrow/iceberg_arrow_export.h"
25-
#include "iceberg/table.h"
25+
#include "iceberg/demo.h"
2626

2727
namespace iceberg::arrow {
2828

29-
class ICEBERG_ARROW_EXPORT DemoArrow : public Table {
29+
class ICEBERG_ARROW_EXPORT DemoArrow : public Demo {
3030
public:
3131
DemoArrow() = default;
3232
~DemoArrow() override = default;

src/iceberg/avro/demo_avro.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "avro/Compiler.hh"
2525
#include "avro/ValidSchema.hh"
26-
#include "iceberg/demo_table.h"
26+
#include "iceberg/demo.h"
2727

2828
namespace iceberg::avro {
2929

src/iceberg/catalog.h

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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+
#pragma once
21+
22+
#include <map>
23+
#include <memory>
24+
#include <string>
25+
#include <vector>
26+
27+
#include "iceberg/expected.h"
28+
#include "iceberg/table_identifier.h"
29+
#include "iceberg/type_fwd.h"
30+
31+
namespace iceberg {
32+
33+
/// \brief A Catalog API for table create, drop, and load operations.
34+
class ICEBERG_EXPORT Catalog {
35+
public:
36+
virtual ~Catalog() = default;
37+
38+
/// \brief Return the name for this catalog
39+
virtual std::string name() const = 0;
40+
41+
/// \brief Return all the identifiers under this namespace
42+
///
43+
/// \param ns a namespace
44+
/// \return a list of identifiers for tables or Error::kNoSuchNamespace
45+
/// if the namespace does not exist
46+
virtual expected<std::vector<TableIdentifier>, Error> ListTables(
47+
const Namespace& ns) const = 0;
48+
49+
/// \brief Create a table
50+
///
51+
/// \param identifier a table identifier
52+
/// \param schema a schema
53+
/// \param spec a partition spec
54+
/// \param location a location for the table; leave empty if unspecified
55+
/// \param properties a string map of table properties
56+
/// \return a Table instance or Error::kAlreadyExists if the table already exists
57+
virtual expected<std::unique_ptr<Table>, Error> CreateTable(
58+
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
59+
const std::string& location,
60+
const std::map<std::string, std::string>& properties) = 0;
61+
62+
/// \brief Start a transaction to create a table
63+
///
64+
/// \param identifier a table identifier
65+
/// \param schema a schema
66+
/// \param spec a partition spec
67+
/// \param location a location for the table; leave empty if unspecified
68+
/// \param properties a string map of table properties
69+
/// \return a Transaction to create the table or Error::kAlreadyExists if the table
70+
/// already exists
71+
virtual expected<std::shared_ptr<Transaction>, Error> NewCreateTableTransaction(
72+
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
73+
const std::string& location,
74+
const std::map<std::string, std::string>& properties) = 0;
75+
76+
/// \brief Check whether table exists
77+
///
78+
/// \param identifier a table identifier
79+
/// \return true if the table exists, false otherwise
80+
virtual bool TableExists(const TableIdentifier& identifier) const = 0;
81+
82+
/// \brief Drop a table; optionally delete data and metadata files
83+
///
84+
/// If purge is set to true the implementation should delete all data and metadata
85+
/// files.
86+
///
87+
/// \param identifier a table identifier
88+
/// \param purge if true, delete all data and metadata files in the table
89+
/// \return true if the table was dropped, false if the table did not exist
90+
virtual bool DropTable(const TableIdentifier& identifier, bool purge) = 0;
91+
92+
/// \brief Load a table
93+
///
94+
/// \param identifier a table identifier
95+
/// \return instance of Table implementation referred to by identifier or
96+
/// Error::kNoSuchTable if the table does not exist
97+
virtual expected<std::shared_ptr<Table>, Error> LoadTable(
98+
const TableIdentifier& identifier) const = 0;
99+
100+
/// \brief Register a table with the catalog if it does not exist
101+
///
102+
/// \param identifier a table identifier
103+
/// \param metadata_file_location the location of a metadata file
104+
/// \return a Table instance or Error::kAlreadyExists if the table already exists
105+
virtual expected<std::shared_ptr<Table>, Error> RegisterTable(
106+
const TableIdentifier& identifier, const std::string& metadata_file_location) = 0;
107+
108+
/// \brief Initialize a catalog given a custom name and a map of catalog properties
109+
///
110+
/// A custom Catalog implementation must have a default constructor. A compute engine
111+
/// will first initialize the catalog without any arguments, and then call this method
112+
/// to complete catalog initialization with properties passed into the engine.
113+
///
114+
/// \param name a custom name for the catalog
115+
/// \param properties catalog properties
116+
virtual void Initialize(const std::string& name,
117+
const std::map<std::string, std::string>& properties) = 0;
118+
119+
/// \brief Instantiate a builder to either create a table or start a create/replace
120+
/// transaction
121+
///
122+
/// \param identifier a table identifier
123+
/// \param schema a schema
124+
/// \return the builder to create a table or start a create/replace transaction
125+
virtual std::unique_ptr<class TableBuilder> BuildTable(
126+
const TableIdentifier& identifier, const Schema& schema) const = 0;
127+
128+
/// \brief A builder used to create valid tables or start create/replace transactions
129+
class TableBuilder {
130+
public:
131+
virtual ~TableBuilder() = default;
132+
133+
/// \brief Sets a partition spec for the table
134+
///
135+
/// \param spec a partition spec
136+
/// \return this for method chaining
137+
virtual TableBuilder& WithPartitionSpec(const PartitionSpec& spec) = 0;
138+
139+
/// \brief Sets a sort order for the table
140+
///
141+
/// \param sort_order a sort order
142+
/// \return this for method chaining
143+
virtual TableBuilder& WithSortOrder(const SortOrder& sort_order) = 0;
144+
145+
/// \brief Sets a location for the table
146+
///
147+
/// \param location a location
148+
/// \return this for method chaining
149+
virtual TableBuilder& WithLocation(const std::string& location) = 0;
150+
151+
/// \brief Adds key/value properties to the table
152+
///
153+
/// \param properties key/value properties
154+
/// \return this for method chaining
155+
virtual TableBuilder& WithProperties(
156+
const std::map<std::string, std::string>& properties) = 0;
157+
158+
/// \brief Adds a key/value property to the table
159+
///
160+
/// \param key a key
161+
/// \param value a value
162+
/// \return this for method chaining
163+
virtual TableBuilder& WithProperty(const std::string& key,
164+
const std::string& value) = 0;
165+
166+
/// \brief Creates the table
167+
///
168+
/// \return the created table
169+
virtual std::unique_ptr<Table> Create() = 0;
170+
171+
/// \brief Starts a transaction to create the table
172+
///
173+
/// \return the Transaction to create the table
174+
virtual std::unique_ptr<Transaction> CreateTransaction() = 0;
175+
};
176+
};
177+
178+
} // namespace iceberg

src/iceberg/demo_table.cc renamed to src/iceberg/demo.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
* under the License.
1818
*/
1919

20-
#include "iceberg/demo_table.h"
20+
#include "iceberg/demo.h"
2121

2222
#include "iceberg/avro.h" // include to export symbols
23+
#include "iceberg/catalog.h"
24+
#include "iceberg/location_provider.h"
2325
#include "iceberg/puffin.h"
26+
#include "iceberg/table.h"
27+
#include "iceberg/table_operations.h"
28+
#include "iceberg/transaction.h"
2429

2530
namespace iceberg {
2631

27-
std::string DemoTable::print() const { return "DemoTable"; }
32+
std::string Demo::print() const { return "Demo"; }
2833

2934
} // namespace iceberg

src/iceberg/demo_table.h renamed to src/iceberg/demo.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@
1919

2020
#pragma once
2121

22-
#include "iceberg/table.h"
22+
#include <string>
23+
24+
#include "iceberg/iceberg_export.h"
2325

2426
namespace iceberg {
2527

26-
class ICEBERG_EXPORT DemoTable : public Table {
28+
class ICEBERG_EXPORT Demo {
2729
public:
28-
DemoTable() = default;
29-
~DemoTable() override = default;
30+
Demo() = default;
31+
virtual ~Demo() = default;
3032

31-
std::string print() const override;
33+
virtual std::string print() const;
3234
};
3335

3436
} // namespace iceberg

src/iceberg/location_provider.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#pragma once
21+
22+
#include <string>
23+
24+
#include "iceberg/iceberg_export.h"
25+
#include "iceberg/type_fwd.h"
26+
27+
namespace iceberg {
28+
29+
/// \brief Interface for providing data file locations to write tasks.
30+
class ICEBERG_EXPORT LocationProvider {
31+
public:
32+
virtual ~LocationProvider() = default;
33+
34+
/// \brief Return a fully-qualified data file location for the given filename.
35+
///
36+
/// \param filename a file name
37+
/// \return a fully-qualified location URI for a data file
38+
virtual std::string NewDataLocation(const std::string& filename) = 0;
39+
40+
/// \brief Return a fully-qualified data file location for the given partition and
41+
/// filename.
42+
///
43+
/// \param spec a partition spec
44+
/// \param partition_data a tuple of partition data for data in the file, matching the
45+
/// given spec
46+
/// \param filename a file name
47+
/// \return a fully-qualified location URI for a data file
48+
///
49+
/// TODO(wgtmac): StructLike is not well thought yet, we may wrap an ArrowArray
50+
/// with single row in StructLike.
51+
virtual std::string NewDataLocation(const PartitionSpec& spec,
52+
const StructLike& partition_data,
53+
const std::string& filename) = 0;
54+
};
55+
56+
} // namespace iceberg

0 commit comments

Comments
 (0)