text:
package org.apache.carbondata.core.scan.executor.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;

import org.apache.carbondata.core.cache.Cache;
import org.apache.carbondata.core.cache.CacheProvider;
import org.apache.carbondata.core.cache.CacheType;
import org.apache.carbondata.core.cache.dictionary.Dictionary;
import org.apache.carbondata.core.cache.dictionary.DictionaryColumnUniqueIdentifier;
import org.apache.carbondata.core.constants.CarbonCommonConstants;
import org.apache.carbondata.core.datastore.block.SegmentProperties;
import org.apache.carbondata.core.keygenerator.KeyGenException;
import org.apache.carbondata.core.keygenerator.KeyGenerator;
import org.apache.carbondata.core.metadata.AbsoluteTableIdentifier;
import org.apache.carbondata.core.metadata.CarbonMetadata;
import org.apache.carbondata.core.metadata.CarbonTableIdentifier;
import org.apache.carbondata.core.metadata.datatype.DataType;
import org.apache.carbondata.core.metadata.encoder.Encoding;
import org.apache.carbondata.core.metadata.schema.table.CarbonTable;
import org.apache.carbondata.core.metadata.schema.table.column.CarbonDimension;
import org.apache.carbondata.core.metadata.schema.table.column.CarbonMeasure;
import org.apache.carbondata.core.scan.complextypes.ArrayQueryType;
import org.apache.carbondata.core.scan.complextypes.PrimitiveQueryType;
import org.apache.carbondata.core.scan.complextypes.StructQueryType;
import org.apache.carbondata.core.scan.executor.infos.KeyStructureInfo;
import org.apache.carbondata.core.scan.expression.ColumnExpression;
import org.apache.carbondata.core.scan.expression.Expression;
import org.apache.carbondata.core.scan.filter.GenericQueryType;
import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf;
import org.apache.carbondata.core.scan.filter.resolver.resolverinfo.DimColumnResolvedFilterInfo;
import org.apache.carbondata.core.scan.model.QueryDimension;
import org.apache.carbondata.core.scan.model.QueryMeasure;
import org.apache.carbondata.core.scan.model.QueryModel;
import org.apache.carbondata.core.util.CarbonUtil;

import org.apache.commons.lang3.ArrayUtils;

/**
 * Utility class for query execution
 */
public class QueryUtil {

  /**
   * Below method will be used to get the masked byte range based on the query
   * dimension. It will give the range in the mdkey. This will be used to get
   * the actual key array from masked mdkey
   *
   * @param queryDimensions query dimension selected in query
   * @param keyGenerator    key generator
   * @return masked key
   */
  public static int[] getMaskedByteRange(List<QueryDimension> queryDimensions,
      KeyGenerator keyGenerator) {
    Set<Integer> byteRangeSet = new TreeSet<Integer>();
    int[] byteRange = null;
    for (int i = 0; i < queryDimensions.size(); i++) {

      // as no dictionary column and complex type columns
      // are not selected in the mdkey
      // so we will not select the those dimension for calculating the
      // range
      if (queryDimensions.get(i).getDimension().getKeyOrdinal() == -1) {
        continue;
      }
      // get the offset of the dimension in the mdkey
      byteRange =
          keyGenerator.getKeyByteOffsets(queryDimensions.get(i).getDimension().getKeyOrdinal());
      for (int j = byteRange[0]; j <= byteRange[1]; j++) {
        byteRangeSet.add(j);
      }
    }
    int[] maksedByteRange = new int[byteRangeSet.size()];
    int index = 0;
    Iterator<Integer> iterator = byteRangeSet.iterator();
    // add the masked byte range
    while (iterator.hasNext()) {
      maksedByteRange[index++] = iterator.next();
    }
    return maksedByteRange;
  }

  public static int[] getMaskedByteRangeBasedOrdinal(List<Integer> ordinals,
      KeyGenerator keyGenerator) {
    Set<Integer> byteRangeSet = new TreeSet<Integer>();
    int[] byteRange = null;
    for (int i = 0; i < ordinals.size(); i++) {

      // get the offset of the dimension in the mdkey
      byteRange = keyGenerator.getKeyByteOffsets(ordinals.get(i));
      for (int j = byteRange[0]; j <= byteRange[1]; j++) {
        byteRangeSet.add(j);
      }
    }
    int[] maksedByteRange = new int[byteRangeSet.size()];
    int index = 0;
    Iterator<Integer> iterator = byteRangeSet.iterator();
    // add the masked byte range
    while (iterator.hasNext()) {
      maksedByteRange[index++] = iterator.next();
    }
    return maksedByteRange;
  }

  /**
   * Below method will return the max key based on the dimension ordinal
   *
   * @param keyOrdinalList
   * @param generator
   * @return
   * @throws KeyGenException
   */
  public static byte[] getMaxKeyBasedOnOrinal(List<Integer> keyOrdinalList, KeyGenerator generator)
      throws KeyGenException {
    long[] max = new long[generator.getDimCount()];
    Arrays.fill(max, 0L);

    for (int i = 0; i < keyOrdinalList.size(); i++) {
      // adding for dimension which is selected in query
      max[keyOrdinalList.get(i)] = Long.MAX_VALUE;
    }
    return generator.generateKey(max);
  }

  /**
   * To get the max key based on dimensions. i.e. all other dimensions will be
   * set to 0 bits and the required query dimension will be masked with all
   * LONG.MAX so that we can mask key and then compare while aggregating This
   * can be useful during filter query when only few dimensions were selected
   * out of row group
   *
   * @param queryDimensions dimension selected in query
   * @param generator       key generator
   * @return max key for dimension
   * @throws KeyGenException if any problem while generating the key
   */
  public static byte[] getMaxKeyBasedOnDimensions(List<QueryDimension> queryDimensions,
      KeyGenerator generator) throws KeyGenException {
    long[] max = new long[generator.getDimCount()];
    Arrays.fill(max, 0L);

    for (int i = 0; i < queryDimensions.size(); i++) {
      // as no dictionary column and complex type columns
      // are not selected in the mdkey
      // so we will not select the those dimension for calculating the
      // range
      if (queryDimensions.get(i).getDimension().getKeyOrdinal() == -1) {
        continue;
      }
      // adding for dimension which is selected in query
      max[queryDimensions.get(i).getDimension().getKeyOrdinal()] = Long.MAX_VALUE;
    }

    return generator.generateKey(max);
  }

  /**
   * Below method will be used to get the masked key for query
   *
   * @param keySize         size of the masked key
   * @param maskedKeyRanges masked byte range
   * @return masked bytes
   */
  public static int[] getMaskedByte(int keySize, int[] maskedKeyRanges) {
    int[] maskedKey = new int[keySize];
    // all the non selected dimension will be filled with -1
    Arrays.fill(maskedKey, -1);
    for (int i = 0; i < maskedKeyRanges.length; i++) {
      maskedKey[maskedKeyRanges[i]] = i;
    }
    return maskedKey;
  }

  /**
   * Below method will be used to get the dimension block index in file based
   * on query dimension
   *
   * @param queryDimensions                query dimension
   * @param dimensionOrdinalToBlockMapping mapping of dimension block in file to query dimension
   * @return block index of file
   */
  public static int[] getDimensionsBlockIndexes(List<QueryDimension> queryDimensions,
      Map<Integer, Integer> dimensionOrdinalToBlockMapping,
      List<CarbonDimension> customAggregationDimension, Set<CarbonDimension> filterDimensions,
      Set<Integer> allProjectionListDimensionIndexes) {
    // using set as in row group columns will point to same block
    Set<Integer> dimensionBlockIndex = new HashSet<Integer>();
    Set<Integer> filterDimensionOrdinal = getFilterDimensionOrdinal(filterDimensions);
    int blockIndex = 0;
    for (int i = 0; i < queryDimensions.size(); i++) {
      if (queryDimensions.get(i).getDimension().hasEncoding(Encoding.IMPLICIT)) {
        continue;
      }

      Integer dimensionOrdinal = queryDimensions.get(i).getDimension().getOrdinal();
      allProjectionListDimensionIndexes.add(dimensionOrdinalToBlockMapping.get(dimensionOrdinal));
      if (queryDimensions.get(i).getDimension().numberOfChild() > 0) {
        addChildrenBlockIndex(allProjectionListDimensionIndexes,
            queryDimensions.get(i).getDimension());
      }

      if (!filterDimensionOrdinal.contains(dimensionOrdinal)) {
        blockIndex = dimensionOrdinalToBlockMapping.get(dimensionOrdinal);
        dimensionBlockIndex.add(blockIndex);
        if (queryDimensions.get(i).getDimension().numberOfChild() > 0) {
          addChildrenBlockIndex(dimensionBlockIndex, queryDimensions.get(i).getDimension());
        }
      }
    }
    for (int i = 0; i < customAggregationDimension.size(); i++) {
      blockIndex =
          dimensionOrdinalToBlockMapping.get(customAggregationDimension.get(i).getOrdinal());
      // not adding the children dimension as dimension aggregation
      // is not push down in case of complex dimension
      dimensionBlockIndex.add(blockIndex);
    }
    int[] dimensionIndex = ArrayUtils
        .toPrimitive(dimensionBlockIndex.toArray(new Integer[dimensionBlockIndex.size()]));
    Arrays.sort(dimensionIndex);
    return dimensionIndex;
  }

