Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ set(ICEBERG_SOURCES
expression/term.cc
file_reader.cc
file_writer.cc
inspect/history_table.cc
Comment thread
All-less marked this conversation as resolved.
inspect/metadata_table.cc
inspect/snapshots_table.cc
inheritable_metadata.cc
json_serde.cc
location_provider.cc
Expand Down
18 changes: 18 additions & 0 deletions src/iceberg/inspect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

iceberg_install_all_headers(iceberg/inspect)
55 changes: 55 additions & 0 deletions src/iceberg/inspect/history_table.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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/inspect/history_table.h"

#include <memory>
#include <utility>

#include "iceberg/inspect/metadata_table.h"
#include "iceberg/schema.h"
#include "iceberg/schema_field.h"
#include "iceberg/table_identifier.h"
#include "iceberg/type.h"

namespace iceberg {

HistoryTable::HistoryTable(std::shared_ptr<Table> table)
: MetadataTable(table, CreateName(table->name())) {
this->schema_ = std::make_shared<Schema>(
std::vector<SchemaField>{
SchemaField::MakeRequired(1, "made_current_at", timestamp_tz()),
SchemaField::MakeRequired(2, "snapshot_id", int64()),
SchemaField::MakeOptional(3, "parent_id", int64()),
SchemaField::MakeRequired(4, "is_current_ancestor", boolean())},
1);
this->schemas_[schema_->schema_id()] = schema_;
}

HistoryTable::~HistoryTable() = default;

TableIdentifier HistoryTable::CreateName(const TableIdentifier& source_name) {
return TableIdentifier{source_name.ns, source_name.name + ".history"};
}

Result<std::unique_ptr<HistoryTable>> HistoryTable::Make(std::shared_ptr<Table> table) {
return std::unique_ptr<HistoryTable>(new HistoryTable(table));
}

} // namespace iceberg
57 changes: 57 additions & 0 deletions src/iceberg/inspect/history_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.
*/

#pragma once

#include <memory>

#include "iceberg/iceberg_export.h"
#include "iceberg/inspect/metadata_table.h"
#include "iceberg/result.h"
#include "iceberg/table.h"

namespace iceberg {

/// \brief History metadata table
///
/// History is based on the table's snapshot log, which logs each update
/// to the table's current snapshot. Each row has columns:
/// - made_current_at (long, timestamp)
/// - snapshot_id (long)
/// - parent_id (long, optional)
/// - is_current_ancestor (bool)
class ICEBERG_EXPORT HistoryTable : public MetadataTable {
public:
/// \brief Create a HistoryTable from table metadata
///
/// \param[in] table The source table
/// \return A HistoryTable instance or error status
static Result<std::unique_ptr<HistoryTable>> Make(std::shared_ptr<Table> table);

~HistoryTable() override;

MetadataTableType type() const noexcept override { return MetadataTableType::kHistory; }

private:
explicit HistoryTable(std::shared_ptr<Table> table);

TableIdentifier CreateName(const TableIdentifier& source_name);
};

} // namespace iceberg
25 changes: 25 additions & 0 deletions src/iceberg/inspect/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.

install_headers(
[
'history_table.h',
'metadata_table.h',
'snapshots_table.h',
],
subdir: 'iceberg/inspect',
)
67 changes: 67 additions & 0 deletions src/iceberg/inspect/metadata_table.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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/inspect/metadata_table.h"

#include <memory>
#include <string>
#include <utility>

#include "iceberg/file_io.h"
#include "iceberg/inspect/history_table.h"
#include "iceberg/inspect/snapshots_table.h"
#include "iceberg/schema.h"
#include "iceberg/schema_field.h"
#include "iceberg/table_identifier.h"
#include "iceberg/table_metadata.h"
#include "iceberg/table_scan.h"
#include "iceberg/type.h"
#include "iceberg/type_fwd.h"
#include "iceberg/util/uuid.h"

namespace iceberg {

MetadataTable::MetadataTable(std::shared_ptr<Table> source_table,
TableIdentifier identifier)
: StaticTable(identifier, source_table->metadata(),
std::string(source_table->metadata_file_location()), source_table->io(),
source_table->catalog()),
source_table_(std::move(source_table)) {
uuid_ = Uuid::GenerateV4().ToString();
}

MetadataTable::~MetadataTable() = default;

Status MetadataTable::Refresh() { return source_table_->Refresh(); }

Result<std::unique_ptr<TableScanBuilder>> MetadataTable::NewScan() const {
return NotSupported("TODO: Scanning metadata tables is not yet supported");
};

Result<std::unique_ptr<SnapshotsTable>> MetadataTableFactory::GetSnapshotsTable(
std::shared_ptr<Table> table) {
return SnapshotsTable::Make(table);
}

Result<std::unique_ptr<HistoryTable>> MetadataTableFactory::GetHistoryTable(
std::shared_ptr<Table> table) {
return HistoryTable::Make(table);
}

} // namespace iceberg
Loading