#![cfg(feature = "duckdb")]
use flowcode_core::duckdb_verbs::map_verb_to_sql;
use flowcode_core::duckdb_session::DuckSession;
use flowcode_core::types::{TypedValue, ValueKind};
use flowcode_core::ast::ArgValue;
use std::error::Error;
#[test]
fn test_join_with_column_selection() -> Result<(), Box<dyn Error>> {
let session = DuckSession::new()?;
let args = vec![
TypedValue::new(ValueKind::String, ArgValue::String("employees".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("departments".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("employees.department = departments.name".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("columns".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("id".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("name".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("location".to_string())),
];
let sql = map_verb_to_sql("join", &args, &session)?;
assert_eq!(sql, "SELECT employees.id, employees.name, departments.location FROM employees LEFT JOIN departments ON employees.department = departments.name");
Ok(())
}
#[test]
fn test_join_without_column_selection() -> Result<(), Box<dyn Error>> {
let session = DuckSession::new()?;
let args = vec![
TypedValue::new(ValueKind::String, ArgValue::String("employees".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("departments".to_string())),
TypedValue::new(ValueKind::String, ArgValue::String("employees.department = departments.name".to_string())),
];
let sql = map_verb_to_sql("join", &args, &session)?;
assert_eq!(sql, "SELECT * FROM employees LEFT JOIN departments ON employees.department = departments.name");
Ok(())
}