Skip to content

Commit 567a8bc

Browse files
committed
feat: add paimon-cpp public headers
1 parent b690461 commit 567a8bc

File tree

86 files changed

+8360
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+8360
-0
lines changed

include/paimon/api.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2024-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Coarse public API while the library is in development
18+
19+
#pragma once
20+
21+
#include "paimon/commit_context.h" // IWYU pragma: export
22+
#include "paimon/defs.h" // IWYU pragma: export
23+
#include "paimon/factories/factory.h" // IWYU pragma: export
24+
#include "paimon/file_store_commit.h" // IWYU pragma: export
25+
#include "paimon/file_store_write.h" // IWYU pragma: export
26+
#include "paimon/fs/file_system_factory.h" // IWYU pragma: export
27+
#include "paimon/memory/memory_pool.h" // IWYU pragma: export
28+
#include "paimon/predicate/predicate.h" // IWYU pragma: export
29+
#include "paimon/read_context.h" // IWYU pragma: export
30+
#include "paimon/reader/batch_reader.h" // IWYU pragma: export
31+
#include "paimon/record_batch.h" // IWYU pragma: export
32+
#include "paimon/result.h" // IWYU pragma: export
33+
#include "paimon/scan_context.h" // IWYU pragma: export
34+
#include "paimon/status.h" // IWYU pragma: export
35+
#include "paimon/table/source/table_read.h" // IWYU pragma: export
36+
#include "paimon/table/source/table_scan.h" // IWYU pragma: export
37+
#include "paimon/write_context.h" // IWYU pragma: export
38+
39+
/// Top-level namespace for Paimon C++ API.
40+
namespace paimon {}

include/paimon/arrow/abi.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
// Adapted from Apache Arrow
19+
// https://github.com/apache/arrow/blob/main/cpp/src/arrow/c/abi.h
20+
21+
/// \file abi.h Arrow C Data Interface
22+
///
23+
/// The Arrow C Data interface defines a very small, stable set
24+
/// of C definitions which can be easily copied into any project's
25+
/// source code and vendored to be used for columnar data interchange
26+
/// in the Arrow format. For non-C/C++ languages and runtimes,
27+
/// it should be almost as easy to translate the C definitions into
28+
/// the corresponding C FFI declarations.
29+
///
30+
/// Applications and libraries can therefore work with Arrow memory
31+
/// without necessarily using the Arrow libraries or reinventing
32+
/// the wheel. Developers can choose between tight integration
33+
/// with the Arrow software project or minimal integration with
34+
/// the Arrow format only.
35+
36+
#pragma once
37+
38+
#include <cstdint>
39+
40+
// Spec and documentation: https://arrow.apache.org/docs/format/CDataInterface.html
41+
42+
#ifdef __cplusplus
43+
extern "C" {
44+
#endif
45+
46+
#ifndef ARROW_C_DATA_INTERFACE
47+
#define ARROW_C_DATA_INTERFACE
48+
49+
#define ARROW_FLAG_DICTIONARY_ORDERED 1
50+
#define ARROW_FLAG_NULLABLE 2
51+
#define ARROW_FLAG_MAP_KEYS_SORTED 4
52+
53+
struct ArrowSchema {
54+
// Array type description
55+
const char* format;
56+
const char* name;
57+
const char* metadata;
58+
int64_t flags;
59+
int64_t n_children;
60+
struct ArrowSchema** children;
61+
struct ArrowSchema* dictionary;
62+
63+
// Release callback
64+
void (*release)(struct ArrowSchema*);
65+
// Opaque producer-specific data
66+
void* private_data;
67+
};
68+
69+
struct ArrowArray {
70+
// Array data description
71+
int64_t length;
72+
int64_t null_count;
73+
int64_t offset;
74+
int64_t n_buffers;
75+
int64_t n_children;
76+
const void** buffers;
77+
struct ArrowArray** children;
78+
struct ArrowArray* dictionary;
79+
80+
// Release callback
81+
void (*release)(struct ArrowArray*);
82+
// Opaque producer-specific data
83+
void* private_data;
84+
};
85+
86+
#endif // ARROW_C_DATA_INTERFACE
87+
88+
#ifdef __cplusplus
89+
}
90+
#endif

