-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sreekanth <[email protected]>
- Loading branch information
Showing
11 changed files
with
81 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,20 @@ | ||
use numaflow::map::start_uds_server; | ||
use numaflow::map; | ||
use std::error::Error; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let map_handler = cat::Cat::new(); | ||
|
||
start_uds_server(map_handler).await?; | ||
|
||
Ok(()) | ||
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> { | ||
map::Server::new(Cat).start().await | ||
} | ||
|
||
pub(crate) mod cat { | ||
pub(crate) struct Cat {} | ||
|
||
impl Cat { | ||
pub(crate) fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
use numaflow::map; | ||
struct Cat; | ||
|
||
#[tonic::async_trait] | ||
impl map::Mapper for Cat { | ||
async fn map<T>(&self, input: T) -> Vec<map::Message> | ||
where | ||
T: map::Datum + Send + Sync + 'static, | ||
{ | ||
vec![map::Message { | ||
keys: input.keys().clone(), | ||
value: input.value().clone(), | ||
tags: vec![], | ||
}] | ||
} | ||
#[tonic::async_trait] | ||
impl map::Mapper for Cat { | ||
async fn map(&self, input: map::MapRequest) -> Vec<map::Message> { | ||
vec![map::Message { | ||
keys: input.keys, | ||
value: input.value, | ||
tags: vec![], | ||
}] | ||
} | ||
} |
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 @@ | ||
target/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,51 @@ | ||
use numaflow::map::start_uds_server; | ||
use numaflow::map; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let map_handler = tickgen::TickGen::new(); | ||
|
||
start_uds_server(map_handler).await?; | ||
|
||
Ok(()) | ||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
map::Server::new(TickGen).start().await | ||
} | ||
|
||
pub(crate) mod tickgen { | ||
use chrono::{SecondsFormat, TimeZone, Utc}; | ||
use numaflow::map; | ||
use numaflow::function::{Datum, Message, Metadata}; | ||
use serde::Serialize; | ||
use tokio::sync::mpsc::Receiver; | ||
|
||
pub(crate) struct TickGen {} | ||
|
||
#[derive(serde::Deserialize)] | ||
struct Data { | ||
value: u64, | ||
} | ||
|
||
#[derive(serde::Deserialize)] | ||
struct Payload { | ||
#[serde(rename = "Data")] | ||
data: Data, | ||
#[serde(rename = "Createdts")] | ||
created_ts: i64, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use chrono::{SecondsFormat, TimeZone, Utc}; | ||
use chrono::{SecondsFormat, TimeZone, Utc}; | ||
use serde::Serialize; | ||
|
||
#[test] | ||
fn deserialize() { | ||
let input = r#"{"Data":{"value":5},"Createdts":1689723721606016637}"#; | ||
let payload: Payload = serde_json::from_str(input).unwrap(); | ||
assert_eq!(payload.data.value, 5); | ||
assert_eq!(payload.created_ts, 1689723721606016637); | ||
} | ||
struct TickGen; | ||
|
||
#[test] | ||
fn to_rfc3339nanos() { | ||
let input = r#"{"Data":{"value":5},"Createdts":1689723721606016637}"#; | ||
let payload: Payload = serde_json::from_str(input).unwrap(); | ||
assert_eq!( | ||
Utc.timestamp_nanos(payload.created_ts) | ||
.to_rfc3339_opts(SecondsFormat::Nanos, true), | ||
"2023-07-18T23:42:01.606016637Z" | ||
); | ||
} | ||
} | ||
#[derive(serde::Deserialize)] | ||
struct Data { | ||
value: u64, | ||
} | ||
|
||
impl TickGen { | ||
pub(crate) fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
#[derive(serde::Deserialize)] | ||
struct Payload { | ||
#[serde(rename = "Data")] | ||
data: Data, | ||
#[serde(rename = "Createdts")] | ||
created_ts: i64, | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct ResultPayload { | ||
value: u64, | ||
time: String, | ||
} | ||
#[derive(Serialize)] | ||
struct ResultPayload { | ||
value: u64, | ||
time: String, | ||
} | ||
|
||
#[tonic::async_trait] | ||
impl map::Mapper for TickGen { | ||
async fn map<T: map::Datum + Send + Sync + 'static>( | ||
&self, | ||
input: T, | ||
) -> Vec<map::Message> { | ||
let value = input.value(); | ||
if let Ok(payload) = serde_json::from_slice::<Payload>(value) { | ||
let ts = Utc | ||
.timestamp_nanos(payload.created_ts) | ||
.to_rfc3339_opts(SecondsFormat::Nanos, true); | ||
vec![map::Message { | ||
keys: input.keys().clone(), | ||
value: serde_json::to_vec(&ResultPayload { | ||
value: payload.data.value, | ||
time: ts, | ||
}) | ||
.unwrap_or(vec![]), | ||
tags: vec![], | ||
}] | ||
} else { | ||
vec![] | ||
} | ||
} | ||
#[tonic::async_trait] | ||
impl map::Mapper for TickGen { | ||
async fn map(&self, input: map::MapRequest) -> Vec<map::Message> { | ||
let Ok(payload) = serde_json::from_slice::<Payload>(&input.value) else { | ||
return vec![]; | ||
}; | ||
let ts = Utc | ||
.timestamp_nanos(payload.created_ts) | ||
.to_rfc3339_opts(SecondsFormat::Nanos, true); | ||
vec![map::Message { | ||
keys: input.keys, | ||
value: serde_json::to_vec(&ResultPayload { | ||
value: payload.data.value, | ||
time: ts, | ||
}) | ||
.unwrap_or_default(), | ||
tags: vec![], | ||
}] | ||
} | ||
} |
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