Skip to content

Commit 187bcc9

Browse files
committed
refactor: remove custom information_schema and use datafusion built-in
1 parent 470b193 commit 187bcc9

File tree

4 files changed

+3
-179
lines changed

4 files changed

+3
-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

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

180-
let session_context = SessionContext::new();
180+
let session_config = SessionConfig::new().with_information_schema(true);
181+
let session_context = SessionContext::new_with_config(session_config);
181182

182183
setup_session_context(&session_context, &opts).await?;
183184

datafusion-postgres/src/handlers.rs

Lines changed: 0 additions & 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>);
@@ -184,39 +183,6 @@ impl DfSessionService {
184183
Ok(None)
185184
}
186185
}
187-
188-
async fn try_respond_information_schema<'a>(
189-
&self,
190-
query_lower: &str,
191-
) -> PgWireResult<Option<Response<'a>>> {
192-
if query_lower.contains("information_schema.schemata") {
193-
let df = schemata_df(&self.session_context)
194-
.await
195-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
196-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
197-
return Ok(Some(Response::Query(resp)));
198-
} else if query_lower.contains("information_schema.tables") {
199-
let df = tables_df(&self.session_context)
200-
.await
201-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
202-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
203-
return Ok(Some(Response::Query(resp)));
204-
} else if query_lower.contains("information_schema.columns") {
205-
let df = columns_df(&self.session_context)
206-
.await
207-
.map_err(|e| PgWireError::ApiError(Box::new(e)))?;
208-
let resp = datatypes::encode_dataframe(df, &Format::UnifiedText).await?;
209-
return Ok(Some(Response::Query(resp)));
210-
}
211-
212-
// Handle pg_catalog.pg_namespace for pgcli compatibility
213-
if query_lower.contains("pg_catalog.pg_namespace") {
214-
let resp = self.mock_pg_namespace().await?;
215-
return Ok(Some(Response::Query(resp)));
216-
}
217-
218-
Ok(None)
219-
}
220186
}
221187

222188
#[async_trait]
@@ -236,10 +202,6 @@ impl SimpleQueryHandler for DfSessionService {
236202
return Ok(vec![resp]);
237203
}
238204

239-
if let Some(resp) = self.try_respond_information_schema(&query_lower).await? {
240-
return Ok(vec![resp]);
241-
}
242-
243205
let df = self
244206
.session_context
245207
.sql(query)
@@ -352,10 +314,6 @@ impl ExtendedQueryHandler for DfSessionService {
352314
return Ok(resp);
353315
}
354316

355-
if let Some(resp) = self.try_respond_information_schema(&query).await? {
356-
return Ok(resp);
357-
}
358-
359317
let plan = &portal.statement.statement;
360318
let param_types = plan
361319
.get_parameter_types()

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)