  /**
   * Below method will be used to get the dimension block index in file based
   * on query dimension
   *
   * @param queryDimensions                query dimension
   * @param dimensionOrdinalToBlockMapping mapping of dimension block in file to query dimension
   * @return block index of file
   */
  public static int[] getDimensionsBlockIndexes(List<QueryDimension> queryDimensions,
      Map<Integer, Integer> dimensionOrdinalToBlockMapping) {
    // using set as in row group columns will point to same block
    Set<Integer> dimensionBlockIndex = new HashSet<Integer>();
    int blockIndex = 0;
    for (int i = 0; i < queryDimensions.size(); i++) {
      blockIndex =
          dimensionOrdinalToBlockMapping.get(queryDimensions.get(i).getDimension().getOrdinal());
      dimensionBlockIndex.add(blockIndex);
      if (queryDimensions.get(i).getDimension().numberOfChild() > 0) {
        addChildrenBlockIndex(dimensionBlockIndex, queryDimensions.get(i).getDimension());
      }
    }
    return ArrayUtils
        .toPrimitive(dimensionBlockIndex.toArray(new Integer[dimensionBlockIndex.size()]));
  }

  /**
   * Below method will be used to add the children block index
   * this will be basically for complex dimension which will have children
   *
   * @param blockIndexes block indexes
   * @param dimension    parent dimension
   */
  private static void addChildrenBlockIndex(Set<Integer> blockIndexes, CarbonDimension dimension) {
    for (int i = 0; i < dimension.numberOfChild(); i++) {
      addChildrenBlockIndex(blockIndexes, dimension.getListOfChildDimensions().get(i));
      blockIndexes.add(dimension.getListOfChildDimensions().get(i).getOrdinal());
    }
  }

