Skip to content

Commit 957a8a8

Browse files
committed
refactor: remove custom information_schema and use datafusion built-in
1 parent efa9cdf commit 957a8a8

File tree

4 files changed

+4
-179
lines changed

4 files changed

+4
-179
lines changed

datafusion-postgres-cli/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55
use datafusion::execution::options::{
66
ArrowReadOptions, AvroReadOptions, CsvReadOptions, NdJsonReadOptions, ParquetReadOptions,
77
};
8-
use datafusion::prelude::SessionContext;
8+
use datafusion::prelude::{SessionConfig, SessionContext};
99
use datafusion_postgres::{serve, ServerOptions}; // Assuming the crate name is `datafusion_postgres`
1010
use structopt::StructOpt;
1111

@@ -179,7 +179,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
179179
let mut opts = Opt::from_args();
180180
opts.include_directory_files()?;
181181

182-
let session_context = SessionContext::new();
182+
let session_config = SessionConfig::new().with_information_schema(true);
183+
let session_context = SessionContext::new_with_config(session_config);
183184

184185
setup_session_context(&session_context, &opts).await?;
185186

datafusion-postgres/src/handlers.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use pgwire::api::{ClientInfo, NoopErrorHandler, PgWireServerHandlers, Type};
1919
use tokio::sync::Mutex;
2020

2121
use crate::datatypes;
22-
use crate::information_schema::{columns_df, schemata_df, tables_df};
2322
use pgwire::error::{PgWireError, PgWireResult};
2423

2524
pub struct HandlerFactory(pub Arc<DfSessionService>);
@@ -189,39 +188,6 @@ impl DfSessionService {
189188
Ok(None)
190189
}
191190
}
192-
193-
async fn try_respond_information_schema<'a>(
194-
&self,
195-
query_lower: &str,
196-
) -> PgWireResult<Option<Response<'a>>> {
197-
if query_lower.contains("information_schema.schemata") {
198-
let df = schemata_df(&self.session_context)
199-
.await
200-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
201-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
202-
return Ok(Some(Response::Query(resp)));
203-
} else if query_lower.contains("information_schema.tables") {
204-
let df = tables_df(&self.session_context)
205-
.await
206-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
207-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
208-
return Ok(Some(Response::Query(resp)));
209-
} else if query_lower.contains("information_schema.columns") {
210-
let df = columns_df(&self.session_context)
211-
.await
212-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
213-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
214-
return Ok(Some(Response::Query(resp)));
215-
}
216-
217-
// Handle pg_catalog.pg_namespace for pgcli compatibility
218-
if query_lower.contains("pg_catalog.pg_namespace") {
219-
let resp = self.mock_pg_namespace().await?;
220-
return Ok(Some(Response::Query(resp)));
221-
}
222-
223-
Ok(None)
224-
}
225191
}
226192

227193
#[async_trait]
@@ -241,10 +207,6 @@ impl SimpleQueryHandler for DfSessionService {
241207
return Ok(vec![resp]);
242208
}
243209

244-
if let Some(resp) = self.try_respond_information_schema(&query_lower).await? {
245-
return Ok(vec![resp]);
246-
}
247-
248210
let df = self
249211
.session_context
250212
.sql(query)
@@ -361,11 +323,8 @@ impl ExtendedQueryHandler for DfSessionService {
361323
return Ok(resp);
362324
}
363325

364-
if let Some(resp) = self.try_respond_information_schema(&query).await? {
365-
return Ok(resp);
366-
}
367-
368326
let (_, plan) = &portal.statement.statement;
327+
369328
let param_types = plan
370329
.get_parameter_types()
371330
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;

datafusion-postgres/src/information_schema.rs

Lines changed: 0 additions & 134 deletions
This file was deleted.

datafusion-postgres/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod datatypes;
22
mod encoder;
33
mod handlers;
4-
mod information_schema;
54

65
use std::sync::Arc;
76

0 commit comments

Comments
 (0)