<commit_before>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.data.engine.impl.document.util;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.core.archive.RAInputStream;
import org.eclipse.birt.core.util.IOUtil;
import org.eclipse.birt.data.engine.cache.BasicCachedArray;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
import org.eclipse.birt.data.engine.impl.document.RowSaveUtil;
import org.eclipse.birt.data.engine.impl.document.viewing.RowIndexUtil;

/**
 * Read expression result when this report document is processed before. For
 * example, if there is an original query which generates a report document, and
 * a new query which is running based the report document. So the new query
 * result may be not the same as the result before.
 */
class ExprDataReader2 implements IExprDataReader
{
	private RAInputStream rowExprsIs;
	private RAInputStream rowLenIs;
	
	private DataInputStream rowExprsDis;
	
	protected int rowCount;
	
	private int lastRowIndex;
	private int currRowIndex;
	
	private int currRowLenReadIndex;
	
	private RowIndexUtil rowIndexUtil;
	
	private int nextDestIndex; // TODO: enhanceme
	
	private Map exprValueMap;	
	private BasicCachedArray rowIDMap;
	private List exprKeys;
	private int metaOffset;
	
	/**
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @throws DataException 
	 */
	protected ExprDataReader2( RAInputStream rowExprsIs, RAInputStream rowLenIs, int rowCount ) throws DataException
	{
		initialize( rowExprsIs, rowLenIs, rowCount );
	}

	/**
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @param rowInfoIs
	 * @throws DataException
	 */
	ExprDataReader2( RAInputStream rowExprsIs, RAInputStream rowLenIs,
			RAInputStream rowInfoIs ) throws DataException
	{
		this.rowIndexUtil = new RowIndexUtil( rowInfoIs );
		
		try
		{
			int rowCount = (int) ( rowInfoIs.length( ) / 4 );
			initialize( rowExprsIs, rowLenIs, rowCount );
		}
		catch ( IOException e )
		{
			throw new DataException( ResourceConstants.RD_LOAD_ERROR,
					e,
					"Result Data" );
		}		
	}
	
	/**
	 * 
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @throws DataException
	 */
	private void initialize( RAInputStream rowExprsIs, RAInputStream rowLenIs, int rowCount ) throws DataException
	{
		try
		{
			//Skip row count.
			IOUtil.readInt( rowExprsIs );
			
			int exprCount = IOUtil.readInt( rowExprsIs );
			this.exprKeys = new ArrayList();
			this.rowExprsDis = new DataInputStream( rowExprsIs );
			for( int i = 0; i < exprCount; i++ )
			{
				this.exprKeys.add( IOUtil.readString( this.rowExprsDis ) );
			}
			this.metaOffset = IOUtil.INT_LENGTH
					+ IOUtil.readInt( this.rowExprsDis ) + IOUtil.INT_LENGTH;
			
		}
		catch ( IOException e )
		{
			throw new DataException( ResourceConstants.RD_LOAD_ERROR,
					e,
					"Result Data" );
		}
		
		this.rowExprsIs = rowExprsIs;
		this.rowLenIs = rowLenIs;
		
		this.currRowIndex = -1;
		this.lastRowIndex = -1;
		this.currRowLenReadIndex = -1;
		this.rowCount = rowCount;
		this.rowIDMap = new BasicCachedArray( rowCount );
	}
	
	/*<commit_msg>CheckIn:Fix tracker bug 89680 IV: Infinite loop progress in attempt to run 2nd chart operation in attached rpt<commit_after>/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/
package org.eclipse.birt.data.engine.impl.document.util;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.birt.core.archive.RAInputStream;
import org.eclipse.birt.core.util.IOUtil;
import org.eclipse.birt.data.engine.cache.BasicCachedArray;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;
import org.eclipse.birt.data.engine.impl.document.RowSaveUtil;
import org.eclipse.birt.data.engine.impl.document.viewing.RowIndexUtil;

/**
 * Read expression result when this report document is processed before. For
 * example, if there is an original query which generates a report document, and
 * a new query which is running based the report document. So the new query
 * result may be not the same as the result before.
 */
class ExprDataReader2 implements IExprDataReader
{
	private RAInputStream rowExprsIs;
	private RAInputStream rowLenIs;
	
	private DataInputStream rowExprsDis;
	
	protected int rowCount;
	
	private int lastRowIndex;
	private int currRowIndex;
	
	private int currRowLenReadIndex;
	
	private RowIndexUtil rowIndexUtil;
	
	private int nextDestIndex; // TODO: enhanceme
	
	private Map exprValueMap;	
	private BasicCachedArray rowIDMap;
	private List exprKeys;
	private int metaOffset;
	
	/**
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @throws DataException 
	 */
	protected ExprDataReader2( RAInputStream rowExprsIs, RAInputStream rowLenIs, int rowCount ) throws DataException
	{
		initialize( rowExprsIs, rowLenIs, rowCount );
	}

	/**
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @param rowInfoIs
	 * @throws DataException
	 */
	ExprDataReader2( RAInputStream rowExprsIs, RAInputStream rowLenIs,
			RAInputStream rowInfoIs ) throws DataException
	{
		this.rowIndexUtil = new RowIndexUtil( rowInfoIs );
		
		try
		{
			int rowCount = (int) ( rowInfoIs.length( ) / 4 );
			initialize( rowExprsIs, rowLenIs, rowCount );
		}
		catch ( IOException e )
		{
			throw new DataException( ResourceConstants.RD_LOAD_ERROR,
					e,
					"Result Data" );
		}		
	}
	
	/**
	 * 
	 * @param rowExprsIs
	 * @param rowLenIs
	 * @throws DataException
	 */
	private void initialize( RAInputStream rowExprsIs, RAInputStream rowLenIs, int rowCount ) throws DataException
	{
		try
		{
			//Skip row count.
			IOUtil.readInt( rowExprsIs );
			
			int exprCount = IOUtil.readInt( rowExprsIs );
			this.exprKeys = new ArrayList();
			this.rowExprsDis = new DataInputStream( rowExprsIs );
			for( int i = 0; i < exprCount; i++ )
			{
				this.exprKeys.add( IOUtil.readString( this.rowExprsDis ) );
			}
			this.metaOffset = IOUtil.INT_LENGTH
					+ IOUtil.readInt( this.rowExprsDis ) + IOUtil.INT_LENGTH;
			
		}
		catch ( IOException e )
		{
			throw new DataException( ResourceConstants.RD_LOAD_ERROR,
					e,
					"Result Data" );
		}
		
		this.rowExprsIs = rowExprsIs;
		this.rowLenIs = rowLenIs;
		
		this.currRowIndex = -1;
		this.lastRowIndex = -1;
		this.currRowLenReadIndex = 0;
		this.rowCount = rowCount;
		this.rowIDMap = new BasicCachedArray( rowCount );
	}
	
	/*
{'fraction_non_alphanumeric': 0.12788232175987277, 'fraction_numerical': 0.0055658627087198514, 'mean_word_length': 4.027981345769487, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6966428', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2261, 'n_words': 617}