Skip to content

Commit

Permalink
Merge pull request #192 from supabase/fix/stripe-table-join
Browse files Browse the repository at this point in the history
fix: incorrect stripe table join
  • Loading branch information
burmecia authored Nov 13, 2023
2 parents 3c19feb + 4e95ddd commit 1ce5e05
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 0 additions & 4 deletions docs/stripe.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,6 @@ While any column is allowed in a where clause, it is most efficient to filter by
- id
- destination

## Limitations

Joining local data against a Stripe FDW returns incomplete or empty results. We're tracking the [issue on GitHub](https://github.com/supabase/wrappers/issues/113) and working towards a fix.

## Examples

Some examples on how to use Stripe foreign tables.
Expand Down
16 changes: 11 additions & 5 deletions wrappers/src/fdw/stripe_fdw/stripe_fdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ pub(crate) struct StripeFdw {
scan_result: Option<Vec<Row>>,
obj: String,
rowid_col: String,
iter_idx: usize,
}

impl StripeFdw {
Expand Down Expand Up @@ -645,6 +646,7 @@ impl ForeignDataWrapper<StripeFdwError> for StripeFdw {
scan_result: None,
obj: String::default(),
rowid_col: String::default(),
iter_idx: 0,
})
}

Expand Down Expand Up @@ -737,16 +739,20 @@ impl ForeignDataWrapper<StripeFdwError> for StripeFdw {

fn iter_scan(&mut self, row: &mut Row) -> StripeFdwResult<Option<()>> {
if let Some(ref mut result) = self.scan_result {
if !result.is_empty() {
return Ok(result
.drain(0..1)
.last()
.map(|src_row| row.replace_with(src_row)));
if self.iter_idx < result.len() {
row.replace_with(result[self.iter_idx].clone());
self.iter_idx += 1;
return Ok(Some(()));
}
}
Ok(None)
}

fn re_scan(&mut self) -> StripeFdwResult<()> {
self.iter_idx = 0;
Ok(())
}

fn end_scan(&mut self) -> StripeFdwResult<()> {
self.scan_result.take();
Ok(())
Expand Down

0 comments on commit 1ce5e05

Please sign in to comment.