-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
postgres connection support #306
Comments
@jonathandune ROAPI supports Postgres. The error you encountered is because your schema is not correct. Change the URL to |
Thanks, indeed just realised this by looking at roapi/columnq/src/table/mod.rs Line 461 in ea01ffe
I am know getting a panic : The DB is up and running and have other processes connected to it so not sure what the issue is. |
This error arises from crate ( /// Opens a connection to a PostgreSQL database.
pub fn connect<T>(&self, tls: T) -> Result<Client, Error>
where
T: MakeTlsConnect<Socket> + 'static + Send,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
{
let runtime = runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap(); // FIXME don't unwrap
let (client, connection) = runtime.block_on(self.config.connect(tls))?;
let connection = Connection::new(runtime, connection, self.notice_callback.clone());
Ok(Client::new(connection, client))
} We can see that the code would create a new Runtime, but our own program is already in a Runtime, so that causes this error. None of those are part of ROAPI, so I have no idea how to fix this now. :( |
It looks like we are using the wrong connectorx api, we are effectively calling a blocking api from an async function, would be better to call the async |
Maybe we should call the connectorx api in an independent thread? pub async fn to_mem_table(
&self,
t: &TableSource,
) -> Result<datafusion::datasource::MemTable, ColumnQError> {
debug!("loading database table data...");
let queries = CXQuery::naked(format!("SELECT * FROM {}", t.name));
let source = SourceConn::try_from(t.get_uri_str())
.map_err(|e| ColumnQError::Database(e.to_string()))?;
let hd = tokio::runtime::Handle::current();
hd.spawn_blocking(move || {
let destination = connectorx::get_arrow::get_arrow(&source, None, &[queries])
.map_err(|e| ColumnQError::Database(e.to_string()))?;
Ok(datafusion::datasource::MemTable::try_new(
destination.arrow_schema(),
vec![destination
.arrow()
.map_err(|e| ColumnQError::Database(e.to_string()))?],
)?)
})
.await
.map_err(|e| ColumnQError::Database(e.to_string()))?
} |
@holicc that feels wrong, do they not have an async api we can call directly from an async context? |
Hi there, use tokio::runtime::Runtime;
pub fn connect<T>(&self, tls: T, runtime: &Runtime) -> Result<Client, Error>
where
T: MakeTlsConnect<Socket> + 'static + Send,
T::TlsConnect: Send,
T::Stream: Send,
<T::TlsConnect as TlsConnect<Socket>>::Future: Send,
{
let (client, connection) = runtime.block_on(self.config.connect(tls))?;
let connection = Connection::new(runtime.clone(), connection, self.notice_callback.clone());
Ok(Client::new(connection, client))
} |
@anvarknian i am not actively working on this right now, I am ok with merging a workaround to unblock this in the short run, but the proper way to fix this is to invoke an async api from their end. Have you filed an upstream connectorx ticket to get some ideas on how to best achieve this? |
@houqp , Hi, I just wanted to confirm that using postgres from roapi is still not advisable? On a side note, in order to enable connecting to a database in the first place, do I need to compile from source with --features "database" as indicated in the first post on this thread? Currently, when I try to connect to a postgres database with roapi
Thanks for any clarity you can provide. |
@chrisfw yes, you need to compile from source for now, the official build doesn't have the mysql database feature enabled by default. |
Thanks for your response @houqp. The same holds true for postgres, correct? Can you please provide the exact flag and value that need to be passed? (--features "postgres" ?) Also, is the postgres support stable as it seemed there were some connector-x threading issues? Regards, |
I've built from source with --features "database" but running :
./roapi --table "postgres://
Returns :
{ source: Some(TableError { source: Extension { msg: "unsupported extension in uri: postgres://postgres:dune@localhost:5432/postgres" } })
I do see postgres in
roapi/columnq/src/table/mod.rs
Line 294 in ea01ffe
Does ROAPI support connecting to a postgres database ?
The text was updated successfully, but these errors were encountered: