Skip to content

Commit

Permalink
Revert "Fix github issue #49 (#187)"
Browse files Browse the repository at this point in the history
This reverts commit f601332.
  • Loading branch information
bluejekyll committed Aug 28, 2020
1 parent f601332 commit e323da2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ members = [
"examples/adding",
# Examples disabled because FDW support broken with PostgreSQL 11+.
# See https://github.com/bluejekyll/pg-extend-rs/issues/49
"examples/fdw",
# "examples/fdw",
# "examples/fdw-rw",
"examples/logging",
"examples/memory_context",
Expand Down
2 changes: 1 addition & 1 deletion examples/fdw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern crate pg_extend;
extern crate pg_extern_attr;

use pg_extend::pg_fdw::{ForeignData, ForeignRow, ForeignTableMetadata, OptionMap};
use pg_extend::pg_fdw::{ForeignData, ForeignRow, OptionMap, ForeignTableMetadata};
use pg_extend::{pg_datum, pg_magic, pg_type};
use pg_extern_attr::pg_foreignwrapper;

Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/fdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use integration_tests::*;
// FDW tests disabled because it's broken with PostgreSQL 11+.
// See See https://github.com/bluejekyll/pg-extend-rs/issues/49
#[test]
#[ignore] // this test is currently broken
fn test_fdw() {
test_in_db("fdw", |mut conn| {
conn.batch_execute(
Expand Down
28 changes: 12 additions & 16 deletions pg-extend/src/pg_fdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,30 +306,26 @@ impl<T: ForeignData> ForeignWrapper<T> {
let mut t = HashMap::new();

for i in 0..(attrs.len().min(data.len())) {
let name = Self::name_to_string((attrs[i]).attname);
let name = Self::name_to_string(unsafe { (*attrs[i]).attname });
let data = unsafe { pg_datum::PgDatum::from_raw(memory_context, data[i], isnull[i]) };
t.insert(name, data);
}

t
}

unsafe fn tupdesc_attrs(tupledesc: &pg_sys::tupleDesc) -> &[pg_sys::FormData_pg_attribute] {
unsafe fn tupdesc_attrs(tupledesc: &pg_sys::tupleDesc) -> &[pg_sys::Form_pg_attribute] {
#[cfg(feature = "postgres-11")]
#[allow(clippy::cast_ptr_alignment)]
{
let attrs = (*tupledesc).attrs.as_ptr();
std::slice::from_raw_parts(attrs, (*tupledesc).natts as usize)
}
let attrs = (*tupledesc).attrs.as_ptr() as *const _;
#[cfg(not(feature = "postgres-11"))]
{
let attrs = (*tupledesc).attrs;
std::slice::from_raw_parts(*attrs, (*tupledesc).natts as usize)
}
let attrs = (*tupledesc).attrs;

std::slice::from_raw_parts(attrs, (*tupledesc).natts as usize)
}

/// Retrieve next row from the result set, or clear tuple slot to indicate
/// EOF.
/// EOF.
/// Fetch one row from the foreign
/// (the node's ScanTupleSlot should be used for this purpose).
/// Return NULL if no more rows are available.
Expand All @@ -355,7 +351,7 @@ impl<T: ForeignData> ForeignWrapper<T> {
let mut isnull = vec![pgbool!(true); attrs.len()];
for (i, pattr) in attrs.iter().enumerate() {
// TODO: There must be a better way to do this?
let result = Self::get_field(&memory_context, &(*pattr), &(*row));
let result = Self::get_field(&memory_context, &(**pattr), &(*row));
match result {
Err(err) => {
warn!("{}", err);
Expand Down Expand Up @@ -412,11 +408,11 @@ impl<T: ForeignData> ForeignWrapper<T> {

if let Some(keys) = T::index_columns(&table_metadata) {
// Build a map of column names to attributes and column index
let attrs: HashMap<String, (&pg_sys::FormData_pg_attribute, usize)> =
let attrs: HashMap<String, (&pg_sys::Form_pg_attribute, usize)> =
Self::tupdesc_attrs(&*(*target_relation).rd_att)
.iter()
.enumerate()
.map(|(idx, rel)| (Self::name_to_string((rel).attname), (rel, idx)))
.map(|(idx, rel)| (Self::name_to_string((**rel).attname), (rel, idx)))
.collect();

for key in keys {
Expand All @@ -432,8 +428,8 @@ impl<T: ForeignData> ForeignWrapper<T> {
let var = pg_sys::makeVar(
(*parsetree).resultRelation as u32,
*idx as i16 + 1, // points to the position in the tuple, 1-indexed
(attr).atttypid,
(attr).atttypmod,
(*attr).atttypid,
(*attr).atttypmod,
0 as pg_sys::Oid, // InvalidOid
0,
);
Expand Down

0 comments on commit e323da2

Please sign in to comment.