18 using System.Collections.Generic;
21 namespace Deveel.Data.Sql.Tables {
26 tableItems =
new List<RawTableItem>();
31 this.tableItems.AddRange(tableItems);
39 return tableItems.Select(x => x.Table).Cast<
ITable>().ToArray();
43 return tableItems.Select(x => x.Rows).ToArray();
48 tableItems.CopyTo(list);
56 int colCount = tableItems.Count;
58 var merge1 = GetSortedItems();
66 if (merge1.Length != merge2.Length)
67 throw new InvalidOperationException(
"Incorrect format in table union");
71 for (
int i = 0; i < merge1.Length; ++i) {
73 size1 = merge1[i].Rows.Count;
75 if (size1 != merge1[i].Rows.Count)
76 throw new InvalidOperationException(
"Incorrect format in table union");
82 for (
int i = 0; i < merge2.Length; ++i) {
84 if (!merge2[i].
Table.TypeEquals(merge1[i].Table))
85 throw new InvalidOperationException(
"Incorrect format in table union");
88 size2 = merge2[i].Rows.Count;
90 if (size2 != merge2[i].Rows.Count)
91 throw new InvalidOperationException(
"Incorrect format in table union");
98 if (size1 == -1 || size2 == -1)
99 throw new InvalidOperationException(
"Incorrect format in table union");
104 var resultItems =
new List<RawTableItem>();
108 int mergeSize = size1 + size2;
112 for (
int i = 0; i < size1; ++i) {
113 var itemRows =
new int[colCount];
115 for (
int n = 0; n < colCount; ++n) {
116 itemRows[n] = merge1[n].Rows[i];
123 for (
int i = 0; i < size2; ++i) {
124 var itemRows =
new int[colCount];
126 for (
int n = 0; n < colCount; ++n) {
127 itemRows[n] = merge2[n].Rows[i];
140 for (
int i = 0; i < colCount; ++i) {
141 merge1[i].Rows.Clear();
145 for (
int n = 0; n < mergeSize; ++n) {
146 var current = elems[n];
151 if (previous == null || previous.
CompareTo(current) != 0) {
152 for (
int i = 0; i < colCount; ++i) {
153 merge1[i].Rows.Add(current.RowValues[i]);
159 for (
int i = 0; i < colCount; ++i) {
160 resultItems.Add(merge1[i]);
169 if (tableItems.Count == 0)
175 var elen = tableItems[0];
176 int len = elen.Rows.Count;
183 int width = tableItems.Count;
188 tableItems.CopyTo(rdup);
193 for (
int i = 0; i < len; ++i) {
194 var itemRows =
new int[width];
195 for (
int n = 0; n < width; ++n) {
196 itemRows[n] = rdup[n].
Rows[i];
208 var resultTables =
new List<RawTableItem>();
217 for (
int i = 0; i < width; ++i) {
218 items[i].Rows.Clear();
222 for (
int n = 0; n < len; ++n) {
223 var current = elems[n];
228 if (previous == null || previous.
CompareTo(current) != 0) {
229 for (
int i = 0; i < width; ++i) {
230 items[i].Rows.Add(current.RowValues[i]);
236 for (
int i = 0; i < width; ++i) {
237 resultTables.Add(items[i]);
248 : this(table, new List<int>()) {
253 Rows =
new List<int>(rows);
258 public IList<int> Rows {
get;
private set; }
261 return Table.GetHashCode() - other.
Table.GetHashCode();
274 public int[] RowValues {
get;
private set; }
277 int size = RowValues.Length;
278 for (
int i = 0; i < size; ++i) {
279 int v1 = RowValues[i];
Defines the contract to access the data contained into a table of a database.
readonly List< RawTableItem > tableItems
RawTableInfo(IEnumerable< RawTableItem > tableItems)
RawTableItem(IRootTable table, IList< int > rows)
int CompareTo(RawTableItem other)
RawTableItem[] GetSortedItems()
RawTableItem(IRootTable table)
int CompareTo(RawRowItem other)
RawTableInfo Union(RawTableInfo info)
void Add(IRootTable table, IList< int > rowSet)
RawTableInfo RemoveDuplicates()
Interface that is implemented by all root tables.