  /**
   * Below method will be used to get the dictionary mapping for all the
   * dictionary encoded dimension present in the query
   *
   * @param queryDimensions         query dimension present in the query this will be used to
   *                                convert the result from surrogate key to actual data
   * @param absoluteTableIdentifier absolute table identifier
   * @return dimension unique id to its dictionary map
   * @throws IOException
   */
  public static Map<String, Dictionary> getDimensionDictionaryDetail(
      List<QueryDimension> queryDimensions, Set<CarbonDimension> filterComplexDimensions,
      AbsoluteTableIdentifier absoluteTableIdentifier) throws IOException {
    // to store dimension unique column id list, this is required as
    // dimension can be present in
    // query dimension, as well as some aggregation function will be applied
    // in the same dimension
    // so we need to get only one instance of dictionary
    // direct dictionary skip is done only for the dictionary lookup
    Set<String> dictionaryDimensionFromQuery = new HashSet<String>();
    for (int i = 0; i < queryDimensions.size(); i++) {
      List<Encoding> encodingList = queryDimensions.get(i).getDimension().getEncoder();
      // TODO need to remove the data type check for parent column in complex type no need to
      // write encoding dictionary
      if (CarbonUtil.hasEncoding(encodingList, Encoding.DICTIONARY) && !CarbonUtil
          .hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY) && !CarbonUtil
          .hasEncoding(encodingList, Encoding.IMPLICIT)) {

        if (queryDimensions.get(i).getDimension().numberOfChild() == 0) {
          dictionaryDimensionFromQuery.add(queryDimensions.get(i).getDimension().getColumnId());
        }
        if (queryDimensions.get(i).getDimension().numberOfChild() > 0) {
          getChildDimensionDictionaryDetail(queryDimensions.get(i).getDimension(),
              dictionaryDimensionFromQuery);
        }
      }
    }
    Iterator<CarbonDimension> iterator = filterComplexDimensions.iterator();
    while (iterator.hasNext()) {
      getChildDimensionDictionaryDetail(iterator.next(), dictionaryDimensionFromQuery);
    }
    // converting to list as api exposed needed list which i think
    // is not correct
    List<String> dictionaryColumnIdList =
        new ArrayList<String>(dictionaryDimensionFromQuery.size());
    dictionaryColumnIdList.addAll(dictionaryDimensionFromQuery);
    return getDictionaryMap(dictionaryColumnIdList, absoluteTableIdentifier);
  }

  /**
   * Below method will be used to fill the children dimension column id
   *
   * @param queryDimensions              query dimension
   * @param dictionaryDimensionFromQuery dictionary dimension for query
   */
  private static void getChildDimensionDictionaryDetail(CarbonDimension queryDimensions,
      Set<String> dictionaryDimensionFromQuery) {
    for (int j = 0; j < queryDimensions.numberOfChild(); j++) {
      List<Encoding> encodingList = queryDimensions.getListOfChildDimensions().get(j).getEncoder();
      if (queryDimensions.getListOfChildDimensions().get(j).numberOfChild() > 0) {
        getChildDimensionDictionaryDetail(queryDimensions.getListOfChildDimensions().get(j),
            dictionaryDimensionFromQuery);
      } else if (!CarbonUtil.hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY)) {
        dictionaryDimensionFromQuery
            .add(queryDimensions.getListOfChildDimensions().get(j).getColumnId());
      }
    }
  }

  /**
   * Below method will be used to get the column id to its dictionary mapping
   *
   * @param dictionaryColumnIdList  dictionary column list
   * @param absoluteTableIdentifier absolute table identifier
   * @return dictionary mapping
   * @throws IOException
   */
  private static Map<String, Dictionary> getDictionaryMap(List<String> dictionaryColumnIdList,
      AbsoluteTableIdentifier absoluteTableIdentifier) throws IOException {
    // this for dictionary unique identifier
    List<DictionaryColumnUniqueIdentifier> dictionaryColumnUniqueIdentifiers =
        getDictionaryColumnUniqueIdentifierList(dictionaryColumnIdList,
            absoluteTableIdentifier.getCarbonTableIdentifier());
    CacheProvider cacheProvider = CacheProvider.getInstance();
    Cache<DictionaryColumnUniqueIdentifier, Dictionary> forwardDictionaryCache = cacheProvider
        .createCache(CacheType.FORWARD_DICTIONARY, absoluteTableIdentifier.getStorePath());

    List<Dictionary> columnDictionaryList =
        forwardDictionaryCache.getAll(dictionaryColumnUniqueIdentifiers);
    Map<String, Dictionary> columnDictionaryMap = new HashMap<>(columnDictionaryList.size());
    for (int i = 0; i < dictionaryColumnUniqueIdentifiers.size(); i++) {
      // TODO: null check for column dictionary, if cache size is less it
      // might return null here, in that case throw exception
      columnDictionaryMap.put(dictionaryColumnIdList.get(i), columnDictionaryList.get(i));
    }
    return columnDictionaryMap;
  }

  /**
   * Below method will be used to get the dictionary column unique identifier
   *
   * @param dictionaryColumnIdList dictionary
   * @param carbonTableIdentifier
   * @return
   */
  private static List<DictionaryColumnUniqueIdentifier> getDictionaryColumnUniqueIdentifierList(
      List<String> dictionaryColumnIdList, CarbonTableIdentifier carbonTableIdentifier) {
    CarbonTable carbonTable =
        CarbonMetadata.getInstance().getCarbonTable(carbonTableIdentifier.getTableUniqueName());
    List<DictionaryColumnUniqueIdentifier> dictionaryColumnUniqueIdentifiers =
        new ArrayList<>(dictionaryColumnIdList.size());
    for (String columnId : dictionaryColumnIdList) {
      CarbonDimension dimension = CarbonMetadata.getInstance()
          .getCarbonDimensionBasedOnColIdentifier(carbonTable, columnId);
      if (dimension != null) {
        dictionaryColumnUniqueIdentifiers.add(
            new DictionaryColumnUniqueIdentifier(
                carbonTableIdentifier,
                dimension.getColumnIdentifier(),
                dimension.getDataType()
            )
        );
      }
    }
    return dictionaryColumnUniqueIdentifiers;
  }

  /**
   * Below method will used to get the method will be used to get the measure
   * block indexes to be read from the file
   *
   * @param queryMeasures              query measure
   * @param expressionMeasure          measure present in the expression
   * @param ordinalToBlockIndexMapping measure ordinal to block mapping
   * @return block indexes
   */
  public static int[] getMeasureBlockIndexes(List<QueryMeasure> queryMeasures,
      List<CarbonMeasure> expressionMeasure, Map<Integer, Integer> ordinalToBlockIndexMapping,
      Set<CarbonMeasure> filterMeasures, List<Integer> allProjectionListMeasureIdexes) {
    Set<Integer> measureBlockIndex = new HashSet<Integer>();
    Set<Integer> filterMeasureOrdinal = getFilterMeasureOrdinal(filterMeasures);
    for (int i = 0; i < queryMeasures.size(); i++) {
      Integer measureOrdinal = queryMeasures.get(i).getMeasure().getOrdinal();
      allProjectionListMeasureIdexes.add(measureOrdinal);
      if (!filterMeasureOrdinal.contains(measureOrdinal)) {
        measureBlockIndex.add(ordinalToBlockIndexMapping.get(measureOrdinal));
      }
    }
    for (int i = 0; i < expressionMeasure.size(); i++) {
      measureBlockIndex.add(ordinalToBlockIndexMapping.get(expressionMeasure.get(i).getOrdinal()));
    }
    int[] measureIndexes =
        ArrayUtils.toPrimitive(measureBlockIndex.toArray(new Integer[measureBlockIndex.size()]));
    Arrays.sort(measureIndexes);
    return measureIndexes;
  }

  /**
   * Below method will be used to get mapping whether dimension is present in
   * order by or not
   *
   * @param sortedDimensions sort dimension present in order by query
   * @param queryDimensions  query dimension
   * @return sort dimension indexes
   */
  public static byte[] getSortDimensionIndexes(List<QueryDimension> sortedDimensions,
      List<QueryDimension> queryDimensions) {
    byte[] sortedDims = new byte[queryDimensions.size()];
    int indexOf = 0;
    for (int i = 0; i < sortedDims.length; i++) {
      indexOf = sortedDimensions.indexOf(queryDimensions.get(i));
      if (indexOf > -1) {
        sortedDims[i] = 1;
      }
    }
    return sortedDims;
  }

  /**
   * Below method will be used to get the mapping of block index and its
   * restructuring info
   *
   * @param queryDimensions   query dimension from query model
   * @param segmentProperties segment properties
   * @return map of block index to its restructuring info
   * @throws KeyGenException if problem while key generation
   */
  public static Map<Integer, KeyStructureInfo> getColumnGroupKeyStructureInfo(
      List<QueryDimension> queryDimensions, SegmentProperties segmentProperties)
      throws KeyGenException {
    Map<Integer, KeyStructureInfo> rowGroupToItsRSInfo = new HashMap<Integer, KeyStructureInfo>();
    // get column group id and its ordinal mapping of column group
    Map<Integer, List<Integer>> columnGroupAndItsOrdinalMappingForQuery =
        getColumnGroupAndItsOrdinalMapping(queryDimensions);
    Map<Integer, KeyGenerator> columnGroupAndItsKeygenartor =
        segmentProperties.getColumnGroupAndItsKeygenartor();

    Iterator<Entry<Integer, List<Integer>>> iterator =
        columnGroupAndItsOrdinalMappingForQuery.entrySet().iterator();
    KeyStructureInfo restructureInfos = null;
    while (iterator.hasNext()) {
      Entry<Integer, List<Integer>> next = iterator.next();
      KeyGenerator keyGenerator = columnGroupAndItsKeygenartor.get(next.getKey());
      restructureInfos = new KeyStructureInfo();
      // sort the ordinal
      List<Integer> ordinal = next.getValue();
      List<Integer> mdKeyOrdinal = new ArrayList<Integer>();
      //Un sorted
      List<Integer> mdKeyOrdinalForQuery = new ArrayList<Integer>();
      for (Integer ord : ordinal) {
        mdKeyOrdinal.add(segmentProperties.getColumnGroupMdKeyOrdinal(next.getKey(), ord));
        mdKeyOrdinalForQuery.add(segmentProperties.getColumnGroupMdKeyOrdinal(next.getKey(), ord));
      }
      Collections.sort(mdKeyOrdinal);
      // get the masked byte range for column group
      int[] maskByteRanges = getMaskedByteRangeBasedOrdinal(mdKeyOrdinal, keyGenerator);
      // max key for column group
      byte[] maxKey = getMaxKeyBasedOnOrinal(mdKeyOrdinal, keyGenerator);
      restructureInfos.setKeyGenerator(keyGenerator);
      restructureInfos.setMaskByteRanges(maskByteRanges);
      restructureInfos.setMaxKey(maxKey);
      restructureInfos.setMdkeyQueryDimensionOrdinal(ArrayUtils
          .toPrimitive(mdKeyOrdinalForQuery.toArray(new Integer[mdKeyOrdinalForQuery.size()])));
      rowGroupToItsRSInfo
          .put(segmentProperties.getDimensionOrdinalToBlockMapping().get(ordinal.get(0)),
              restructureInfos);
    }
    return rowGroupToItsRSInfo;
  }

  /**
   * return true if given key is found in array
   *
   * @param data
   * @param key
   * @return
   */
  public static boolean searchInArray(int[] data, int key) {
    for (int i = 0; i < data.length; i++) {
      if (key == data[i]) {
        return true;
      }
    }
    return false;
  }

  /**
   * Below method will be used to create a mapping of column group columns
   * this mapping will have column group id to all the dimension ordinal
   * present in the column group This mapping will be used during query
   * execution, to create a mask key for the column group dimension which will
   * be used in aggregation and filter query as column group dimension will be
   * stored in bit level
   */
  private static Map<Integer, List<Integer>> getColumnGroupAndItsOrdinalMapping(
      List<QueryDimension> origdimensions) {

    List<QueryDimension> dimensions = new ArrayList<QueryDimension>(origdimensions.size());
    dimensions.addAll(origdimensions);
    /**
     * sort based on column group id
     */
    Collections.sort(dimensions, new Comparator<QueryDimension>() {

      @Override public int compare(QueryDimension o1, QueryDimension o2) {
        return Integer
            .compare(o1.getDimension().columnGroupId(), o2.getDimension().columnGroupId());
      }
    });
    // list of row groups this will store all the row group column
    Map<Integer, List<Integer>> columnGroupAndItsOrdinalsMapping =
        new HashMap<Integer, List<Integer>>();
    // to store a column group
    List<Integer> currentColumnGroup = null;
    // current index
    int index = 0;
    // previous column group to check all the column of row id has bee
    // selected
    int prvColumnGroupId = -1;
    while (index < dimensions.size()) {
      // if dimension group id is not zero and it is same as the previous
      // column group id
      // then we need to add ordinal of that column as it belongs to same
      // column group
      if (dimensions.get(index).getDimension().hasEncoding(Encoding.IMPLICIT)) {
        index++;
        continue;
      } else if (!dimensions.get(index).getDimension().isColumnar()
          && dimensions.get(index).getDimension().columnGroupId() == prvColumnGroupId
          && null != currentColumnGroup) {
        currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal());
      }

      // if dimension is not a columnar then it is column group column
      else if (!dimensions.get(index).getDimension().isColumnar()) {
        currentColumnGroup = new ArrayList<Integer>();
        columnGroupAndItsOrdinalsMapping
            .put(dimensions.get(index).getDimension().columnGroupId(), currentColumnGroup);
        currentColumnGroup.add(dimensions.get(index).getDimension().getOrdinal());
      }
      // update the row id every time,this is required to group the
      // columns
      // of the same row group
      prvColumnGroupId = dimensions.get(index).getDimension().columnGroupId();
      index++;
    }
    return columnGroupAndItsOrdinalsMapping;
  }

  /**
   * Below method will be used to get masked byte
   *
   * @param data           actual data
   * @param maxKey         max key
   * @param maskByteRanges mask byte range
   * @param byteCount
   * @return masked byte
   */
  public static byte[] getMaskedKey(byte[] data, byte[] maxKey, int[] maskByteRanges,
      int byteCount) {
    byte[] maskedKey = new byte[byteCount];
    int counter = 0;
    int byteRange = 0;
    for (int i = 0; i < byteCount; i++) {
      byteRange = maskByteRanges[i];
      if (byteRange != -1) {
        maskedKey[counter++] = (byte) (data[byteRange] & maxKey[byteRange]);
      }
    }
    return maskedKey;
  }

  /**
   * Below method will be used to fill block indexes of the query dimension
   * which will be used in creating a output row Here is method we are passing
   * two list which store the indexes one for dictionary column other for not
   * dictionary column. This is done for specific purpose so that in one
   * iteration we will be able to fill both type dimension block indexes
   *
   * @param queryDimensions                  dimension present in the query
   * @param columnOrdinalToBlockIndexMapping column ordinal to block index mapping
   * @param dictionaryDimensionBlockIndex    list to store dictionary column block indexes
   * @param noDictionaryDimensionBlockIndex  list to store no dictionary block indexes
   */
  public static void fillQueryDimensionsBlockIndexes(List<QueryDimension> queryDimensions,
      Map<Integer, Integer> columnOrdinalToBlockIndexMapping,
      Set<Integer> dictionaryDimensionBlockIndex, List<Integer> noDictionaryDimensionBlockIndex) {
    for (QueryDimension queryDimension : queryDimensions) {
      if (CarbonUtil.hasEncoding(queryDimension.getDimension().getEncoder(), Encoding.DICTIONARY)
          && queryDimension.getDimension().numberOfChild() == 0) {
        dictionaryDimensionBlockIndex
            .add(columnOrdinalToBlockIndexMapping.get(queryDimension.getDimension().getOrdinal()));
      } else if (
          !CarbonUtil.hasEncoding(queryDimension.getDimension().getEncoder(), Encoding.IMPLICIT)
              && queryDimension.getDimension().numberOfChild() == 0) {
        noDictionaryDimensionBlockIndex
            .add(columnOrdinalToBlockIndexMapping.get(queryDimension.getDimension().getOrdinal()));
      }
    }
  }

  /**
   * Below method will be used to resolve the query model
   * resolve will be setting the actual dimension and measure object
   * as from driver only column name will be passes to avoid the heavy object
   * serialization
   *
   * @param queryModel query model
   */
  public static void resolveQueryModel(QueryModel queryModel) {
    CarbonMetadata.getInstance().addCarbonTable(queryModel.getTable());
    // TODO need to load the table from table identifier
    CarbonTable carbonTable = queryModel.getTable();
    String tableName =
        queryModel.getAbsoluteTableIdentifier().getCarbonTableIdentifier().getTableName();
    // resolve query dimension
    for (QueryDimension queryDimension : queryModel.getQueryDimension()) {
      queryDimension
          .setDimension(carbonTable.getDimensionByName(tableName, queryDimension.getColumnName()));
    }
    // resolve query measure
    for (QueryMeasure queryMeasure : queryModel.getQueryMeasures()) {
      // in case of count start column name will  be count * so
      // first need to check any measure is present or not and as if measure
      // if measure is present and if first measure is not a default
      // measure than add measure otherwise
      // than add first dimension as a measure
      //as currently if measure is not present then
      //we are adding default measure so first condition will
      //never come false but if in future we can remove so not removing first if check
      if (queryMeasure.getColumnName().equals("count(*)")) {
        if (carbonTable.getMeasureByTableName(tableName).size() > 0 && !carbonTable
            .getMeasureByTableName(tableName).get(0).getColName()
            .equals(CarbonCommonConstants.DEFAULT_INVISIBLE_DUMMY_MEASURE)) {
          queryMeasure.setMeasure(carbonTable.getMeasureByTableName(tableName).get(0));
        } else {
          CarbonMeasure dummyMeasure = new CarbonMeasure(
              carbonTable.getDimensionByTableName(tableName).get(0).getColumnSchema(), 0);
          queryMeasure.setMeasure(dummyMeasure);
        }
      } else {
        queryMeasure
            .setMeasure(carbonTable.getMeasureByName(tableName, queryMeasure.getColumnName()));
      }
    }
  }

  /**
   * below method will be used to get the actual type aggregator
   *
   * @param aggType
   * @return index in aggrgetor
   */
  public static int[] getActualTypeIndex(List<String> aggType) {
    List<Integer> indexList = new ArrayList<Integer>();
    for (int i = 0; i < aggType.size(); i++) {
      if (!CarbonCommonConstants.SUM.equals(aggType.get(i)) && !CarbonCommonConstants.AVERAGE
          .equals(aggType.get(i))) {
        indexList.add(i);
      }
    }
    return ArrayUtils.toPrimitive(indexList.toArray(new Integer[indexList.size()]));
  }

  /**
   * Below method will be used to get the key structure for the column group
   *
   * @param segmentProperties      segment properties
   * @param dimColumnEvaluatorInfo dimension evaluator info
   * @return key structure info for column group dimension
   * @throws KeyGenException
   */
  public static KeyStructureInfo getKeyStructureInfo(SegmentProperties segmentProperties,
      DimColumnResolvedFilterInfo dimColumnEvaluatorInfo) throws KeyGenException {
    int colGrpId = getColumnGroupId(segmentProperties, dimColumnEvaluatorInfo.getColumnIndex());
    KeyGenerator keyGenerator = segmentProperties.getColumnGroupAndItsKeygenartor().get(colGrpId);
    List<Integer> mdKeyOrdinal = new ArrayList<Integer>();

    mdKeyOrdinal.add(segmentProperties
        .getColumnGroupMdKeyOrdinal(colGrpId, dimColumnEvaluatorInfo.getColumnIndex()));
    int[] maskByteRanges = QueryUtil.getMaskedByteRangeBasedOrdinal(mdKeyOrdinal, keyGenerator);
    byte[] maxKey = QueryUtil.getMaxKeyBasedOnOrinal(mdKeyOrdinal, keyGenerator);
    KeyStructureInfo restructureInfos = new KeyStructureInfo();
    restructureInfos.setKeyGenerator(keyGenerator);
    restructureInfos.setMaskByteRanges(maskByteRanges);
    restructureInfos.setMaxKey(maxKey);
    return restructureInfos;
  }

  /**
   * Below method will be used to get the column group id based on the ordinal
   *
   * @param segmentProperties segment properties
   * @param ordinal           ordinal to be searched
   * @return column group id
   */
  public static int getColumnGroupId(SegmentProperties segmentProperties, int ordinal) {
    int[][] columnGroups = segmentProperties.getColumnGroups();
    int colGrpId = -1;
    for (int i = 0; i < columnGroups.length; i++) {
      if (columnGroups[i].length > 1) {
        colGrpId++;
        if (QueryUtil.searchInArray(columnGroups[i], ordinal)) {
          break;
        }
      }
    }
    return colGrpId;
  }

  /**
   * Below method will be used to get the map of for complex dimension and its type
   * which will be used to during query execution to
   *
   * @param queryDimensions          complex dimension in query
   * @param dimensionToBlockIndexMap dimension to block index in file map
   * @return complex dimension and query type
   */
  public static Map<Integer, GenericQueryType> getComplexDimensionsMap(
      List<QueryDimension> queryDimensions, Map<Integer, Integer> dimensionToBlockIndexMap,
      int[] eachComplexColumnValueSize, Map<String, Dictionary> columnIdToDictionaryMap,
      Set<CarbonDimension> filterDimensions) {
    Map<Integer, GenericQueryType> complexTypeMap = new HashMap<Integer, GenericQueryType>();
    for (QueryDimension dimension : queryDimensions) {
      CarbonDimension actualDimension = dimension.getDimension();
      if (actualDimension.getNumberOfChild() == 0) {
        continue;
      }
      fillParentDetails(dimensionToBlockIndexMap, actualDimension, complexTypeMap,
          eachComplexColumnValueSize, columnIdToDictionaryMap);
    }
    if (null != filterDimensions) {
      for (CarbonDimension filterDimension : filterDimensions) {
        // do not fill nay details for implicit dimension type
        if (filterDimension.hasEncoding(Encoding.IMPLICIT)
            || filterDimension.getNumberOfChild() == 0) {
          continue;
        }
        fillParentDetails(dimensionToBlockIndexMap, filterDimension, complexTypeMap,
            eachComplexColumnValueSize, columnIdToDictionaryMap);
      }
    }
    return complexTypeMap;
  }

  private static void fillParentDetails(Map<Integer, Integer> dimensionToBlockIndexMap,
      CarbonDimension dimension, Map<Integer, GenericQueryType> complexTypeMap,
      int[] eachComplexColumnValueSize, Map<String, Dictionary> columnIdToDictionaryMap) {
    int parentBlockIndex = dimensionToBlockIndexMap.get(dimension.getOrdinal());
    GenericQueryType parentQueryType = dimension.getDataType().equals(DataType.ARRAY) ?
        new ArrayQueryType(dimension.getColName(), dimension.getColName(), parentBlockIndex) :
        new StructQueryType(dimension.getColName(), dimension.getColName(),
            dimensionToBlockIndexMap.get(dimension.getOrdinal()));
    complexTypeMap.put(dimension.getOrdinal(), parentQueryType);
    parentBlockIndex =
        fillChildrenDetails(eachComplexColumnValueSize, columnIdToDictionaryMap, parentBlockIndex,
            dimension, parentQueryType);
  }

  private static int fillChildrenDetails(int[] eachComplexColumnValueSize,
      Map<String, Dictionary> columnIdToDictionaryMap, int parentBlockIndex,
      CarbonDimension dimension, GenericQueryType parentQueryType) {
    for (int i = 0; i < dimension.getNumberOfChild(); i++) {
      switch (dimension.getListOfChildDimensions().get(i).getDataType()) {
        case ARRAY:
          parentQueryType.addChildren(
              new ArrayQueryType(dimension.getListOfChildDimensions().get(i).getColName(),
                  dimension.getColName(), ++parentBlockIndex));
          break;
        case STRUCT:
          parentQueryType.addChildren(
              new StructQueryType(dimension.getListOfChildDimensions().get(i).getColName(),
                  dimension.getColName(), ++parentBlockIndex));
          break;
        default:
          boolean isDirectDictionary = CarbonUtil
              .hasEncoding(dimension.getListOfChildDimensions().get(i).getEncoder(),
                  Encoding.DIRECT_DICTIONARY);
          parentQueryType.addChildren(
              new PrimitiveQueryType(dimension.getListOfChildDimensions().get(i).getColName(),
                  dimension.getColName(), ++parentBlockIndex,
                  dimension.getListOfChildDimensions().get(i).getDataType(),
                  eachComplexColumnValueSize[dimension.getListOfChildDimensions().get(i)
                      .getComplexTypeOrdinal()], columnIdToDictionaryMap
                  .get(dimension.getListOfChildDimensions().get(i).getColumnId()),
                  isDirectDictionary));
      }
      if (dimension.getListOfChildDimensions().get(i).getNumberOfChild() > 0) {
        parentBlockIndex = fillChildrenDetails(eachComplexColumnValueSize, columnIdToDictionaryMap,
            parentBlockIndex, dimension.getListOfChildDimensions().get(i), parentQueryType);
      }
    }
    return parentBlockIndex;
  }

  public static void getAllFilterDimensions(FilterResolverIntf filterResolverTree,
      Set<CarbonDimension> filterDimensions, Set<CarbonMeasure> filterMeasure) {
    if (null == filterResolverTree) {
      return;
    }
    List<ColumnExpression> dimensionResolvedInfos = new ArrayList<ColumnExpression>();
    Expression filterExpression = filterResolverTree.getFilterExpression();
    addColumnDimensions(filterExpression, filterDimensions, filterMeasure);
    for (ColumnExpression info : dimensionResolvedInfos) {
      if (info.isDimension() && info.getDimension().getNumberOfChild() > 0) {
        filterDimensions.add(info.getDimension());
      }
    }
  }

  /**
   * This method will check if a given expression contains a column expression
   * recursively and add the dimension instance to the set which holds the dimension
   * instances of the complex filter expressions.
   */
  private static void addColumnDimensions(Expression expression,
      Set<CarbonDimension> filterDimensions, Set<CarbonMeasure> filterMeasure) {
    if (null != expression && expression instanceof ColumnExpression) {
      if (((ColumnExpression) expression).isDimension()) {
        filterDimensions.add(((ColumnExpression) expression).getDimension());
      } else {
        filterMeasure.add((CarbonMeasure) ((ColumnExpression) expression).getCarbonColumn());
      }
      return;
    } else if (null != expression) {
      for (Expression child : expression.getChildren()) {
        addColumnDimensions(child, filterDimensions, filterMeasure);
      }
    }
  }

  private static Set<Integer> getFilterMeasureOrdinal(Set<CarbonMeasure> filterMeasures) {
    Set<Integer> filterMeasuresOrdinal = new HashSet<>();
    for (CarbonMeasure filterMeasure : filterMeasures) {
      filterMeasuresOrdinal.add(filterMeasure.getOrdinal());
    }
    return filterMeasuresOrdinal;
  }

  private static Set<Integer> getFilterDimensionOrdinal(Set<CarbonDimension> filterDimensions) {
    Set<Integer> filterDimensionsOrdinal = new HashSet<>();
    if(filterDimensions == null){
       return filterDimensionsOrdinal;
    }
    for (CarbonDimension filterDimension : filterDimensions) {
      filterDimensionsOrdinal.add(filterDimension.getOrdinal());
      getChildDimensionOrdinal(filterDimension, filterDimensionsOrdinal);
    }
    return filterDimensionsOrdinal;
  }

  /**
   * Below method will be used to fill the children dimension column id
   */
  private static void getChildDimensionOrdinal(CarbonDimension queryDimensions,
      Set<Integer> filterDimensionsOrdinal) {
    for (int j = 0; j < queryDimensions.numberOfChild(); j++) {
      List<Encoding> encodingList = queryDimensions.getListOfChildDimensions().get(j).getEncoder();
      if (queryDimensions.getListOfChildDimensions().get(j).numberOfChild() > 0) {
        getChildDimensionOrdinal(queryDimensions.getListOfChildDimensions().get(j),
            filterDimensionsOrdinal);
      } else if (!CarbonUtil.hasEncoding(encodingList, Encoding.DIRECT_DICTIONARY)) {
        filterDimensionsOrdinal.add(queryDimensions.getListOfChildDimensions().get(j).getOrdinal());
      }
    }
  }
}


