public static string getColumnNamePartitionedBy(Table t)
        {
            QueryPartitionSource qs = (QueryPartitionSource)t.Partitions[0].Source;
            string partitionQuery   = qs.Query.ToString().Replace("\"", "").ToUpper();
            int    first            = partitionQuery.IndexOf("WHERE", 0) + "where".Length;
            int    last             = Math.Min(partitionQuery.IndexOf(">", 0) > 0 ? partitionQuery.IndexOf(">", 0) : partitionQuery.Length,
                                               partitionQuery.IndexOf("<", 0) > 0 ? partitionQuery.IndexOf("<", 0) : partitionQuery.Length);

            string fullObjName = partitionQuery.Substring(first, last - first);

            first = fullObjName.LastIndexOf(".") + 1;
            last  = fullObjName.Length;
            string tabularPartitionBy = fullObjName.Substring(first, last - first);

            return(tabularPartitionBy);
        }
Beispiel #2
0
    static private void getPartitionQueries(Model model)
    {
        foreach (Table table in model.Tables)
        {
            switch (table.Partitions[0].SourceType)
            {
            case PartitionSourceType.Query:
                QueryPartitionSource queryPartitionSource = (QueryPartitionSource)table.Partitions[0].Source;
                myConsoleWriteLine($"Table = {table.Name} - Query =  {queryPartitionSource.Query}");
                break;

            case PartitionSourceType.M:
                MPartitionSource mPartitionSource = (MPartitionSource)table.Partitions[0].Source;
                myConsoleWriteLine($"Table = {table.Name} - Expression =  {mPartitionSource.Expression}");
                break;
            }
        }
    }
Beispiel #3
0
        private static void MergePartitions(Table table)
        {
            // Create a new Current Partition so we can re-add it later
            QueryPartitionSource currentPartitionSource = table.Partitions["0"].Source as QueryPartitionSource;
            Partition            newCurrentPartition    = new Partition
            {
                Name   = "0",
                Source = new QueryPartitionSource {
                    DataSource = currentPartitionSource.DataSource, Query = currentPartitionSource.Query
                }
            };

            table.Partitions["1"].RequestMerge(new List <Partition> {
                table.Partitions["0"]
            });
            table.Model.SaveChanges();

            // Add the new Current Partition - the old Current Partition is now Merged with Partition "1", Process RECALC to update relationships and save the Model
            table.Partitions.Add(newCurrentPartition);
        }
Beispiel #4
0
        private static void ShufflePartitions(Table table)
        {
            // Load the Partition Query for each Partition into a dictionary to use when shuffling Partitions. Find the maximum number of partitions we are dealing with.
            var partitionQueries = table.Partitions.ToDictionary((x) => int.Parse(x.Name), y => (y.Source as QueryPartitionSource).Query);
            int maxPartition     = partitionQueries.Keys.Max();

            // If we have already performed the Partition shuffle(i.e. this routine has already been run today), there is nothing to do so exit
            if (table.Partitions["0"].ModifiedTime.ToLocalTime() > DateTime.Today)
            {
                return;
            }
            ;

            // Create a new Current Partition so we can re-add it later
            QueryPartitionSource currentPartitionSource = table.Partitions["0"].Source as QueryPartitionSource;
            Partition            newCurrentPartition    = new Partition
            {
                Name   = "0",
                Source = new QueryPartitionSource {
                    DataSource = currentPartitionSource.DataSource, Query = currentPartitionSource.Query
                }
            };

            // Delete the oldest Partition and save the model
            table.Partitions.Remove($"{maxPartition}");
            table.Model.SaveChanges();

            // Now iterate over all the Partitions from the second oldest to the newest to rename them to the next oldest
            for (int i = (maxPartition - 1); i >= 0; i--)
            {
                ((QueryPartitionSource)table.Partitions[i.ToString()].Source).Query = partitionQueries[i + 1];
                table.Partitions[i.ToString()].RequestRename((i + 1).ToString());
                table.Model.SaveChanges();
            }

            // Add the new Current Partition - the old Current Partition is now named "1", Process RECALC to update relationships and save the Model
            table.Partitions.Add(newCurrentPartition);
        }
        public static Tuple <DateTime, DateTime> getPartitionFromTo(Partition p)
        {
            QueryPartitionSource qs = (QueryPartitionSource)p.Source;
            string partitionQuery = qs.Query.ToString().Replace("\"", "");
            int    greaterInd = partitionQuery.IndexOf(">", 0);
            int    lessInd = partitionQuery.IndexOf("<", 0);
            string fromStr, toStr;

            if (greaterInd < lessInd && greaterInd > 0 && lessInd > 0)
            {
                fromStr = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(greaterInd, lessInd - greaterInd), "[^0-9]+", string.Empty));
                toStr   = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(lessInd, partitionQuery.Length - lessInd), "[^0-9]+", string.Empty));
            }

            else if (greaterInd > lessInd && greaterInd > 0 && lessInd > 0)
            {
                toStr   = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(lessInd, greaterInd - lessInd), "[^0-9]+", string.Empty));
                fromStr = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(greaterInd, partitionQuery.Length - greaterInd), "[^0-9]+", string.Empty));
            }
            else if (greaterInd < 0 && lessInd > 0)
            {
                toStr   = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(lessInd, partitionQuery.Length - lessInd), "[^0-9]+", string.Empty));
                fromStr = XMLreader.minDefaultDate;
            }
            else if (greaterInd > 0 && lessInd < 0)
            {
                fromStr = (System.Text.RegularExpressions.Regex.Replace(partitionQuery.Substring(greaterInd, partitionQuery.Length - greaterInd), "[^0-9]+", string.Empty));
                toStr   = XMLreader.maxDefaultDate;
            }

            else
            {
                fromStr = XMLreader.minDefaultDate;
                toStr   = XMLreader.maxDefaultDate;
            }
            return(Tuple.Create(DateTime.ParseExact(fromStr, "yyyyMMdd", null), DateTime.ParseExact(toStr, "yyyyMMdd", null)));
        }