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
14 changes: 14 additions & 0 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
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["datafusion-postgres", "datafusion-postgres-cli", "arrow-pg"]
members = ["datafusion-postgres", "datafusion-postgres-cli", "arrow-pg", "datafusion-pg-catalog"]

[workspace.package]
version = "0.10.2"
Expand Down
29 changes: 29 additions & 0 deletions datafusion-pg-catalog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "datafusion-pg-catalog"
description = "pg_catalog compatibility for datafusion"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
keywords.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true
readme = "../README.md"
rust-version.workspace = true
include = [
"src/**/*",
"pg_catalog_arrow_exports/**/*",
"Cargo.toml"
]

[dependencies]
async-trait = "0.1"
datafusion.workspace = true
futures.workspace = true
log = "0.4"
postgres-types.workspace = true
tokio = { version = "1.47", features = ["sync"] }

[dev-dependencies]
env_logger = "0.11"
4 changes: 4 additions & 0 deletions datafusion-pg-catalog/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod pg_catalog;
pub mod sql;

pub use pg_catalog::setup_pg_catalog;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Debug;
use std::{fmt::Debug, sync::Arc};

use async_trait::async_trait;

Expand All @@ -20,6 +20,22 @@ pub struct EmptyContextProvider;

impl PgCatalogContextProvider for EmptyContextProvider {}

#[async_trait]
impl<T> PgCatalogContextProvider for Arc<T>
where
T: PgCatalogContextProvider,
{
// retrieve all database role names
async fn roles(&self) -> Vec<String> {
self.roles().await
}

// retrieve database role information
async fn role(&self, name: &str) -> Option<Role> {
self.role(name).await
}
}

/// User information stored in the authentication system
#[derive(Debug, Clone)]
pub struct User {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion datafusion-postgres-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use datafusion::execution::options::{
};
use datafusion::prelude::{SessionConfig, SessionContext};
use datafusion_postgres::auth::AuthManager;
use datafusion_postgres::pg_catalog::setup_pg_catalog;
use datafusion_postgres::datafusion_pg_catalog::setup_pg_catalog;
use datafusion_postgres::{serve, ServerOptions};
use env_logger::Env;
use log::info;
Expand Down
7 changes: 1 addition & 6 deletions datafusion-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@ repository.workspace = true
documentation.workspace = true
readme = "../README.md"
rust-version.workspace = true
include = [
"src/**/*",
"pg_catalog_arrow_exports/**/*",
"Cargo.toml"
]


[dependencies]
arrow-pg = { path = "../arrow-pg", version = "0.6.1", default-features = false, features = ["datafusion"] }
bytes.workspace = true
async-trait = "0.1"
chrono.workspace = true
datafusion.workspace = true
datafusion-pg-catalog = { path = "../datafusion-pg-catalog", version = "0.10.2" }
futures.workspace = true
getset = "0.1"
log = "0.4"
Expand Down
30 changes: 15 additions & 15 deletions datafusion-postgres/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use pgwire::api::auth::{AuthSource, LoginInfo, Password};
use pgwire::error::{PgWireError, PgWireResult};
use tokio::sync::RwLock;

use crate::pg_catalog::context::*;
use datafusion_pg_catalog::pg_catalog::context::*;

/// Authentication manager that handles users and roles
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct AuthManager {
users: Arc<RwLock<HashMap<String, User>>>,
roles: Arc<RwLock<HashMap<String, Role>>>,
Expand Down Expand Up @@ -445,6 +445,19 @@ impl AuthManager {
}
}

#[async_trait]
impl PgCatalogContextProvider for AuthManager {
// retrieve all database role names
async fn roles(&self) -> Vec<String> {
self.list_roles().await
}

// retrieve database role information
async fn role(&self, name: &str) -> Option<Role> {
self.get_role(name).await
}
}

/// AuthSource implementation for integration with pgwire authentication
/// Provides proper password-based authentication instead of custom startup handler
#[derive(Clone)]
Expand Down Expand Up @@ -547,19 +560,6 @@ impl SimpleAuthSource {
}
}

#[async_trait]
impl PgCatalogContextProvider for Arc<AuthManager> {
// retrieve all database role names
async fn roles(&self) -> Vec<String> {
self.list_roles().await
}

// retrieve database role information
async fn role(&self, name: &str) -> Option<Role> {
self.role(name).await
}
}

#[async_trait]
impl AuthSource for SimpleAuthSource {
async fn get_password(&self, login: &LoginInfo) -> PgWireResult<Password> {
Expand Down
4 changes: 2 additions & 2 deletions datafusion-postgres/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ use pgwire::messages::response::TransactionStatus;
use tokio::sync::Mutex;

use crate::auth::AuthManager;
use crate::pg_catalog::context::{Permission, ResourceType};
use crate::sql::PostgresCompatibilityParser;
use arrow_pg::datatypes::df;
use arrow_pg::datatypes::{arrow_schema_to_pg_fields, into_pg_type};
use datafusion_pg_catalog::pg_catalog::context::{Permission, ResourceType};
use datafusion_pg_catalog::sql::PostgresCompatibilityParser;

// Metadata keys for session-level settings
const METADATA_STATEMENT_TIMEOUT: &str = "statement_timeout_ms";
Expand Down
3 changes: 1 addition & 2 deletions datafusion-postgres/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
mod handlers;
pub mod pg_catalog;
pub mod sql;

use std::fs::File;
use std::io::{BufReader, Error as IOError, ErrorKind};
Expand All @@ -26,6 +24,7 @@ pub use handlers::{DfSessionService, Parser};

/// re-exports
pub use arrow_pg;
pub use datafusion_pg_catalog;
pub use pgwire;

#[derive(Getters, Setters, WithSetters, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion datafusion-postgres/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::{collections::HashMap, sync::Arc};

use datafusion::prelude::SessionContext;
use datafusion_postgres::{auth::AuthManager, pg_catalog::setup_pg_catalog, DfSessionService};
use datafusion_pg_catalog::pg_catalog::setup_pg_catalog;
use datafusion_postgres::{auth::AuthManager, DfSessionService};
use futures::Sink;
use pgwire::{
api::{ClientInfo, ClientPortalStore, PgWireConnectionState, METADATA_USER},
Expand Down
Loading