Skip to content

Commit

Permalink
fix: include read_deltalake feature (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
tshauck authored Sep 4, 2024
1 parent e4c2713 commit 7a37be7
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions exon/exon-core/src/session_context/exon_context_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use datafusion::{
prelude::{DataFrame, SessionConfig, SessionContext},
};
#[cfg(feature = "deltalake")]
use deltalake::delta_datafusion::DeltaTableFactory;

#[cfg(feature = "deltalake")]
use deltalake::aws::register_handlers;
use deltalake::{aws::register_handlers, delta_datafusion::DeltaTableFactory, open_table};

use crate::{
datasources::{
Expand Down Expand Up @@ -578,6 +575,18 @@ impl ExonSession {
Ok(table)
}

/// Read a Delta Lake table.
#[cfg(feature = "deltalake")]
pub async fn read_deltalake(&self, table_path: &str) -> Result<DataFrame, ExonError> {
let table = open_table(table_path).await.map_err(|e| {
ExonError::ExecutionError(format!("Error opening Delta Lake table: {}", e))
})?;

let df = self.session.read_table(Arc::new(table))?;

Ok(df)
}

/// Read a FASTA file.
pub async fn read_fasta(
&self,
Expand Down Expand Up @@ -714,6 +723,7 @@ impl ExonSession {
#[cfg(test)]
mod tests {
use datafusion::datasource::file_format::file_compression_type::FileCompressionType;
use exon_test::test_listing_table_dir;

use crate::{
datasources::{
Expand Down Expand Up @@ -878,6 +888,20 @@ mod tests {
Ok(())
}

#[cfg(feature = "deltalake")]
#[tokio::test]
async fn test_read_deltalake() -> Result<(), Box<dyn std::error::Error>> {
let ctx = ExonSession::new_exon()?;

let path = exon_test::test_listing_table_url("delta");

let df = ctx.read_deltalake(path.as_str()).await?;

assert_eq!(df.count().await?, 2);

Ok(())
}

#[tokio::test]
async fn test_read_bigwig_view_file() -> Result<(), Box<dyn std::error::Error>> {
let ctx = ExonSession::new_exon()?;
Expand Down

0 comments on commit 7a37be7

Please sign in to comment.