Skip to main content

tl_data/
redshift.rs

1// ThinkingLanguage — Amazon Redshift Connector
2// Licensed under MIT OR Apache-2.0
3//
4// Redshift uses the PostgreSQL wire protocol. This thin wrapper delegates
5// to the existing PG cursor-batching code with SSL mode enforcement.
6
7use crate::engine::DataEngine;
8
9impl DataEngine {
10    /// Read from Amazon Redshift using a connection string and SQL query.
11    /// Delegates to the PostgreSQL connector (Redshift is PG wire-compatible).
12    /// Ensures SSL mode is set for Redshift cluster connections.
13    pub fn read_redshift(
14        &self,
15        conn_str: &str,
16        query: &str,
17    ) -> Result<datafusion::prelude::DataFrame, String> {
18        let conn_str = if !conn_str.contains("sslmode") {
19            format!("{conn_str} sslmode=require")
20        } else {
21            conn_str.to_string()
22        };
23        self.query_postgres(&conn_str, query, "__redshift_result")
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    #[ignore] // Requires a running Redshift cluster
33    fn test_read_redshift() {
34        let engine = DataEngine::new();
35        let df = engine
36            .read_redshift(
37                "host=cluster.abc.redshift.amazonaws.com port=5439 dbname=prod user=admin password=secret",
38                "SELECT 1 AS test_col",
39            )
40            .unwrap();
41        let batches = engine.collect(df).unwrap();
42        assert!(!batches.is_empty());
43    }
44}