-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-parquet] parquet default processor extractor step (#601)
### Description This is to add an extractor step for parquet default processor. Changes invovled: - added a map to filter parquet structs. - added a new model RawTableItem and a trait `TableItemConvertible` which is implemented for both Parquet and Postgres TableItem. - updated a (Postgres) `TableItem::from_write_table_item` to return `table_items` only Context on why we added a new `RawTableItem` model: **tl;dr** This is to reduce the duplicated code as much as possible and reuse the common parsing logic. RawTableItem represents parsed transaction data. This struct will act as the unified output from the parsing function. Parquet TableItem and Postgres TableItem will implement a TableItemConvertible trait to convert RawTableItem into the appropriate format. With this approach, parsing logic is centralized, and each processor (Postgres or Parquet) can convert RawTableItem to its respective TableItem type, keeping code DRY and maintainable while supporting format-specific needs.
- Loading branch information
Showing
134 changed files
with
570 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod block_metadata_transactions; | ||
pub mod move_resources; | ||
pub mod move_tables; | ||
|
||
// parquet models | ||
pub mod parquet_move_modules; | ||
pub mod parquet_move_resources; | ||
pub mod parquet_move_tables; | ||
pub mod parquet_transactions; | ||
pub mod parquet_write_set_changes; | ||
pub mod raw_table_items; |
137 changes: 0 additions & 137 deletions
137
rust/processor/src/db/common/models/default_models/move_tables.rs
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
rust/processor/src/db/common/models/default_models/raw_table_items.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
use crate::{ | ||
db::postgres::models::default_models::move_tables::{CurrentTableItem, TableItem}, | ||
utils::util::{hash_str, standardize_address}, | ||
}; | ||
use aptos_protos::transaction::v1::{DeleteTableItem, WriteTableItem}; | ||
|
||
/// RawTableItem is a struct that will be used to converted into Postgres or Parquet TableItem | ||
pub struct RawTableItem { | ||
pub txn_version: i64, | ||
pub block_timestamp: chrono::NaiveDateTime, | ||
pub write_set_change_index: i64, | ||
pub transaction_block_height: i64, | ||
pub table_key: String, | ||
pub table_handle: String, | ||
pub decoded_key: String, | ||
pub decoded_value: Option<String>, | ||
pub is_deleted: bool, | ||
} | ||
|
||
impl RawTableItem { | ||
pub fn from_write_table_item( | ||
write_table_item: &WriteTableItem, | ||
write_set_change_index: i64, | ||
txn_version: i64, | ||
transaction_block_height: i64, | ||
block_timestamp: chrono::NaiveDateTime, | ||
) -> (Self, CurrentTableItem) { | ||
( | ||
Self { | ||
txn_version, | ||
write_set_change_index, | ||
transaction_block_height, | ||
table_key: write_table_item.key.to_string(), | ||
table_handle: standardize_address(&write_table_item.handle.to_string()), | ||
decoded_key: write_table_item.data.as_ref().unwrap().key.clone(), | ||
decoded_value: Some(write_table_item.data.as_ref().unwrap().value.clone()), | ||
is_deleted: false, | ||
block_timestamp, | ||
}, | ||
CurrentTableItem { | ||
table_handle: standardize_address(&write_table_item.handle.to_string()), | ||
key_hash: hash_str(&write_table_item.key.to_string()), | ||
key: write_table_item.key.to_string(), | ||
decoded_key: serde_json::from_str( | ||
write_table_item.data.as_ref().unwrap().key.as_str(), | ||
) | ||
.unwrap(), | ||
decoded_value: serde_json::from_str( | ||
write_table_item.data.as_ref().unwrap().value.as_str(), | ||
) | ||
.unwrap(), | ||
last_transaction_version: txn_version, | ||
is_deleted: false, | ||
}, | ||
) | ||
} | ||
|
||
pub fn from_delete_table_item( | ||
delete_table_item: &DeleteTableItem, | ||
write_set_change_index: i64, | ||
txn_version: i64, | ||
transaction_block_height: i64, | ||
block_timestamp: chrono::NaiveDateTime, | ||
) -> (Self, CurrentTableItem) { | ||
( | ||
Self { | ||
txn_version, | ||
write_set_change_index, | ||
transaction_block_height, | ||
table_key: delete_table_item.key.to_string(), | ||
table_handle: standardize_address(&delete_table_item.handle.to_string()), | ||
decoded_key: delete_table_item.data.as_ref().unwrap().key.clone(), | ||
decoded_value: None, | ||
is_deleted: true, | ||
block_timestamp, | ||
}, | ||
CurrentTableItem { | ||
table_handle: standardize_address(&delete_table_item.handle.to_string()), | ||
key_hash: hash_str(&delete_table_item.key.to_string()), | ||
key: delete_table_item.key.to_string(), | ||
decoded_key: serde_json::from_str( | ||
delete_table_item.data.as_ref().unwrap().key.as_str(), | ||
) | ||
.unwrap(), | ||
decoded_value: None, | ||
last_transaction_version: txn_version, | ||
is_deleted: true, | ||
}, | ||
) | ||
} | ||
|
||
pub fn postgres_table_item_from_write_item( | ||
write_table_item: &WriteTableItem, | ||
write_set_change_index: i64, | ||
txn_version: i64, | ||
transaction_block_height: i64, | ||
block_timestamp: chrono::NaiveDateTime, | ||
) -> TableItem { | ||
let (raw_table_item, _current_table_item) = RawTableItem::from_write_table_item( | ||
write_table_item, | ||
write_set_change_index, | ||
txn_version, | ||
transaction_block_height, | ||
block_timestamp, | ||
); | ||
TableItem::from_raw(&raw_table_item) | ||
} | ||
} | ||
|
||
pub trait TableItemConvertible { | ||
fn from_raw(raw_item: &RawTableItem) -> Self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod account_transaction_models; | ||
pub mod ans_models; | ||
pub mod coin_models; | ||
pub mod default_models; | ||
pub mod events_models; | ||
pub mod fungible_asset_models; | ||
pub mod ledger_info; | ||
pub mod object_models; | ||
pub mod processor_status; | ||
pub mod property_map; | ||
pub mod resources; | ||
pub mod stake_models; | ||
pub mod token_models; | ||
pub mod token_v2_models; | ||
pub mod transaction_metadata_model; | ||
pub mod user_transactions_models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
pub mod common; | ||
pub mod parquet; | ||
pub mod postgres; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// parquet models | ||
pub mod parquet_move_modules; | ||
pub mod parquet_move_resources; | ||
pub mod parquet_move_tables; | ||
pub mod parquet_transactions; | ||
pub mod parquet_write_set_changes; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod default_models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.