include/paimon/catalog/catalog.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2024-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <map>
20+
#include <memory>
21+
#include <string>
22+
#include <vector>
23+
24+
#include "paimon/catalog/identifier.h"
25+
#include "paimon/result.h"
26+
#include "paimon/status.h"
27+
#include "paimon/type_fwd.h"
28+
#include "paimon/visibility.h"
29+
30+
struct ArrowSchema;
31+
32+
namespace paimon {
33+
class Identifier;
34+
35+
/// This interface is responsible for reading and writing metadata such as database/table from a
36+
/// paimon catalog.
37+
class PAIMON_EXPORT Catalog {
38+
public:
39+
static const char SYSTEM_DATABASE_NAME[];
40+
static const char SYSTEM_TABLE_SPLITTER[];
41+
static const char DB_SUFFIX[];
42+
static const char DB_LOCATION_PROP[];
43+
44+
/// %Factory method for creating a `Catalog` instance.
45+
///
46+
/// @param root_path Path to the root directory where the catalog is located.
47+
/// @param options Configuration options for catalog initialization.
48+
/// @return A result containing a unique pointer to a `Catalog` instance, or an error status.
49+
static Result<std::unique_ptr<Catalog>> Create(
50+
const std::string& root_path, const std::map<std::string, std::string>& options);
51+
52+
virtual ~Catalog() = default;
53+
54+
/// Creates a database with the specified properties.
55+
///
56+
/// @param name Name of the database to be created.
57+
/// @param options Additional properties associated with the database.
58+
/// @param ignore_if_exists If true, no action is taken if the database already exists.
59+
/// If false, an error status is returned if the database exists.
60+
/// @return A status indicating success or failure.
61+
virtual Status CreateDatabase(const std::string& name,
62+
const std::map<std::string, std::string>& options,
63+
bool ignore_if_exists) = 0;
64+
65+
/// Creates a new table in the catalog.
66+
///
67+
/// @note System tables cannot be created using this method.
68+
///
69+
/// @param identifier Identifier of the table to be created.
70+
/// @param c_schema The schema of the table to be created.
71+
/// @param partition_keys List of columns that should be used as partition keys for the table.
72+
/// @param primary_keys List of columns that should be used as primary keys for the table.
73+
/// @param options Additional table-specific options.
74+
/// @param ignore_if_exists If true, no action is taken if the table already exists.
75+
/// If false, an error status is returned if the table exists.
76+
/// @return A status indicating success or failure.
77+
virtual Status CreateTable(const Identifier& identifier, ArrowSchema* c_schema,
78+
const std::vector<std::string>& partition_keys,
79+
const std::vector<std::string>& primary_keys,
80+
const std::map<std::string, std::string>& options,
81+
bool ignore_if_exists) = 0;
82+
83+
/// Lists all the databases available in the catalog.
84+
///
85+
/// @return A result containing a vector of database names, or an error status.
86+
virtual Result<std::vector<std::string>> ListDatabases() const = 0;
87+
88+
/// Lists all the tables within a specified database.
89+
///
90+
/// @note System tables will not be listed.
91+
///
92+
/// @param db_name The name of the database to list tables from.
93+
/// @return A result containing a vector of table names in the specified database, or an error
94+
/// status.
95+
virtual Result<std::vector<std::string>> ListTables(const std::string& db_name) const = 0;
96+
};
97+
98+
} // namespace paimon
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2024-present Alibaba Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
21+
#include "paimon/type_fwd.h"
22+
#include "paimon/visibility.h"
23+
24+
namespace paimon {
25+
26+
/// An identifier for a table containing database and table name.
27+
class PAIMON_EXPORT Identifier {
28+
public:
29+
Identifier(const std::string& database, const std::string& table);
30+
31+
bool operator==(const Identifier& other);
32+
const std::string& GetDatabaseName() const;
33+
const std::string& GetTableName() const;
34+
std::string ToString() const;
35+
36+
private:
37+
const std::string database_;
38+
const std::string table_;
39+
};
40+
41+
} // namespace paimon

0 commit comments

Comments
 (0)