예제 #1
0
 public override void And(Bitmap other)
 {
     if (other is RoaringBitmap)
     {
         RoaringBitmap roaringBitmapOther = (RoaringBitmap)other;
         for (int i = 0; i < roaringBitmapOther.containers.Count(); i++)
         {
             if (roaringBitmapOther.containers[i] is BitmapContainer)
             {
                 containers[i].And(roaringBitmapOther.containers[i]);
                 if (containers[i].cardinality < 4096 && containers[i] is BitmapContainer)
                 {
                     containers[i] = new ArrayContainer((BitmapContainer)containers[i]);
                 }
             }
             else if (containers[i] is ArrayContainer)
             {
                 containers[i].And(roaringBitmapOther.containers[i]);
             }
             else
             {
                 containers[i].And(roaringBitmapOther.containers[i]);
                 ArrayContainer res = (ArrayContainer)roaringBitmapOther.containers[i];
                 containers[i] = res;
             }
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Реализует первую и вторую фазы Invisible Join
        /// </summary>
        /// <param name="filters"></param>
        /// <returns></returns>
        public static RoaringBitmap Phase1AndPhase2(string[] filters)
        {
            RoaringBitmap resBitmap = null;

            for (int i = 0; i < filters.Length; i++)
            {
                string             tableAndColumn = filters[i].Split(' ')[0];
                string             tableName      = tableAndColumn.Split('.')[0];
                string             columnName     = tableAndColumn.Split('.')[1];
                Table              table          = CreateTable(tableAndColumn, true);
                Type               columnType     = table.GetTypeOfColumn(columnName);
                Predicate <object> filter         = GetPredicate(filters[i], columnType);
                RoaringBitmap      columnBitmap;
                if (tableName == factTableName)
                {
                    columnBitmap = table.GetBitmap(filter);
                }
                else
                {
                    List <int> indexes = table.GetListIndexes(columnName, filter);
                    string     columnNameInFactTable = tableName == "DimDate" ? "OrderDateKey" : $"{tableName.Substring(3)}Key";
                    string     pathToFactTableColumn = $"{pathToData}/{factTableName}.{columnNameInFactTable}.csv";
                    columnBitmap = Table.GetBitmap(pathToFactTableColumn, indexes);
                }
                resBitmap = resBitmap == null ? columnBitmap : resBitmap;
                resBitmap.And(columnBitmap);
            }
            if (resBitmap == null)
            {
                int countLinesInTable = File.ReadAllLines($"{pathToData}/FactResellerSales.CarrierTrackingNumber.csv").Length;
                resBitmap = RoaringBitmap.OnesRoaringBitmap(countLinesInTable);
            }
            return(resBitmap);
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Incorrect args");
            }
            else
            {
                pathToData  = args[0].Trim('/');
                pathToTests = args[1];
                pathToAns   = args[2];

                //Get input data
                string[] input          = File.ReadAllLines(pathToTests);
                int      countOfFilters = int.Parse(input[1]);
                string[] filters        = new string[countOfFilters];
                //Invisible join
                Array.Copy(input, 2, filters, 0, input.Length - 2);
                RoaringBitmap resBitmap     = Phase1AndPhase2(filters);
                string[]      neededColumns = input[0].Split(',');
                Table         resultTable   = Phase3(neededColumns);
                //Print result
                string result = resultTable.ToString(resBitmap);
                File.WriteAllText(pathToAns, result);
            }
        }
예제 #4
0
        public static RoaringBitmap OnesRoaringBitmap(int countOfElem)
        {
            RoaringBitmap bitmap = new RoaringBitmap(countOfElem);

            for (int i = 0; i < bitmap.containers.Length; i++)
            {
                bitmap.containers[i] = new BitmapContainer(false);
            }
            return(bitmap);
        }
예제 #5
0
        /// <summary>
        /// Выводит подходящие под bitmap строки таблицы, разделяя
        /// их \n
        /// </summary>
        /// <param name="bitmap"></param>
        /// <returns></returns>
        public string ToString(RoaringBitmap bitmap)
        {
            string result = string.Empty;

            for (int i = 0; i < countOfStrings; i++)
            {
                if (bitmap.Get(i))
                {
                    List <string> values = new List <string>();
                    foreach (Array arrays in columns.Values)
                    {
                        values.Add(arrays.GetValue(i).ToString());
                    }
                    result += $"{string.Join("|", values)}\n";
                }
            }
            return(result);
        }