iceberg-cpp
Loading...
Searching...
No Matches
hive_utils.h
Go to the documentation of this file.
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#include <string_view>
24#include <unordered_map>
25#include <vector>
26
29#include "iceberg/result.h"
31
34
35namespace iceberg::hive {
36
38inline constexpr std::string_view kMetadataLocationKey = "metadata_location";
39inline constexpr std::string_view kTableTypeKey = "table_type";
40inline constexpr std::string_view kTableTypeIceberg = "ICEBERG";
41inline constexpr std::string_view kExternalKey = "EXTERNAL";
42inline constexpr std::string_view kExternalTrue = "TRUE";
43
45inline constexpr std::string_view kCommentProperty = "comment";
46inline constexpr std::string_view kLocationProperty = "location";
47
49inline constexpr std::string_view kHmsTableOwnerProperty = "hive.metastore.table.owner";
50
52inline constexpr std::string_view kHmsDbOwnerProperty = "hive.metastore.database.owner";
53inline constexpr std::string_view kHmsDbOwnerTypeProperty =
54 "hive.metastore.database.owner-type";
55
57inline constexpr std::string_view kLazySimpleSerDe =
58 "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe";
59inline constexpr std::string_view kFileInputFormat =
60 "org.apache.hadoop.mapred.FileInputFormat";
61inline constexpr std::string_view kFileOutputFormat =
62 "org.apache.hadoop.mapred.FileOutputFormat";
63
65struct ICEBERG_HIVE_EXPORT HiveDatabase {
66 std::string name;
67 std::string description;
68 std::string location_uri;
69 std::unordered_map<std::string, std::string> parameters;
70 std::string owner_name;
71 std::string owner_type; // "USER", "GROUP" or "ROLE"; empty means HMS-default
72};
73
75struct ICEBERG_HIVE_EXPORT HiveTable {
76 std::string db_name;
77 std::string table_name;
78 std::string owner;
79 std::string table_type; // "EXTERNAL_TABLE" for Iceberg tables
80 std::string location;
81 std::vector<HiveColumn> columns;
82 std::unordered_map<std::string, std::string> parameters;
83 std::string serde;
84 std::string input_format;
85 std::string output_format;
86};
87
89struct ICEBERG_HIVE_EXPORT HiveNamespace {
90 Namespace ns;
91 std::unordered_map<std::string, std::string> properties;
92};
93
96 const Namespace& ns, const std::unordered_map<std::string, std::string>& properties);
97
99ICEBERG_HIVE_EXPORT HiveNamespace ConvertFromHiveDatabase(const HiveDatabase& database);
100
105 const TableIdentifier& identifier, const std::vector<HiveColumn>& columns,
106 std::string_view metadata_location, std::string_view location,
107 const std::unordered_map<std::string, std::string>& table_properties);
108
111 const std::unordered_map<std::string, std::string>& table_parameters);
112
114ICEBERG_HIVE_EXPORT Status ValidateIcebergTable(
115 const TableIdentifier& identifier,
116 const std::unordered_map<std::string, std::string>& table_parameters);
117
119ICEBERG_HIVE_EXPORT std::string GetDefaultTableLocation(std::string_view warehouse,
120 const Namespace& ns,
121 std::string_view table_name);
122
124ICEBERG_HIVE_EXPORT Status ValidateNamespace(const Namespace& ns);
125
128ICEBERG_HIVE_EXPORT Status
129ValidateOwnerSettings(const std::unordered_map<std::string, std::string>& properties);
130
131} // namespace iceberg::hive
Definition expected.h:1199
Render Iceberg schemas as Hive type strings.
Define symbol visibility macros for the Hive catalog library.
Hive catalog APIs.
Definition hive_catalog.h:34
constexpr std::string_view kHmsTableOwnerProperty
HMS table owner key.
Definition hive_utils.h:49
ICEBERG_HIVE_EXPORT Status ValidateNamespace(const Namespace &ns)
Require a single-level namespace.
ICEBERG_HIVE_EXPORT Result< HiveTable > ConvertToHiveTable(const TableIdentifier &identifier, const std::vector< HiveColumn > &columns, std::string_view metadata_location, std::string_view location, const std::unordered_map< std::string, std::string > &table_properties)
Build an external Iceberg table with a LazySimpleSerDe descriptor. Translate gc.enabled to external....
ICEBERG_HIVE_EXPORT std::string GetDefaultTableLocation(std::string_view warehouse, const Namespace &ns, std::string_view table_name)
Return <warehouse>/<namespace>.db/<table_name>.
ICEBERG_HIVE_EXPORT Status ValidateIcebergTable(const TableIdentifier &identifier, const std::unordered_map< std::string, std::string > &table_parameters)
Require table_type=ICEBERG (case-insensitive).
constexpr std::string_view kMetadataLocationKey
Iceberg-on-HMS parameter keys.
Definition hive_utils.h:38
ICEBERG_HIVE_EXPORT Status ValidateOwnerSettings(const std::unordered_map< std::string, std::string > &properties)
Require owner when owner-type is set. owner-type must be USER, GROUP or ROLE.
ICEBERG_HIVE_EXPORT Result< std::string > GetMetadataLocation(const std::unordered_map< std::string, std::string > &table_parameters)
Return metadata_location, or kNotFound if absent or empty.
constexpr std::string_view kCommentProperty
Property keys lifted into HMS fields.
Definition hive_utils.h:45
constexpr std::string_view kHmsDbOwnerProperty
HMS database owner keys.
Definition hive_utils.h:52
ICEBERG_HIVE_EXPORT Result< HiveDatabase > ConvertToHiveDatabase(const Namespace &ns, const std::unordered_map< std::string, std::string > &properties)
Lift reserved properties into HMS fields. Caller resolves defaults.
ICEBERG_HIVE_EXPORT HiveNamespace ConvertFromHiveDatabase(const HiveDatabase &database)
Extract namespace properties from an HMS database.
constexpr std::string_view kLazySimpleSerDe
Fallback storage descriptor classes.
Definition hive_utils.h:57
Define Result, Status, and error helpers.
A namespace in a catalog.
Definition table_identifier.h:35
Identifies a table in iceberg catalog.
Definition table_identifier.h:46
Subset of HMS Database used by HiveCatalog.
Definition hive_utils.h:65
Namespace and properties read from HMS.
Definition hive_utils.h:89
Subset of HMS Table used by HiveCatalog.
Definition hive_utils.h:75