using System;
using System.Collections.Generic;
namespace BismNormalizer.TabularCompare
{
///
/// Keeps track of tables for processing, and dynamically increments the rows processed in each partition.
///
public class ProcessingTable : IComparable
{
private string _name;
private string _id;
private List _partitions = new List();
///
/// Name of the table being processed.
///
public string Name => _name;
///
/// Id of the table being processed. Can be different for tabular models with multidimensional metadata.
///
public string Id => _id;
///
/// Collection of PartitionRowCounter objects.
///
public List Partitions => _partitions;
///
/// Initializes a new instance of the PartitionRowCounter class using a name and id.
///
public ProcessingTable(string name, string id)
{
_name = name;
_id = id;
}
///
/// Get the total row count for all partitions associated with the table.
///
/// Total row count.
public long GetRowCount()
{
long rowCount = 0;
foreach (PartitionRowCounter partition in _partitions)
{
rowCount += partition.RowCount;
}
return rowCount;
}
///
/// Find partition based on its Id.
///
///
/// PartitionRowCounter object. Null if not found.
public PartitionRowCounter FindPartition(string id)
{
foreach (PartitionRowCounter partition in _partitions)
{
if (partition.Id == id)
{
return partition;
}
}
return null;
}
///
/// Verifies if table contains a partition with the specified Id.
///
///
/// A Boolean specifying whether the partition is contained by the table.
public bool ContainsPartition(string id)
{
foreach (PartitionRowCounter partition in _partitions)
{
if (partition.Id == id)
{
return true;
}
}
return false;
}
public int CompareTo(ProcessingTable other) => string.Compare(this.Name, other.Name);
}
}