<commit_before>/**********************************************************************
 **                                                                   **
 **               This code belongs to the KETTLE project.            **
 **                                                                   **
 ** Kettle, from version 2.2 on, is released into the public domain   **
 ** under the Lesser GNU Public License (LGPL).                       **
 **                                                                   **
 ** For more details, please read the document LICENSE.txt, included  **
 ** in this project                                                   **
 **                                                                   **
 ** http://www.kettle.be                                              **
 ** <EMAIL>                                                    **
 **                                                                   **
 **********************************************************************/

package be.ibridge.kettle.trans.step.sortrows;

import java.sql.ResultSet;
import java.util.Random;

import junit.framework.TestCase;
import be.ibridge.kettle.core.Const;
import be.ibridge.kettle.core.LogWriter;
import be.ibridge.kettle.core.Row;
import be.ibridge.kettle.core.database.Database;
import be.ibridge.kettle.core.database.DatabaseMeta;
import be.ibridge.kettle.core.exception.KettleException;
import be.ibridge.kettle.core.util.EnvUtil;
import be.ibridge.kettle.core.value.Value;
import be.ibridge.kettle.trans.StepLoader;
import be.ibridge.kettle.trans.Trans;
import be.ibridge.kettle.trans.TransHopMeta;
import be.ibridge.kettle.trans.TransMeta;
import be.ibridge.kettle.trans.step.StepMeta;
import be.ibridge.kettle.trans.step.StepMetaInterface;
import be.ibridge.kettle.trans.step.combinationlookup.CombinationLookupMeta;
import be.ibridge.kettle.trans.step.tableinput.TableInputMeta;

/**
 * Test class for sort rows step. HSQL is used
 * as database in memory to get an easy playground for database
 * tests. HSQL does not support all SQL features but it should
 * proof enough for most of our tests.
 * 
 * What will be done... a database table will be filled with rows
 * consisting of 2 keyfields (randomly generated, but unique). 
 * A database step will read the table, link it to a sort rows step,
 * linking it to a combination lookup step.
 * 
 * The combination lookup step is abused to assign a increasing number
 * to the rows. So that later on we can the rows order by that number
 * in order to check whether sort is working.
 *
 * @author <NAME>
 */
public class SortRowsTest extends TestCase
{
    public static final String[] databasesXML = {
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
        "<connection>" +
            "<name>db</name>" +
            "<server>127.0.0.1</server>" +
            "<type>HYPERSONIC</type>" +
            "<access>Native</access>" +
            "<database>mem:db</database>" +
            "<port></port>" +
            "<username>sa</username>" +
            "<password></password>" +
          "</connection>",
    };
    
    private static String target_table = "sort_target";
    private static String source_table = "sort_source";
    
    public static int MAX_COUNT = 15000;
    
	/**
	 * Create source and target table.
	 */
	public void createTables(Database db) throws Exception
	{		
		Row r = new Row();
		r.addValue(new Value("ID",       Value.VALUE_TYPE_INTEGER, 8, 0));
		r.addValue(new Value("KEY1",     Value.VALUE_TYPE_STRING, 40, 0));
		r.addValue(new Value("KEY2",     Value.VALUE_TYPE_STRING, 40, 0));
		
		String target = db.getCreateTableStatement(target_table, r, null, false, null, true);
		try  {
		    db.execStatement(target);
		}
		catch ( KettleException ex ) 
		{
		   // Table already existed probably	<commit_msg>Check in for CR #2428 : 500 rows is enough for testing sortrows step<commit_after>/**********************************************************************
 **                                                                   **
 **               This code belongs to the KETTLE project.            **
 **                                                                   **
 ** Kettle, from version 2.2 on, is released into the public domain   **
 ** under the Lesser GNU Public License (LGPL).                       **
 **                                                                   **
 ** For more details, please read the document LICENSE.txt, included  **
 ** in this project                                                   **
 **                                                                   **
 ** http://www.kettle.be                                              **
 ** <EMAIL>                                                    **
 **                                                                   **
 **********************************************************************/

package be.ibridge.kettle.trans.step.sortrows;

import java.sql.ResultSet;
import java.util.Random;

import junit.framework.TestCase;
import be.ibridge.kettle.core.Const;
import be.ibridge.kettle.core.LogWriter;
import be.ibridge.kettle.core.Row;
import be.ibridge.kettle.core.database.Database;
import be.ibridge.kettle.core.database.DatabaseMeta;
import be.ibridge.kettle.core.exception.KettleException;
import be.ibridge.kettle.core.util.EnvUtil;
import be.ibridge.kettle.core.value.Value;
import be.ibridge.kettle.trans.StepLoader;
import be.ibridge.kettle.trans.Trans;
import be.ibridge.kettle.trans.TransHopMeta;
import be.ibridge.kettle.trans.TransMeta;
import be.ibridge.kettle.trans.step.StepMeta;
import be.ibridge.kettle.trans.step.StepMetaInterface;
import be.ibridge.kettle.trans.step.combinationlookup.CombinationLookupMeta;
import be.ibridge.kettle.trans.step.tableinput.TableInputMeta;

/**
 * Test class for sort rows step. HSQL is used
 * as database in memory to get an easy playground for database
 * tests. HSQL does not support all SQL features but it should
 * proof enough for most of our tests.
 * 
 * What will be done... a database table will be filled with rows
 * consisting of 2 keyfields (randomly generated, but unique). 
 * A database step will read the table, link it to a sort rows step,
 * linking it to a combination lookup step.
 * 
 * The combination lookup step is abused to assign a increasing number
 * to the rows. So that later on we can the rows order by that number
 * in order to check whether sort is working.
 *
 * @author <NAME>
 */
public class SortRowsTest extends TestCase
{
    public static final String[] databasesXML = {
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
        "<connection>" +
            "<name>db</name>" +
            "<server>127.0.0.1</server>" +
            "<type>HYPERSONIC</type>" +
            "<access>Native</access>" +
            "<database>mem:db</database>" +
            "<port></port>" +
            "<username>sa</username>" +
            "<password></password>" +
          "</connection>",
    };
    
    private static String target_table = "sort_target";
    private static String source_table = "sort_source";
    
    public static int MAX_COUNT = 500;
    
	/**
	 * Create source and target table.
	 */
	public void createTables(Database db) throws Exception
	{		
		Row r = new Row();
		r.addValue(new Value("ID",       Value.VALUE_TYPE_INTEGER, 8, 0));
		r.addValue(new Value("KEY1",     Value.VALUE_TYPE_STRING, 40, 0));
		r.addValue(new Value("KEY2",     Value.VALUE_TYPE_STRING, 40, 0));
		
		String target = db.getCreateTableStatement(target_table, r, null, false, null, true);
		try  {
		    db.execStatement(target);
		}
		catch ( KettleException ex ) 
		{
		   // Table already existed probably	
{'fraction_non_alphanumeric': 0.13937910601571557, 'fraction_numerical': 0.007600154579415174, 'mean_word_length': 2.049489395129615, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 2, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 42, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2653175', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1971, 'n_words': 572}