hamelin_legacy 0.3.9

Legacy AST translation code for Hamelin (to be deprecated)
Documentation
use crate::ast::assignment_clause::HamelinAssignmentClause;
use crate::ast::pipeline::HamelinPipeline;
use crate::env::Environment;
use crate::translation::projection_builder::ProjectionBuilder;
use crate::translation::PendingQueryResult;
use hamelin_lib::antlr::hamelinparser::{SelectCommandContext, SelectCommandContextAttrs};
use hamelin_lib::err::TranslationError;
use hamelin_lib::func::def::FunctionTranslationContext;

pub fn translate(
    ctx: &SelectCommandContext<'static>,
    pipeline: &HamelinPipeline,
    pending_query_result: &mut PendingQueryResult,
) {
    let mut new_projection = ProjectionBuilder::default();
    for clause in ctx.assignmentClause_all() {
        let expr_ctx = pipeline.context.expression_translation_context(
            &pending_query_result.translation.env,
            FunctionTranslationContext::default(),
        );

        if let Some((identifier, translation)) = pending_query_result
            .errors
            .consume_errors(HamelinAssignmentClause::new(clause.clone(), expr_ctx).to_sql())
        {
            new_projection.bind(identifier.into(), translation.sql, translation.typ)
        }
    }

    match new_projection
        .clone()
        .build_projections()
        .map_err(|e| TranslationError::wrap_box(ctx, e.into()))
    {
        Ok(projections) => {
            pending_query_result.translation.query = pending_query_result
                .translation
                .query
                .replace_projections(projections);
        }
        Err(e) => {
            pending_query_result.errors.add(e);
        }
    }

    pending_query_result.translation.env = Environment::new(new_projection.build_hamelin_type());
}