Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ Which would yield something like:
the rowid option is required. As are the names key and value for the columns.


## Pushdowning

#### ORDER BY push-down
`etcd_fdw` now also supports order by push-down. If possible, push order by
clause to the remote server so that we get the ordered result set from the
foreign server itself.

#### LIMIT push-down
`etcd_fdw` now also supports limit offset push-down. Wherever possible,
perform LIMIT operations on the remote server.


Usage
-----

Expand Down
31 changes: 29 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use etcd_client::{Client, ConnectOptions, TlsOptions, Identity, Certificate, Error, DeleteOptions, GetOptions, KeyValue, PutOptions};
use etcd_client::{Client, ConnectOptions, TlsOptions, Identity, Certificate, Error, DeleteOptions, GetOptions, KeyValue, PutOptions, SortTarget, SortOrder};
use std::time::Duration;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::PgSqlErrorCode;
Expand Down Expand Up @@ -86,6 +86,9 @@ pub enum EtcdFdwError {
#[error("Invalid option '{0}' with value '{1}'")]
InvalidOption(String, String),

#[error("Invalid sort field value '{0}'")]
InvalidSortField(String),

#[error("{0}")]
OptionsError(#[from] OptionsError),
}
Expand Down Expand Up @@ -237,7 +240,7 @@ impl ForeignDataWrapper<EtcdFdwError> for EtcdFdw {
&mut self,
_quals: &[Qual],
columns: &[Column],
_sorts: &[Sort],
sort: &[Sort],
limit: &Option<Limit>,
options: &std::collections::HashMap<String, String>,
) -> Result<(), EtcdFdwError> {
Expand Down Expand Up @@ -284,6 +287,30 @@ impl ForeignDataWrapper<EtcdFdwError> for EtcdFdw {
get_options = get_options.with_serializable();
}

// XXX Support for WHERE clause push-downs is pending
// etcd doesn't have anything like WHERE clause because it
// a NOSQL database.
// But may be we can still support some simple WHERE
// conditions like '<', '>=', 'LIKE', '=' by mapping them
// to key, range_end and prefix options.

// sort pushdown
if let Some(first_sort) = sort.first() {
let field_name = first_sort.field.to_ascii_uppercase();

if let Some(target) = SortTarget::from_str_name(&field_name) {
let order = if first_sort.reversed {
SortOrder::Descend
} else {
SortOrder::Ascend
};

get_options = get_options.with_sort(target, order);
} else {
return Err(EtcdFdwError::InvalidSortField(first_sort.field.clone()));
}
}

// preference order : prefix > key_start > default "\0"
// samllest possible valid key '\0'
let key = prefix.clone()
Expand Down
Loading