#39;s title-track was featured in a province-wide campaign in their native Saskatchewan. Early 2008 has already seen the completion of their follow-up album, which mixes elements of southern rock and moody soul with gleeful straight-forward rockers. Once again, the boys are hitting the road, spreading their rock n roll revival to the rest of Canada.


There are various techniques which can be used to determine a blown head gasket. Be very careful when performing these tests, when a vehicle has a blown head gasket, the engine can overheat quickly. The cooling system can also build excessive pressure which could cause the cooling system to rupture. Even a very small breach in the head gasket (often the diameter of a paper clip) will allow exhaust gases to enter into the coolant system. If exhaust gases are present, a head gasket repair will be required. A very common method to test for exhaust gases is a block test kit, which can be purchased for around $50 or most auto parts stores will provide the kit on a "loaner" basis. You will usally have to purchase the test fluid, the price is around $10.
1. Remove the pressure cap from the radiator or expansion tank, check to see that the coolant level is low enough to prevent any coolant from getting into the test equipment (approx. 3″ below the fill hole). It may be necessary to drain enough coolant out to prevent the contamination of the test fluid.
2. Warm the engine, and allow it to idle during the test. Coolant must be circulating so the exhaust gases can enter the cooling system while this test is in process.
3. The color of test fluid before pouring it into your test equipment should be blue. If the fluid is green or yellow, the fluid is too old and should be replaced with blue test fluid.
4. Pour test fluid into glass tube to the fill line.
5. Insert the cone of the test instrument onto the neck of the radiator or expansion tank, insure there is a tight seal.
6. Insert the squeeze bulb into the top of the test instrument and squeeze it for about a minute to pull radiator gases through test fluid. If exhaust gases are present, the test fliud will "sniff" the gases as they are pulled through the fluid. If the blue fluid turns yellow or green, exhaust gases are leaking into the coolant system, and a head gasket repair is required.
7. If fluid remains blue, exhaust gases are not present in the cooling system.
8. If a blown head gasket is suspected, but the block test passes, it is possible that the head gasket breach is between the cylinders. Sometimes a vehicle can still have a blown head gasket without exhaust gases leaking into the coolant system. A compression test will be required. Call Ideal Head Gasket Repair for help in diagnosing a blown head gasket.


