-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
547 additions
and
132 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
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,75 @@ | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
use arrow::array::{ArrayRef, AsArray, RecordBatch}; | ||
use arrow::compute::StringArrayType; | ||
use arrow::datatypes::DataType; | ||
use async_trait::async_trait; | ||
use futures::future::OptionFuture; | ||
use futures::stream::FuturesOrdered; | ||
use futures::StreamExt; | ||
use redis::{AsyncCommands, RedisFuture, RedisResult}; | ||
use arroyo_formats::de::ArrowDeserializer; | ||
use crate::LookupConnector; | ||
use crate::redis::{RedisClient, RedisConnector}; | ||
use crate::redis::sink::GeneralConnection; | ||
|
||
pub struct RedisLookup { | ||
deserializer: ArrowDeserializer, | ||
client: RedisClient, | ||
connection: Option<GeneralConnection>, | ||
} | ||
|
||
// pub enum RedisFutureOrNull<'a> { | ||
// RedisFuture(RedisFuture<'a, String>), | ||
// Null | ||
// } | ||
// | ||
// impl <'a> Future for RedisFutureOrNull<'a> { | ||
// type Output = RedisResult<Option<String>>; | ||
// | ||
// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
// match self { | ||
// RedisFutureOrNull::RedisFuture(f) => (**f).poll().map(|t| Some(t)), | ||
// RedisFutureOrNull::Null => Poll::Ready(None), | ||
// } | ||
// } | ||
// } | ||
|
||
#[async_trait] | ||
impl LookupConnector for RedisLookup { | ||
fn name(&self) -> String { | ||
"RedisLookup".to_string() | ||
} | ||
|
||
async fn lookup(&mut self, keys: &[ArrayRef]) -> RecordBatch { | ||
if self.connection.is_none() { | ||
self.connection = Some(self.client.get_connection().await.unwrap()); | ||
} | ||
|
||
assert_eq!(keys.len(), 1, "redis lookup can only have a single key"); | ||
assert_eq!(*keys[0].data_type(), DataType::Utf8, "redis lookup key must be a string"); | ||
|
||
let key = keys[0].as_string(); | ||
|
||
let connection = self.connection.as_mut().unwrap(); | ||
|
||
let result = connection.mget::<_, Vec<String>>(&key.iter().filter_map(|k| k).collect::<Vec<_>>()) | ||
.await | ||
.unwrap(); | ||
|
||
let mut result_iter = result.iter(); | ||
|
||
for k in key.iter() { | ||
if k.is_some() { | ||
self.deserializer.deserialize_slice()result_iter.next() | ||
} | ||
} | ||
|
||
while let Some(t) = futures.next().await { | ||
|
||
}; | ||
|
||
Ok(()) | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.