forked from mycelial/mycelial
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate incoming message to hashmap
We really only expect one row in the incoming message and so we'll convert that to a string-string hashmap to pass as the arguments for the job submission. We do this in a roundabout route (dataframe->recordbatch->json->hashmap).
- Loading branch information
Showing
4 changed files
with
20 additions
and
84 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 +1,5 @@ | ||
use std::sync::Arc; | ||
|
||
use section::message::{Ack, Chunk, Column, DataFrame, DataType, Message, ValueView}; | ||
pub mod api; | ||
pub mod destination; | ||
pub mod jobstore; | ||
|
||
type StdError = Box<dyn std::error::Error + Send + Sync + 'static>; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct BacalhauPayload { | ||
pub filepath: String, | ||
} | ||
|
||
impl BacalhauPayload { | ||
fn new(filepath: String) -> Self { | ||
Self { filepath } | ||
} | ||
} | ||
|
||
impl DataFrame for BacalhauPayload { | ||
fn columns(&self) -> Vec<section::message::Column<'_>> { | ||
vec![Column::new( | ||
"filepath", | ||
DataType::Str, | ||
Box::new(std::iter::once(ValueView::from(&self.filepath))), | ||
)] | ||
} | ||
} | ||
|
||
pub struct BacalhauMessage { | ||
origin: Arc<str>, | ||
payload: Option<Box<dyn DataFrame>>, | ||
ack: Option<Ack>, | ||
} | ||
|
||
impl BacalhauMessage { | ||
fn new(origin: Arc<str>, payload: impl DataFrame, ack: Option<Ack>) -> Self { | ||
Self { | ||
origin, | ||
payload: Some(Box::new(payload)), | ||
ack, | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for BacalhauMessage { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("BacalhauMessage") | ||
.field("origin", &self.origin) | ||
.field("payload", &self.payload) | ||
.finish() | ||
} | ||
} | ||
|
||
impl Message for BacalhauMessage { | ||
fn origin(&self) -> &str { | ||
self.origin.as_ref() | ||
} | ||
|
||
fn next(&mut self) -> section::message::Next<'_> { | ||
let v = self.payload.take().map(Chunk::DataFrame); | ||
Box::pin(async move { Ok(v) }) | ||
} | ||
|
||
fn ack(&mut self) -> Ack { | ||
self.ack.take().unwrap_or(Box::pin(async {})) | ||
} | ||
} |