text:
Treasury security
Title: Treasury security
Subject: Federal Reserve System, Thomas Jefferson, Marian Anderson, Short (finance), George Meade, Debt, Monetary policy of the United States, Federal Deposit Insurance Corporation, John Wesley Snyder (US Cabinet Secretary), Brady Bonds
This article provides insufficient context for those unfamiliar with the subject. Please help improve the article with a good introductory style. (February 2013)
A United States Treasury security is a government debt issued by the United States Department of the Treasury through the Bureau of the Public Debt. Treasury securities are the debt financing instruments of the United States federal government, and they are often referred to simply as Treasuries. There are four types of marketable treasury securities: Treasury bills, Treasury notes, Treasury bonds, and Treasury Inflation Protected Securities (TIPS). There are several types of non-marketable treasury securities including State and Local Government Series (SLGS), Government Account Series debt issued to government-managed trust funds, and savings bonds. All of the marketable Treasury securities are very liquid and are heavily traded on the secondary market. The non-marketable securities (such as savings bonds) are issued to subscribers and cannot be transferred through market sales.
1 Backing of US Currency
3 Marketable securities
3.1 Directly issued by the United States Government
3.1.1 Treasury bill
3.1.1.1 Pricing & Quotation
3.1.2 Treasury note
3.1.3 Treasury bond
3.1.4 TIPS
3.2 Created by the Financial Industry
3.2.1 STRIPS
4 Nonmarketable securities
4.1 Zero-Percent Certificate of Indebtedness
4.2 Government Account Series
4.3 U.S. Savings Bonds
4.3.1 Series EE
4.3.2 Series I
4.3.3 Series HH
5 Holdings
5.1 Domestic
5.2 International
Backing of US Currency
The Congress has specified that Federal Reserve Banks must hold collateral equal in value to the Federal Reserve notes that the Federal Reserve Bank puts into circulation. This collateral is chiefly held in the form of U.S. Treasury debt, federal agency, and government-sponsored enterprise securities.[1]
The U.S. government knew that the costs of World War I would be high, and the question of how to pay for the war was a matter of intense debate. The resulting decision was to pay for the war with a balance between higher taxes (see the War Tax Act) and government debt. Traditionally, the government borrowed from other countries, but there were no other countries from which to borrow in 1917: US citizens would have to finance the war through both higher taxes and purchases of war bonds.[2]
The Treasury raised funding throughout the war by selling $21.5 billion in 'Liberty bonds.' These bonds were sold at subscription where officials created coupon price and then sold it at Par value. At this price, subscriptions could be filled in as little as one day, but usually remained open for several weeks, depending on demand for the bond.[2]
After the war, the Liberty Bonds were reaching maturity, but the Treasury was unable to pay each down fully with only limited budget surpluses. The resolution to this problem was to refinance the debt with variable short and medium-term maturities. Again the Treasury issued debt through fixed-price subscription, where both the coupon and the price of the debt were dictated by the treasury.[2]
The problems with debt issuance became apparent in the late-1920s. The system suffered from chronic oversubscription, where interest rates were so attractive that there were more purchasers of debt than supplied by the government. This indicated that the government was paying too much for debt. As government debt was undervalued, debt purchasers could buy from the government and immediately sell to another market participant at a higher price.[2]
In 1929, the US Treasury shifted from the fixed-price subscription system to a system of auctioning where 'Treasury Bills' would be sold to the highest bidder. Securities were then issued on a pro rata system where securities would be allocated to the highest bidder until their demand was full. If more treasurys were supplied by the government, they would then be allocated to the next highest bidder. This system allowed the market, rather than the government, to set the price. On December 10, 1929, the Treasury issued its first auction. The result was the issuing of $224 million three-month bills. The highest bid was at 99.310 with the lowest bid accepted at 99.152.[2]
Foreign countries later started to buy US debt as an investment of their surplus US Dollars. There was fear that foreign countries held so many bonds that if they stopped buying them, the US economy would collapse. In reality more bonds were transferred in a single day by the Treasury than were held by any single sovereign state.[3] The perception of this dependence furthers belief that the US and China economies are so tightly linked that both fear the consequences of a potential slow down in China's purchase of those bonds. In her 2010 visit to China, the US Secretary of State Hillary Clinton called on authorities in Beijing to continue buying US Treasurys, saying it would help jumpstart the flagging US economy and stimulate imports of Chinese goods.[4]
As the economic recession continues, more doubts arise over the real value of US treasury securities. Though carefully worded, Chinese premier Wen Jia Bao's warning about possible devaluation of Chinese held US bonds was taken very seriously by Washington:
"Of course we are concerned about the safety of our assets. To be honest, I'm a little bit worried" ... "I would like to call on the United States to honor its words, stay a credible nation and ensure the safety of Chinese assets."[5] - Chinese premier, Wen Jiabao, said at a news conference after the closing of China's 2009 legislative session.
As of April 2009, the US dollar had rallied YTD against all other major world currencies. On March 18, 2009, the Federal Reserve used quantitative easing "to help improve conditions in private credit markets, the Committee decided to purchase up to $300 billion of longer-term Treasury securities over the next six months."[6]
Directly issued by the United States Government
Treasury bill
"Treasury bill" redirects here. Note that the Bank of England issues these in the United Kingdom.
Treasury bills (or T-Bills) mature in one year or less. Like zero-coupon bonds, they do not pay interest prior to maturity; instead they are sold at a discount of the par value to create a positive yield to maturity.[7] Many regard Treasury bills as the least risky investment available to U.S. investors.
Regular weekly T-Bills are commonly issued with maturity dates of 28 days (or 4 weeks, about a month), 91 days (or 13 weeks, about 3 months), 182 days (or 26 weeks, about 6 months), and 364 days (or 52 weeks, about 1 year). Treasury bills are sold by single-price auctions held weekly. Offering amounts for 13-week and 26-week bills are announced each Thursday for auction, usually at 11:30 a.m., on the following Monday and settlement, or issuance, on Thursday. Offering amounts for 4-week bills are announced on Monday for auction the next day, Tuesday, usually at 11:30 a.m., and issuance on Thursday. Offering amounts for 52-week bills are announced every fourth Thursday for auction the next Tuesday, usually at 11:30 am, and issuance on Thursday. Purchase orders at TreasuryDirect must be entered before 11:00 on the Monday of the auction. The minimum purchase, effective April 7, 2008, is $100. (This amount formerly had been $1,000.) Mature T-bills are also redeemed on each Thursday. Banks and financial institutions, especially primary dealers, are the largest purchasers of T-bills.
Like other securities, individual issues of T-bills are identified with a unique CUSIP number. The 13-week bill issued three months after a 26-week bill is considered a re-opening of the 26-week bill and is given the same CUSIP number. The 4-week bill issued two months after that and maturing on the same day is also considered a re-opening of the 26-week bill and shares the same CUSIP number. For example, the 26-week bill issued on March 22, 2007, and maturing on September 20, 2007, has the same CUSIP number (912795A27) as the 13-week bill issued on June 21, 2007, and maturing on September 20, 2007, and as the 4-week bill issued on August 23, 2007 that matures on September 20, 2007.
During periods when Treasury cash balances are particularly low, the Treasury may sell cash management bills (or CMBs). These are sold at a discount and by auction just like weekly Treasury bills. They differ in that they are irregular in amount, term (often less than 21 days), and day of the week for auction, issuance, and maturity. When CMBs mature on the same day as a regular weekly bill, usually Thursday, they are said to be on-cycle. The CMB is considered another reopening of the bill and has the same CUSIP. When CMBs mature on any other day, they are off-cycle and have a different CUSIP number.
Pricing & Quotation
Treasury bills are quoted for purchase and sale in the secondary market on an annualized discount percentage, or basis.
General calculation for the discount yield for Treasury bills is
\text{Discount Yield} (%) = \frac{\text{Face Value} - \text{Purchase Price}}{\text{Purchase Value}} \times \frac{\text{365}}{\text{Days Till Maturity}} \times 100[%]
Treasury note
This is the modern usage of "Treasury Note" in the U.S., for the earlier meanings see Treasury Note (disambiguation).
Treasury notes (or T-Notes) mature in two to ten years, have a coupon payment every six months, and have denominations of $1,000. In the basic transaction, one buys a "$1,000" T-Note for say, $950, collects interest over 10 years of say, 3% per year, which comes to $30 yearly, and at the end of the 10 years cashes it in for $1000. So, $950 over the course of 10 years becomes $1300.
T-Notes and T-Bonds are quoted on the secondary market at percentage of par in thirty-seconds of a point (n/32 of a point, where n = 1,2,3,...). Thus, for example, a quote of 95:07 on a note indicates that it is trading at a discount: $952.19 (i.e., 95 + 7/32%) for a $1,000 bond. (Several different notations may be used for bond price quotes. The example of 95 and 7/32 points may be written as 95:07, or 95-07, or 95'07, or decimalized as 95.21875.) Other notation includes a +, which indicates 1/64 points and a third digit may be specified to represent 1/256 points. Examples include 95:07+ which equates to (95 + 7/32 + 1/64) and 95:073 which equates to (95 + 7/32 + 3/256). Notation such as 95:073+ is not typically used.
The 10-year Treasury note has become the security most frequently quoted when discussing the performance of the U.S. government bond market and is used to convey the market's take on longer-term macroeconomic expectations.
Treasury bond
"U.S. Bonds" redirects here. For the singer/performer, see Gary U.S. Bonds.
Treasury bonds (T-Bonds, or the long bond) have the longest maturity, from twenty years to thirty years. They have a coupon payment every six months like T-Notes, and are commonly issued with maturity of thirty years. The secondary market is highly liquid, so the yield on the most recent T-Bond offering was commonly used as a proxy for long-term interest rates in general. This role has largely been taken over by the 10-year note, as the size and frequency of long-term bond issues declined significantly in the 1990s and early 2000s.
The U.S. Federal government suspended issuing 30-year Treasury bonds for four years from February 18, 2002 to February 9, 2006.[8] As the U.S. government used budget surpluses to pay down Federal debt in the late 1990s,[9] the 10-year Treasury note began to replace the 30-year Treasury bond as the general, most-followed metric of the U.S. bond market. However, because of demand from pension funds and large, long-term institutional investors, along with a need to diversify the Treasury's liabilities - and also because the flatter yield curve meant that the opportunity cost of selling long-dated debt had dropped - the 30-year Treasury bond was re-introduced in February 2006 and is now issued quarterly.[10] This brought the U.S. in line with Japan and European governments issuing longer-dated maturities amid growing global demand from pension funds. Since the 1970s the 10 Year Treasury Note and the 30 year fixed mortgage have had a very tight correlation.[11]
Treasury Inflation-Protected Securities (or TIPS) are the inflation-indexed bonds issued by the U.S. Treasury. The principal is adjusted to the Consumer Price Index (CPI), the commonly used measure of inflation. When the CPI rises, the principal adjusts upward. If the index falls, the principal adjusts downwards.[12] The coupon rate is constant, but generates a different amount of interest when multiplied by the inflation-adjusted principal, thus protecting the holder against the official inflation rate (as asserted by the CPI). TIPS were introduced in 1997.[13] TIPS are currently offered in 5-year, 10-year and 30-year maturities.[14]
Created by the Financial Industry
Separate Trading of Registered Interest and Principal Securities (or STRIPS) are T-Notes, T-Bonds and TIPS whose interest and principal portions of the security have been separated, or "stripped"; these may then be sold separately (in units of $100 face value) in the secondary market. The name derives from the days before computerization, when paper bonds were physically traded; traders would literally tear the interest coupons off of paper securities for separate resale.
The government does not directly issue STRIPS; they are formed by investment banks or brokerage firms, but the government does register STRIPS in its book-entry system. They cannot be bought through TreasuryDirect, but only through a broker.
STRIPS are used by the Treasury and split into individual principal and interest payments, which get resold in the form of zero-coupon bonds. Because they then pay no interest, there is not any interest to re-invest, and so there is no reinvestment risk with STRIPS.
Nonmarketable securities
Zero-Percent Certificate of Indebtedness
The "Certificate of Indebtedness" is a Treasury security that does not earn any interest and has no fixed maturity. It can only be held in a TreasuryDirect account and bought or sold directly through the Treasury. It is intended to be used as a source of funds for traditional Treasury security purchases. Purchases and redemptions can be made at any time.[15]
Government Account Series
Government Account Series Treasurys (GAS) are the principal form of intragovernmental debt holdings.[16] Surpluses from the Social Security Trust Fund are invested in this type of security.
U.S. Savings Bonds
Savings bonds were created to finance World War I, and were originally called Liberty Bonds. Unlike Treasury Bonds, they are not marketable. In 2002, the Treasury Department started changing the savings bond program by lowering interest rates and closing its marketing offices.[17] As of January 1, 2012, financial institutions no longer sell paper savings bonds.[18] The annual (calendar year) purchase limit for electronic Series EE and Series I savings bonds is $10,000 for each series. The limit is applied per Social Security Number (SSN) or Taxpayer Identification Number (TIN). For paper Series I Savings Bonds purchased through IRS tax refunds (see below), the purchase limit is $5,000 per SSN, which is in addition to the online purchase limit.[19]
Series EE
Series EE bonds reach maturity (double in value) 20 years from issuance though they continue to earn interest for a total of 30 years. Interest accrues monthly and is paid when the holder cashes the bond. For bonds issued before May 2005 the rate of interest is recomputed every six months at 90% of the average five-year Treasury yield for the preceding six months. Bonds issued in May 2005 or later pay a fixed interest rate for the life of the bond (0.20% in November 2012).[20] At 0.20%, a $100 bond would be worth less than $105 just before 20 years, but will be adjusted to the maturity value of $200 at 20 years (giving it an effective rate of 3.5%) then continue to earn the fixed rate for 10 more years. In the space of a decade, interest dropped from well over 5% to 0.7% for new bonds in 2009.[21] Paper EE bonds were issued with a face value of twice their purchase price, so a $100 bond could be bought for $50, but would not be worth $100 until maturity.
Series I bonds have a variable yield based on inflation. The interest rate consists of two components: the first is a fixed rate which will remain constant over the life of the bond. The second component is a variable rate reset every six months from the time the bond is purchased based on the current inflation rate. New rates are published on May 1 and November 1 of every year.[22] The fixed rate is determined by the Treasury Department (0% in November 2012); the variable component is based on the Consumer Price Index (CPI-U) from a six-month period ending one month prior to the reset time (0.878% in November 2012, reflecting the CPI-U from March to September, published in mid-October, for an effective annual inflation rate of 1.76%).[20] As an example, if someone purchases a bond in February, they will lock in the current fixed rate forever, but the inflation component will be based on the rate published the previous November. In August, six months after the purchase month, the inflation component will now change to the rate that was published in May while the fixed rate remains locked. Interest accrues monthly, in full, on the first day of the month (i.e., a Savings Bond will have the same value on July 1 as on July 31, but on August 1 its value will increase for the August interest accrual). The fixed portion of the rate has varied from as much as 3.6% to 0%. During times of deflation (during part of 2009), the negative inflation portion can wipe out the return of the fixed portion, but the combined rate cannot go below 0% and the bond will not lose value.[22]
Besides being available for purchase online, tax payers may purchase I-bonds using a portion of their tax refund via IRS Form 8888 Allocation of Refund. Bonds purchased using Form 8888 are issued as paper bonds and mailed to the address listed on the tax return. Tax payers may purchase bonds for themselves or other persons such as children or grandchildren. The remainder of the tax payer's refund may be received by direct deposit or check.[23]
Series HH
Series HH bonds have been discontinued. Unlike Series EE and I bonds, they do not increase in value, but pay interest every six months for 20 years. When they are cashed in or mature they are still worth face value. Issuance of Series HH bonds ended August 31, 2004.[24][25]
Further information: United States public debt
For the quantitative easing policy, the Federal Reserve holdings of U.S. Treasuries increased from $750 billion in 2007 to over $1.7 trillion as of end-March 2013.[26] On September 13, 2012, in an 11-to-1 vote, the Federal Reserve announced they were also buying $45 billion in long-term Treasuries each month on top of the $40 billion a month in mortgage-backed securities. The program is called QE3 because it is the Fed's third try at quantitative easing.[27] The result is that an enormous proportion of the US debt is actually owed from the Treasury to the Federal Reserve.
As of July 2013,[28] the top 25 foreign holders of U.S. Treasury Securities are:
$US billion
1. China 1277.3
2. Japan 1135.4
3. Caribbean Banking Centers 287.7
4. Oil Exporters 257.7
5. Brazil 256.4
6. Taiwan 185.8
7. Switzerland 178.2
8. Belgium 167.7
9. United Kingdom 156.9
10. Luxembourg 146.8
11. Russia 131.6
12. Hong Kong 120.0
13. Ireland 117.9
14. Singapore 81.5
15. Norway 74.6
16. Canada 65.5
17. Mexico 63.3
18. India 59.1
19. Germany 56.3
20. Turkey 55.0
21. Korea 51.4
22. France 49.8
23. Thailand 43.7
24. Philippines 38.9
25. Australia 33.1
Chiasso financial smuggling case
Strong dollar policy
War bond
War savings stamps
Bureau of the Public Debt: US Savings Bonds Online
Major Foreign Holders of U.S. Treasury Bonds
U.S. Bureau of the Public Debt: Series A, B, C, D, E, F, G, H, J, and K Savings Bonds and Savings Notes.
Features and Risks of Treasury Inflation Protection Securities
Types of bonds by issuer
Agency bond
Corporate bond (Senior debt, Subordinated debt)
Municipal bond
Types of bonds by payout
Accrual bond
Auction rate security
Callable bond
Commercial paper
Convertible bond
Exchangeable bond
Extendible bond
Fixed rate bond
Floating rate note
High-yield debt
Inflation-indexed bond
Inverse floating rate note
Perpetual bond
Puttable bond
Reverse convertible
Zero-coupon bond
Bond valuation
Clean price
Convexity
Credit spread
Current yield
Dirty price
I-spread
Mortgage yield
Nominal yield
Z-spread
Securitized products
Asset-backed security
Collateralized debt obligation
Collateralized mortgage obligation
Commercial mortgage-backed security
Mortgage-backed security
Yield-curve spread
Bond options
Embedded option
Option-adjusted spread
Commercial Mortgage Securities Association (CMSA)
International Capital Market Association (ICMA)
Securities Industry and Financial Markets Association (SIFMA)
fr:Treasury Note
ja:米国債 ru:Казначейские ценные бумаги США zh:国库券 (美国)
Monetary policy, President of the United States, United States, United States Senate, Federal Reserve Act
John Adams, James Madison, Benjamin Franklin, James Monroe, Virginia
Easter, The New York Times, Ella Fitzgerald, Eleanor Roosevelt, Franklin D. Roosevelt
Short (finance)
Structured finance, Canada, Speculation, Technical analysis, Stock market
George Meade
American Civil War, Battle of Gettysburg, Ulysses S. Grant, Abraham Lincoln, Overland Campaign

redpajama_set_name: RedPajamaCommonCrawl


text:
Iblul-Il je bil najbolj energičen kralj (lugal) Drugega marijskega kraljestva, ki je vladal okoli leta 2380 pr. n. št. Znan je po obsežnih vojnih pohodih proti Ebli v dolini srednjega Evfrata in proti različnin nasprotnikom ob gornjem Tigrisu, s katerimi je vzpostavil marijsko oblast na severu Sirije.

Vladanje

Viri
Iblul-Il je dokazan v Mariju, kjer so bili v mestnih templjih leta 1952 odkriti kipi z njegovim imenom. Njegova dejanja so znana iz pisma, ki ga je njegov naslednik Enna-Dagan poslal v Eblo.

Pohodi
Iblul-Il je organiziral več pohodov proti Ebli in njenim vazalom in zaveznikom. Vzrok zanje je bila verjetno naraščajoča militantnost Eble, njihov namen pa je bil prekinili trgovske poti med Kišem, Nagarjem in Eblo. Iblul-Il je bil sodobnik Eblinega kralja Igriš-Halama. V Enna-Daganovem pismu je omenjeno, da je ob srednjem Evfratu premagal mesto Galalaneni, in sodeloval v zmagoviti bitki z Abarsalom v pokrajini Zahiran,  ki jo je opustošil. Zatem se je odpravil na pohod v pokrajino Burman v deželi Sugurum, kjer je porazil mesta Šadab, Adalini in Arisum. Ko je izropal mesta Šaran in Damium, je pohod nadaljevali proti Neraadu in Hasuvanu. V mestu Mane je prejel davek iz Eble in iz trdnjave Hazuvan nadaljeval pohod in osvojil Emar.

V dolini Tigrisa je porazil  mesta Nahal, Nubat in Ša-da v pokrajini Gasur. Iblul-Il je pismu zadnjič omenjen po osvojitvi eblaitskih mest Barama, Aburu, Tibalat in Belan. Marijski kralj je uspešno dosegel svoje cilje, oslabil Eblo in pobral velik davek v srebru in zlatu.

Nasledstvo
Iblul-Ila je nasledil Nizi. Enna-Daganovo pismo je izjemno težko brati. V prvih branjih je bil  avtor Enna-Dagan   predstavljen kot general Eble, ki je porazil in odstavil Iblul-Ila. Novejša branja so potrdila Anna-Dagana kot marijskega kralja. Razvozlanje besedil iz arhivov Eble je pokazalo, da je Anna-Dagan kot princ Marija med vladanjem svojih predhodnikov prejemal darila Eble.

Opombe

Sklici

Kralji Marija
Vladarji v 24. stoletju pr. n. št.

redpajama_set_name: RedPajamaWikipedia


text:
Nick Allen March 26, 2021
A smoothie shop employee with butterflies in his stomach and a bleeding right hand sits next to an older gentleman on a bench. "Can I ask you something?" he prefaces. The worker then proceeds to babble about his crush, Maria. Should he follow her to New York City, and leave Florida behind? The older man offers advice—speaking from the heart—and it fills the younger man's soul, so much that he leaps from the bench and bursts into song. It's this young guy's big romantic moment, and he dances away before almost getting hit by a car, and then sings at people inside a mall, in which one patron tries to side-kick him.
This hilarious sequence, which overlaps cliché storytelling with the unassuming public, is just one of many endearing moments in "Bad Trip," a hidden camera comedy gem starring Eric André, Lil Rel Howery, and Tiffany Haddish that's finally coming out on Netflix. Directed by Kitao Sakurai, the previous director behind numerous episodes of "The Eric André Show," it shows an evolution in the hidden camera subgenre, given its warming spirit about people. Unlike the films that previously defined the subgenre, it's not so much about creating a freak show from unsuspecting extras, but in noting what one would do when confronted with someone as delusional as André's character Chris. Natural human behavior can be extremely funny, and Sakurai and André know it's possible to bring it out of people without being mean-spirited. Footage in the end credits of the real people excited to learn that they're in a movie—a comfort for us as well—confirms the chaos is controlled physically and emotionally, and that allows it to be a party.
"Bad Trip" is an excellent showcase for Eric André—it's more mainstream than his talk-show-in-hell "The Eric André Show" and less watered down than his recent resume-boosting, commercial work like "The Lion King" and elsewhere. This role lets him scream, sprint, crash into things, and show off that he's a sweetheart who wants to include you his absurdity. It's no stretch to say that André is going to be a huge comedic force—I knew this when I caught his Legalize Everything stand-up tour in Chicago in 2019, when he had a sold-out Chicago Theater completely wrapped up in his FaceTime-ing with the parents of random audience members. He's an affable anarchist with Robin Williams-like verve, and this project lets his burgeoning persona run wild alongside what the film advertises as "Real People. Real Pranks."
André's hilarious earnest Chris is joined in the movie by Lil Rel Howery, who would have been known enough at the time of filming from his scene-stealing turn in "Get Out," but is disguised as Chris' reserved friend Bud. They have adorable chemistry as two friends in Florida who decide to drive to New York to reunite Chris with his high school crush Maria (Michaela Conlin) after two disastrous brief run-ins at Eric's jobs. They support each other, like when Chris gets extremely drunk at a cowboy bar, or Bud finds himself inside a Porta Potty. Chris is the wide-eyed dreamer, and Bud is the demure rationalist. Their chemistry is as pure as the Golden Girls, so "Thank You For Being a Friend" is featured prominently in the soundtrack, in between scenes of slapstick pranks that further their road trip.
When Bud and Chris need a car to get to New York City, they "borrow" the bright pink Crown Vic that belongs to Bud's sister, Trina (Tiffany Haddish), who Bud fears but is relieved when she's put in jail for breaking house arrest. And yet soon enough, Haddish crawls out from under a prison bus, having broken out and starts looking for her car. When it's not where she stored it, she hunts Bud and Chris up the Eastern seaboard, making for some incredibly funny, abrasive scenes of her confronting people about whether they've seen them or her car that has "Bad Bitch" written on the window. Haddish bulldozes into every set-piece, exemplifying the film's over-the-top spirit. When talking to progressively uncomfortable strangers, she doesn't miss a beat and she relishes the opportunity to appear dangerous; when she steals a cop car and burns out of a donut shop parking lot, it's one of her many triumphant moments.
"Bad Trip" is a collision of great improvisational actors and authentically bewildered reactions from people unaware that they're now in Chris' story—which makes Michaela Conlin's performance as Maria all the more an essential middle to its Venn diagram. She enters the movie also as an innocent bystander, but that's a deceptive comic energy that plays out in very funny ways as she pushes back against Chris' delusions. In Chris' prank-based daydreams, Conlin matches André's intensity; that she has to play it straight in later scenes adds to the tension she creates, like when Chris tries to profess his love to her.
Just how funny is "Bad Trip"? After two viewings, it's one of those comedies with a stable laughing average and high replay value, even if it doesn't always hit you as hard. It knowingly plays a hit-and-miss game, and some scenes don't entirely work (like a grocery store drug trip that plays out like a soft tribute to "The Eric Andre Show"), while other pranks go for discomfort more than big laughs (like when Chris gets gas springing all over a gas station). But the movie has speediness on its side, with pacing that takes the plotting from one prank to the next, often including crowds of people in the latest big dramatic confrontation that comes from Bud and Chris' expected emotional arc. (A sudden car crash sequence is particularly well planned out, with cameras and extras ready nearby.) It's a steady build to its ultimate destination of NYC, and every major set piece is constructed to bubble with discomfort before then skyrocketing over the top. An early scene at Chris' smoothie shop job only begins with him making the drinks without spoons—it escalates to awkward tension with disgusted, annoyed customers, and then boom, a laugh-out-loud, gory finale that hits with impeccable, unexpected timing.
If certain parts of "Bad Trip" aren't as out-and-out cry-laughing as the work put into them desires, the story is still involving as it adds the dimensionality of unscripted human behavior. And it doesn't continue the hidden camera movie's waning intention of dunking on dummies, a factor that also makes this story more fluid than the start-and-stop traps, primed for reaction shots, in something like "Jackass"-spinoff like "Bad Grandpa." That's the true sweet spot, in how its pranks are engineered to get the unexpected to interact with Bud, Chris, and or Trina, and see if strangers try to help. ("You turned on us!" says Chris, after a golfer starts swinging a club at Chris and Bud while their penises are enjoined by a Chinese fingertrap.) An amazing scene comes at a tense mid-point, when Trina appears at a restaurant, spreading around fliers with Bud and Chris' dopey faces on them, advertising her desire to kill the two. She leaves. Bud and Chris then show up at the same place minutes later, and everyone's response, with some people trying to warn them, and others not wanting to get caught in the middle, is incredible. "Bad Trip" knows how to stir things up, and its funniest scenes often involve real people getting in the mix, tested by the brilliant skills of André, Howery, and Haddish. The ways that some people react to their pranks might shock you in some ways, and absolutely will not in others.
Now available on Netflix.
Nick Allen is an Assistant Editor at RogerEbert.com and a member of the Chicago Film Critics Association.
Margrete: Queen of the North
Tomris Laffly
Bad Trip (2021)
Rated R for crude sexual content, pervasive language, some graphic nudity and drug use.
Eric André as Chris
Lil Rel Howery as Bud
Tiffany Haddish as Trina Malone
Michaela Conlin as Maria Li
Andrew Barchilon
Andrew Laboy
Sascha Stanton Craven
Matthew Kosinski
Caleb Swyers
Joseph Shirley


"Topnotch4Real"..Straight out Of Dallas,Tx Brings You the Hottest,Swagged Out, Club Banger Of 2009 "COOGI DOWN" With Dallas Being Labeld as a ringtone city, Topnotch4Real has plans to change the whole misconception of that phrase!"We got Hit Records Out Here!..It Aint Just About No Dancing" Says TopnotchWell Here It is a new Movement Of HitS Has Arrived For The New Year!
Don't sleep on the homie!!!
im doin a mixtape banga to this one!!!!
I gotcha, finna re-up the link!


text:
La gasela vermella (Eudorcas rufina) és una espècie de gasela extinta que solia viure al nord d'Algèria i el Marroc. Tanmateix, alguns autors consideren que es tractava d'una subespècie de la gasela de front vermell (E. rufifrons). Probablement vivia a les àrees muntanyoses de l'Àfrica del Nord, que comptaven amb més aigua que els deserts. Fou observada per última vegada abans del 1894. Se'n coneixen tres espècimens, que foren comprats a Alger i Orà a finals del .

Referències

Eudorcas
Bòvids extints
Artiodàctils d'extinció recent