<commit_before>/*
 * Copyright (c) 2007 Pentaho Corporation.  All rights reserved. 
 * This software was developed by Pentaho Corporation and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is Pentaho 
 * Data Integration.  The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.
*/
package org.pentaho.di.trans.steps.abort;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;


/**
 * Step that will abort after having seen 'x' number of rows on its input.
 * 
 * @author <NAME>
 */
public class Abort extends BaseStep implements StepInterface {

	private static Class<?> PKG = Abort.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

    private AbortMeta meta;
    private AbortData data;
    private int nrInputRows;
    private int nrThresholdRows;
    
    public Abort(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans)
    {
        super(stepMeta, stepDataInterface, copyNr, transMeta, trans);
    }
    
	public boolean init(StepMetaInterface smi, StepDataInterface sdi)
	{
		meta=(AbortMeta)smi;
		data=(AbortData)sdi;
		
		if (super.init(smi, sdi))
		{
		    // Add init code here.
			nrInputRows = 0;
			String threshold = environmentSubstitute(meta.getRowThreshold());
			nrThresholdRows = Const.toInt(threshold, -1);
			if ( nrThresholdRows < 0 )
			{
			    logError(BaseMessages.getString(PKG, "Abort.Log.ThresholdInvalid", threshold));
			}
			
		    return true;
		}
		return false;
	} 
    
    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
		meta=(AbortMeta)smi;
		data=(AbortData)sdi;
		
        Object[] r=getRow();  // Get row from input rowset & set row busy!
        if (r==null)          // no more input to be expected...
        {
            setOutputDone();
            return false;
        }
        else
        {
        	putRow(getInputRowMeta(), r);
        	nrInputRows++;
        	if ( nrInputRows > nrThresholdRows)
        	{
        	   //
        	   // Here we abort!!
        	   //
        	   logError(BaseMessages.getString(PKG, "Abort.Log.Wrote.AbortRow", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        		
        	   String message = environmentSubstitute(meta.getMessage());
        	   if ( message == null || message.length() == 0 )
        	   {
        		   logError(BaseMessages.getString(PKG, "Abort.Log.DefaultAbortMessage", "" + nrInputRows));
        	   }
        	   else
        	   {
        		   logMinimal(message);
        	   }
               setErrors(1);
               stopAll();        	   
        	}
        	else 
        	{
        		// seen a row but not yet reached the threshold
        		if ( meta.isAlwaysLogRows() )
        		{
        			logMinimal(BaseMessages.getString(PKG, "Abort.Log.Wrote.Row", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        		}
        		else
        		{
        	        if (log.isRowLevel())
        	        {        	        	
        	            logRowlevel(BaseMessages.getString(PKG, "Abort.Log.Wrote.Row", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        	        }
        		}
        	}
        }
        
        return true;
    }

    //
    // Run is were the action happens!
    public void run()
    {
    	BaseStep.runStepThread(this, meta, data);
    }
}<commit_msg>Abort should log error lines, it's very counter intuitive if it doesn't.<commit_after>/*
 * Copyright (c) 2007 Pentaho Corporation.  All rights reserved. 
 * This software was developed by Pentaho Corporation and is provided under the terms 
 * of the GNU Lesser General Public License, Version 2.1. You may not use 
 * this file except in compliance with the license. If you need a copy of the license, 
 * please go to http://www.gnu.org/licenses/lgpl-2.1.txt. The Original Code is Pentaho 
 * Data Integration.  The Initial Developer is Pentaho Corporation.
 *
 * Software distributed under the GNU Lesser Public License is distributed on an "AS IS" 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
 * the license for the specific language governing your rights and limitations.
*/
package org.pentaho.di.trans.steps.abort;

import org.pentaho.di.core.Const;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStep;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;


/**
 * Step that will abort after having seen 'x' number of rows on its input.
 * 
 * @author <NAME>
 */
public class Abort extends BaseStep implements StepInterface {

	private static Class<?> PKG = Abort.class; // for i18n purposes, needed by Translator2!!   $NON-NLS-1$

    private AbortMeta meta;
    private AbortData data;
    private int nrInputRows;
    private int nrThresholdRows;
    
    public Abort(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans)
    {
        super(stepMeta, stepDataInterface, copyNr, transMeta, trans);
    }
    
	public boolean init(StepMetaInterface smi, StepDataInterface sdi)
	{
		meta=(AbortMeta)smi;
		data=(AbortData)sdi;
		
		if (super.init(smi, sdi))
		{
		    // Add init code here.
			nrInputRows = 0;
			String threshold = environmentSubstitute(meta.getRowThreshold());
			nrThresholdRows = Const.toInt(threshold, -1);
			if ( nrThresholdRows < 0 )
			{
			    logError(BaseMessages.getString(PKG, "Abort.Log.ThresholdInvalid", threshold));
			}
			
		    return true;
		}
		return false;
	} 
    
    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
		meta=(AbortMeta)smi;
		data=(AbortData)sdi;
		
        Object[] r=getRow();  // Get row from input rowset & set row busy!
        if (r==null)          // no more input to be expected...
        {
            setOutputDone();
            return false;
        }
        else
        {
        	putRow(getInputRowMeta(), r);
        	nrInputRows++;
        	if ( nrInputRows > nrThresholdRows)
        	{
        	   //
        	   // Here we abort!!
        	   //
        	   logError(BaseMessages.getString(PKG, "Abort.Log.Wrote.AbortRow", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        		
        	   String message = environmentSubstitute(meta.getMessage());
        	   if ( message == null || message.length() == 0 )
        	   {
        		   logError(BaseMessages.getString(PKG, "Abort.Log.DefaultAbortMessage", "" + nrInputRows));
        	   }
        	   else
        	   {
        		   logError(message);
        	   }
               setErrors(1);
               stopAll();        	   
        	}
        	else 
        	{
        		// seen a row but not yet reached the threshold
        		if ( meta.isAlwaysLogRows() )
        		{
        			logMinimal(BaseMessages.getString(PKG, "Abort.Log.Wrote.Row", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        		}
        		else
        		{
        	        if (log.isRowLevel())
        	        {        	        	
        	            logRowlevel(BaseMessages.getString(PKG, "Abort.Log.Wrote.Row", Long.toString(nrInputRows), getInputRowMeta().getString(r)) );
        	        }
        		}
        	}
        }
        
        return true;
    }

    //
    // Run is were the action happens!
    public void run()
    {
    	BaseStep.runStepThread(this, meta, data);
    }
}
{'fraction_non_alphanumeric': 0.09994162288382955, 'fraction_numerical': 0.00443666082895505, 'mean_word_length': 2.280735350440444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4619247', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2563, 'n_words': 653}