flowcode-core 0.4.3-alpha

Core execution engine for FlowCode data scripting language
Documentation
// Integration tests for DuckDB 'join' verb
use flowcode_core::duckdb_verbs::map_verb_to_sql;
use flowcode_core::types::{TypedValue, ValueKind};
use flowcode_core::ast::ArgValue;
use flowcode_core::error::FCError;
use flowcode_core::duckdb_session::DuckSession;

fn tv(s: &str) -> TypedValue {
    TypedValue { value: ArgValue::String(s.to_string()), kind: ValueKind::String }
}

#[test]
fn test_join_no_arguments() {
    let session = DuckSession::new().unwrap();
    let args: Vec<TypedValue> = vec![];
    let result = map_verb_to_sql("join", &args, &session);
    assert!(result.is_err());
    if let Err(FCError::InvalidArgument(msg)) = result {
        assert_eq!(msg, "join needs: join <left> <right> \"predicate\" [column <cols…>]".to_string());
    } else {
        panic!("Expected InvalidArgument error for join with no arguments");
    }
}

#[test]
fn test_join_insufficient_arguments() {
    let session = DuckSession::new().unwrap();
    let args = vec![tv("employees"), tv("departments")];
    let result = map_verb_to_sql("join", &args, &session);
    assert!(result.is_err());
    if let Err(FCError::InvalidArgument(msg)) = result {
        assert_eq!(msg, "join needs: join <left> <right> \"predicate\" [column <cols…>]".to_string());
    } else {
        panic!("Expected InvalidArgument error for join with insufficient arguments");
    }
}

#[test]
fn test_join_basic() {
    let session = DuckSession::new().unwrap();
    let args = vec![tv("employees"), tv("departments"), tv("employees.dept_id = departments.dept_id")];
    let result = map_verb_to_sql("join", &args, &session);
    assert!(result.is_ok(), "Join mapping failed: {:?}", result.err());
    if let Ok(sql) = result {
        assert_eq!(sql, "SELECT * FROM employees LEFT JOIN departments ON employees.dept_id = departments.dept_id");
    }
}

#[test]
fn test_join_with_columns() {
    let session = DuckSession::new().unwrap();
    // Test join with specific columns
    let args = vec![
        tv("employees"),
        tv("departments"),
        tv("employees.dept_id = departments.dept_id"),
        tv("column"),
        tv("name"),
        tv("dept_name"),
    ];
    let result = map_verb_to_sql("join", &args, &session);
    assert!(result.is_ok(), "Join with columns mapping failed: {:?}", result.err());
    if let Ok(sql) = result {
        assert!(sql.contains("SELECT employees.name, departments.dept_name FROM employees LEFT JOIN departments ON employees.dept_id = departments.dept_id") ||
                sql.contains("SELECT departments.dept_name, employees.name FROM employees LEFT JOIN departments ON employees.dept_id = departments.dept_id") ||
                sql.contains("SELECT employees.name, employees.dept_name FROM employees LEFT JOIN departments ON employees.dept_id = departments.dept_id"),
                "Unexpected SQL: {}", sql);
    }
}