<commit_before>/*-----------------------------------------------------------------------------
 *
 * prov_rewriter_main.c
 *		Main entry point to the provenance rewriter.
 *		
 *		AUTHOR: lord_pretzel
 *
 *		
 *
 *-----------------------------------------------------------------------------
 */

#include "provenance_rewriter/prov_rewriter.h"
#include "provenance_rewriter/pi_cs_rewrites/pi_cs_main.h"
#include "provenance_rewriter/transformation_rewrites/transformation_prov_main.h"

#include "model/query_operator/query_operator.h"
#include "model/node/nodetype.h"
#include "model/list/list.h"

/* function declarations */
static QueryOperator *findProvenanceComputations (QueryOperator *op);
static QueryOperator *rewriteProvenanceComputation (ProvenanceComputation *op);

/* function definitions */
List *
provRewriteQueryList (List *list)
{
    FOREACH(QueryOperator,q,list)
        q_his_cell->data.ptr_value = provRewriteQuery(q);

    return list;
}


QueryOperator *
provRewriteQuery (QueryOperator *input)
{
    return findProvenanceComputations(input);
}


QueryOperator *
findProvenanceComputations (QueryOperator *op)
{
    // is provenance computation? then rewrite
    if (isA(op, ProvenanceComputation))
        rewriteProvenanceComputation((ProvenanceComputation *) op);

    // else search for children with provenance
    FOREACH(QueryOperator, x, op->inputs)
    {
        findProvenanceComputations(x);
    }

    return op;
}

QueryOperator *
rewriteProvenanceComputation (ProvenanceComputation *op)
{
    if (LIST_LENGTH(op->op.inputs) > 1)
    {
        // merge
        //need a loop here for all updates into one 
        FOREACH(QueryOperator, u, op->op.inputs)
          {
             PREP_VISIT(TableAccessOperator);
             VISIT_OPERATOR_FIELDS(u);
          }
        FOREACH(TableAccessOperator, t, op->op.inputs)
          {
             //find the first updates U' in position j with j>i that has updated table T
             PREP_VISIT(TableAccessOperator);
             VISIT_OPERATOR_FIELD(t);
             if(t!= NULL)
              {
                t = SetOperator *op;
              }
          }
         
        // rewrite
        if (isA(op, ProvenanceComputation))
            {<commit_msg>mmmmm<commit_after>/*-----------------------------------------------------------------------------
 *
 * prov_rewriter_main.c
 *		Main entry point to the provenance rewriter.
 *		
 *		AUTHOR: lord_pretzel
 *
 *		
 *
 *-----------------------------------------------------------------------------
 */

#include "provenance_rewriter/prov_rewriter.h"
#include "provenance_rewriter/pi_cs_rewrites/pi_cs_main.h"
#include "provenance_rewriter/transformation_rewrites/transformation_prov_main.h"

#include "model/query_operator/query_operator.h"
#include "model/node/nodetype.h"
#include "model/list/list.h"

/* function declarations */
static QueryOperator *findProvenanceComputations (QueryOperator *op);
static QueryOperator *rewriteProvenanceComputation (ProvenanceComputation *op);

/* function definitions */
List *
provRewriteQueryList (List *list)
{
    FOREACH(QueryOperator,q,list)
        q_his_cell->data.ptr_value = provRewriteQuery(q);

    return list;
}


QueryOperator *
provRewriteQuery (QueryOperator *input)
{
    return findProvenanceComputations(input);
}


QueryOperator *
findProvenanceComputations (QueryOperator *op)
{
    // is provenance computation? then rewrite
    if (isA(op, ProvenanceComputation))
        rewriteProvenanceComputation((ProvenanceComputation *) op);

    // else search for children with provenance
    FOREACH(QueryOperator, x, op->inputs)
    {
        findProvenanceComputations(x);
    }

    return op;
}

QueryOperator *
rewriteProvenanceComputation (ProvenanceComputation *op)
{
    if (LIST_LENGTH(op->op.inputs) > 1)
    {

    	// merge
        //need a loop here for all updates into one 
        FOREACH(QueryOperator, u, op->op.inputs)
          {
             PREP_VISIT(TableAccessOperator);
             VISIT_OPERATOR_FIELDS(u);

          }
        FOREACH(TableAccessOperator, t, op->op.inputs)
          {
             //find the first updates U' in position j with j>i that has updated table T
             PREP_VISIT(TableAccessOperator);
             VISIT_OPERATOR_FIELD(t);
             if(t!= NULL)
              {
                t = SetOperator *op;
              }
          }
         
        // rewrite
        if (isA(op, ProvenanceComputation))
            {
{'fraction_non_alphanumeric': 0.15896405447644563, 'fraction_numerical': 0.00044652824291136416, 'mean_word_length': 2.1818181818181817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002444', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1291, 'n_words': 258}