using System; namespace AsPartitionProcessing { /// /// Configuration information for partitioning of a table within an AS tabular model. /// public class PartitioningConfiguration : IComparable { /// /// ID of the PartitioningConfiguration table. /// public int PartitioningConfigurationID { get; set; } /// /// Partition granularity, which can be Yearly, Monthly or Daily. /// public Granularity Granularity { get; set; } /// /// Count of all partitions in the rolling window. For example, a rolling window of 10 years partitioned by month would result in 120 partitions. /// public int NumberOfPartitionsFull { get; set; } /// /// Count of “hot partitions” where the data can change. For example, it may be necessary to refresh the most recent 3 months of data every day. This only applies to the most recent partitions. /// public int NumberOfPartitionsForIncrementalProcess { get; set; } /// /// If MaxDateIsNow = false, the maximum date that needs to be accounted for in the partitioned table. /// public DateTime MaxDate { get; set; } /// /// Lower boundary for date range covered by partitioning configuration. /// public DateTime LowerBoundary { get; } /// /// Upper boundary for date range covered by partitioning configuration. /// public DateTime UpperBoundary { get; } /// /// Assumes date keys are integers. If false assumes date type. /// public bool IntegerDateKey { get; set; } /// /// Template query used for partition source queries. /// public string TemplateSourceQuery { get; set; } /// /// Initialize partitioning configuration for partitioned table. Normally populated from a configuration database. /// /// Parent model. /// ID of the PartitioningConfiguration table. /// Partition granularity, which can be Yearly, Monthly or Daily. /// Count of all partitions in the rolling window. For example, a rolling window of 10 years partitioned by month would result in 120 partitions. /// Count of “hot partitions” where the data can change. For example, it may be necessary to refresh the most recent 3 months of data every day. This only applies to the most recent partitions. /// Assumes maximum date to be accounted for is today. /// The maximum date that needs to be accounted for in the partitioned table. Represents the upper boundary of the rolling window. /// Assumes date keys are integers. If false assumes date type. /// Template query used for partition source queries. public PartitioningConfiguration( int partitioningConfigurationID, Granularity granularity, int numberOfPartitionsFull, int numberOfPartitionsForIncrementalProcess, bool maxDateIsNow, DateTime maxDate, bool integerDateKey, string templateSourceQuery ) { PartitioningConfigurationID = partitioningConfigurationID; Granularity = granularity; NumberOfPartitionsFull = numberOfPartitionsFull; NumberOfPartitionsForIncrementalProcess = numberOfPartitionsForIncrementalProcess; if (maxDateIsNow) { MaxDate = DateTime.Today; } else { MaxDate = maxDate; } IntegerDateKey = integerDateKey; TemplateSourceQuery = templateSourceQuery; switch (granularity) { case Granularity.Daily: LowerBoundary = MaxDate.AddDays(-numberOfPartitionsFull + 1); UpperBoundary = MaxDate; break; case Granularity.Monthly: LowerBoundary = Convert.ToDateTime(MaxDate.AddMonths(-numberOfPartitionsFull + 1).ToString("yyyy-MMM-01")); UpperBoundary = Convert.ToDateTime(MaxDate.AddMonths(1).ToString("yyyy-MMM-01")).AddDays(-1); break; case Granularity.Yearly: LowerBoundary = Convert.ToDateTime(MaxDate.AddYears(-numberOfPartitionsFull + 1).ToString("yyyy-01-01")); UpperBoundary = Convert.ToDateTime(MaxDate.AddYears(1).ToString("yyyy-01-01")).AddDays(-1); break; default: break; } } public int CompareTo(PartitioningConfiguration other) => string.Compare(this.LowerBoundary.ToString("yyyy-MM-dd"), other.LowerBoundary.ToString("yyyy-MM-dd")); } /// /// Enumeration of supported partition granularities. /// public enum Granularity { Daily = 0, Monthly = 1, Yearly = 2 } }