Skip to content
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 Timestamp type #6

Merged
merged 2 commits into from
Sep 10, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

Added `Timestamp` type.

## [1.3.2]

Added `ToValue` implementation for for `Vec<Vec<u8>>` which used to create Graph Node schema object of the form `[Bytes]`.
Expand Down
21 changes: 19 additions & 2 deletions pb/sf/substreams/sink/entity/v1/entity.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion proto/sf/substreams/sink/entity/v1/entity.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ message Value {
string string = 4;
string bytes = 5;
bool bool = 6;
int64 timestamp = 7;

//reserved 7 to 9; // For future types
//reserved 8 to 9; // For future types

Array array = 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub mod entity_change {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Value {
#[prost(oneof="value::Typed", tags="1, 2, 3, 4, 5, 6, 10")]
#[prost(oneof="value::Typed", tags="1, 2, 3, 4, 5, 6, 7, 10")]
pub typed: ::core::option::Option<value::Typed>,
}
/// Nested message and enum types in `Value`.
Expand All @@ -83,7 +83,9 @@ pub mod value {
Bytes(::prost::alloc::string::String),
#[prost(bool, tag="6")]
Bool(bool),
// reserved 7 to 9; // For future types
#[prost(int64, tag="7")]
Timestamp(i64),
// reserved 8 to 9; // For future types

#[prost(message, tag="10")]
Array(super::Array),
Expand Down
35 changes: 34 additions & 1 deletion substreams-entity-change/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ impl ToValue for Vec<BigDecimal> {
impl ToValue for &::prost_types::Timestamp {
fn to_value(self) -> Value {
Value {
typed: Some(Typed::String(self.to_string())),
typed: Some(Typed::Timestamp(
self.seconds * 1_000_000 + self.nanos as i64 / 1000,
)),
}
}
}
Expand Down Expand Up @@ -471,6 +473,37 @@ mod test {

use super::Tables;

#[test]
fn test_timestamp() {
let mut tables = Tables::new();
tables.create_row("table", "1").set(
"field",
&::prost_types::Timestamp {
seconds: 123,
nanos: 456789000,
},
);

let changes = tables.to_entity_changes();
assert_eq!(changes.entity_changes.len(), 1);
assert_eq!(
changes.entity_changes[0],
EntityChange {
entity: "table".to_string(),
id: "1".to_string(),
operation: Operation::Create as i32,
fields: vec![Field {
name: "field".to_string(),
new_value: Some(Value {
typed: Some(Typed::Timestamp(123456789)),
}),
..Default::default()
}],
..Default::default()
}
);
}

#[test]
fn test_vec_vec_u8() {
let mut tables = Tables::new();
Expand Down
Loading