-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Parquet Events Processor #451
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28e1ec8
temp
yuunlimm 2563261
remove logs
yuunlimm 47a017f
add more metrics
yuunlimm 430d09c
Add Parquet Events Processor
yuunlimm 63c5f6d
add validator txn handling logi
yuunlimm 1fff88e
use context
yuunlimm d103458
change variable name
yuunlimm 9b02b24
rebase
yuunlimm b28e1c5
add event_version for events v2 future proofing
yuunlimm 2e1457a
add block_timestamp to events
yuunlimm 1c8de5d
fix conflicts
yuunlimm 53cd334
handle validator txn event to have default size of 0
yuunlimm 855062d
rebase
yuunlimm 3b717c6
lint
yuunlimm 9dd46c6
add logs when event size and event size info size don't match
yuunlimm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub mod events; | ||
|
||
// parquet model | ||
pub mod parquet_events; |
109 changes: 109 additions & 0 deletions
109
rust/processor/src/db/common/models/events_models/parquet_events.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,109 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![allow(clippy::extra_unused_lifetimes)] | ||
|
||
use crate::{ | ||
bq_analytics::generic_parquet_processor::{GetTimeStamp, HasVersion, NamedTable}, | ||
utils::util::{standardize_address, truncate_str}, | ||
}; | ||
use allocative_derive::Allocative; | ||
use aptos_protos::transaction::v1::{Event as EventPB, EventSizeInfo}; | ||
use parquet_derive::ParquetRecordWriter; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
// p99 currently is 303 so using 300 as a safe max length | ||
const EVENT_TYPE_MAX_LENGTH: usize = 300; | ||
|
||
#[derive(Allocative, Clone, Debug, Default, Deserialize, ParquetRecordWriter, Serialize)] | ||
pub struct Event { | ||
pub txn_version: i64, | ||
pub account_address: String, | ||
pub sequence_number: i64, | ||
pub creation_number: i64, | ||
pub block_height: i64, | ||
pub event_type: String, | ||
pub data: String, | ||
pub event_index: i64, | ||
pub indexed_type: String, | ||
pub type_tag_bytes: i64, | ||
pub total_bytes: i64, | ||
pub event_version: i8, | ||
#[allocative(skip)] | ||
pub block_timestamp: chrono::NaiveDateTime, | ||
} | ||
|
||
impl NamedTable for Event { | ||
const TABLE_NAME: &'static str = "events"; | ||
} | ||
|
||
impl HasVersion for Event { | ||
fn version(&self) -> i64 { | ||
self.txn_version | ||
} | ||
} | ||
|
||
impl GetTimeStamp for Event { | ||
fn get_timestamp(&self) -> chrono::NaiveDateTime { | ||
self.block_timestamp | ||
} | ||
} | ||
|
||
impl Event { | ||
pub fn from_event( | ||
event: &EventPB, | ||
txn_version: i64, | ||
block_height: i64, | ||
event_index: i64, | ||
size_info: &EventSizeInfo, | ||
block_timestamp: chrono::NaiveDateTime, | ||
) -> Self { | ||
let event_type: &str = event.type_str.as_ref(); | ||
Event { | ||
account_address: standardize_address( | ||
event.key.as_ref().unwrap().account_address.as_str(), | ||
), | ||
creation_number: event.key.as_ref().unwrap().creation_number as i64, | ||
sequence_number: event.sequence_number as i64, | ||
txn_version, | ||
block_height, | ||
event_type: event_type.to_string(), | ||
data: event.data.clone(), | ||
event_index, | ||
indexed_type: truncate_str(event_type, EVENT_TYPE_MAX_LENGTH), | ||
type_tag_bytes: size_info.type_tag_bytes as i64, | ||
total_bytes: size_info.total_bytes as i64, | ||
event_version: 1i8, // this is for future proofing. TODO: change when events v2 comes | ||
block_timestamp, | ||
} | ||
} | ||
|
||
pub fn from_events( | ||
events: &[EventPB], | ||
txn_version: i64, | ||
block_height: i64, | ||
event_size_info: &[EventSizeInfo], | ||
block_timestamp: chrono::NaiveDateTime, | ||
) -> Vec<Self> { | ||
events | ||
.iter() | ||
.enumerate() | ||
.map(|(index, event)| { | ||
let size_info = event_size_info.get(index).unwrap_or(&EventSizeInfo { | ||
type_tag_bytes: 0, | ||
total_bytes: 0, | ||
}); | ||
Self::from_event( | ||
event, | ||
txn_version, | ||
block_height, | ||
index as i64, | ||
size_info, | ||
block_timestamp, | ||
) | ||
}) | ||
.collect::<Vec<ParquetEventModel>>() | ||
} | ||
} | ||
|
||
pub type ParquetEventModel = Event; |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new logic added to handle validator txn type, as this doesn't have size info added yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larry-aptos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one sec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's start a thread to discuss this; these transactions do come with event and event size = 0 may not be a good choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably need to emit a warning and some metrics when this happens.