DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Sql.Tables.RawTableInfo Class Reference

Classes

class  RawRowItem
 
class  RawTableItem
 

Public Member Functions

 RawTableInfo ()
 
void Add (IRootTable table, IList< int > rowSet)
 
ITable[] GetTables ()
 
IList< int >[] GetRows ()
 
RawTableInfo Union (RawTableInfo info)
 
RawTableInfo RemoveDuplicates ()
 

Private Member Functions

 RawTableInfo (IEnumerable< RawTableItem > tableItems)
 
RawTableItem[] GetSortedItems ()
 

Private Attributes

readonly List< RawTableItemtableItems
 

Detailed Description

Definition at line 22 of file RawTableInfo.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Tables.RawTableInfo.RawTableInfo ( )
inline

Definition at line 25 of file RawTableInfo.cs.

25  {
26  tableItems = new List<RawTableItem>();
27  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
Deveel.Data.Sql.Tables.RawTableInfo.RawTableInfo ( IEnumerable< RawTableItem tableItems)
inlineprivate

Definition at line 29 of file RawTableInfo.cs.

30  : this() {
31  this.tableItems.AddRange(tableItems);
32  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23

Member Function Documentation

void Deveel.Data.Sql.Tables.RawTableInfo.Add ( IRootTable  table,
IList< int >  rowSet 
)
inline

Definition at line 34 of file RawTableInfo.cs.

34  {
35  tableItems.Add(new RawTableItem(table, rowSet));
36  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
IList<int> [] Deveel.Data.Sql.Tables.RawTableInfo.GetRows ( )
inline

Definition at line 42 of file RawTableInfo.cs.

42  {
43  return tableItems.Select(x => x.Rows).ToArray();
44  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
RawTableItem [] Deveel.Data.Sql.Tables.RawTableInfo.GetSortedItems ( )
inlineprivate

Definition at line 46 of file RawTableInfo.cs.

46  {
47  var list = new RawTableItem[tableItems.Count];
48  tableItems.CopyTo(list);
49  Array.Sort(list);
50  return list;
51  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
ITable [] Deveel.Data.Sql.Tables.RawTableInfo.GetTables ( )
inline

Definition at line 38 of file RawTableInfo.cs.

38  {
39  return tableItems.Select(x => x.Table).Cast<ITable>().ToArray();
40  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
RawTableInfo Deveel.Data.Sql.Tables.RawTableInfo.RemoveDuplicates ( )
inline

Definition at line 166 of file RawTableInfo.cs.

166  {
167  // If no tables in duplicate then return
168 
169  if (tableItems.Count == 0)
170  return new RawTableInfo();
171 
172  // Get the length of the first row set in the first table. We assume that
173  // the row set length is identical across each table in the Vector.
174 
175  var elen = tableItems[0];
176  int len = elen.Rows.Count;
177  if (len == 0)
178  return new RawTableInfo(tableItems.ToArray());
179 
180  // Create a new row element to sort.
181 
182  var elems = new RawRowItem[len];
183  int width = tableItems.Count;
184 
185  // Create an array of RawTableElement so we can quickly access the data
186 
187  var rdup = new RawTableItem[width];
188  tableItems.CopyTo(rdup);
189 
190  // Run through the data building up a new RawTableElement[] array with
191  // the information in every raw span.
192 
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];
197  }
198  elems[i] = new RawRowItem(itemRows);
199  }
200 
201  // Now 'elems' it an array of individual RawRowItem objects which
202  // represent each individual row in the table.
203 
204  // Now sort and remove duplicates to make up a new set.
205 
206  Array.Sort(elems);
207 
208  var resultTables = new List<RawTableItem>();
209 
210  // Make a new set of RawTableElement[] objects
211 
212  var items = rdup;
213 
214  // Set up the 'raw_info' vector with the new RawTableElement[] removing
215  // any duplicate rows.
216 
217  for (int i = 0; i < width; ++i) {
218  items[i].Rows.Clear();
219  }
220 
221  RawRowItem previous = null;
222  for (int n = 0; n < len; ++n) {
223  var current = elems[n];
224 
225  // Check that the current element in the set is not a duplicate of the
226  // previous.
227 
228  if (previous == null || previous.CompareTo(current) != 0) {
229  for (int i = 0; i < width; ++i) {
230  items[i].Rows.Add(current.RowValues[i]);
231  }
232  previous = current;
233  }
234  }
235 
236  for (int i = 0; i < width; ++i) {
237  resultTables.Add(items[i]);
238  }
239 
240  return new RawTableInfo(resultTables.ToArray());
241  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
RawTableInfo Deveel.Data.Sql.Tables.RawTableInfo.Union ( RawTableInfo  info)
inline

Definition at line 53 of file RawTableInfo.cs.

53  {
54  // Number of Table 'columns'
55 
56  int colCount = tableItems.Count;
57 
58  var merge1 = GetSortedItems();
59  var merge2 = info.GetSortedItems();
60 
61  int size1 = -1;
62  int size2 = -1;
63 
64  // First check number of tables in each merge is correct.
65 
66  if (merge1.Length != merge2.Length)
67  throw new InvalidOperationException("Incorrect format in table union");
68 
69  // Check each table in the merge1 set has identical length row_sets
70 
71  for (int i = 0; i < merge1.Length; ++i) {
72  if (size1 == -1) {
73  size1 = merge1[i].Rows.Count;
74  } else {
75  if (size1 != merge1[i].Rows.Count)
76  throw new InvalidOperationException("Incorrect format in table union");
77  }
78  }
79 
80  // Check each table in the merge2 set has identical length row_sets
81 
82  for (int i = 0; i < merge2.Length; ++i) {
83  // Check the tables in merge2 are identical to the tables in merge1
84  if (!merge2[i].Table.TypeEquals(merge1[i].Table))
85  throw new InvalidOperationException("Incorrect format in table union");
86 
87  if (size2 == -1) {
88  size2 = merge2[i].Rows.Count;
89  } else {
90  if (size2 != merge2[i].Rows.Count)
91  throw new InvalidOperationException("Incorrect format in table union");
92  }
93  }
94 
95  // If size1 or size2 are -1 then we have a corrupt table. (It will be
96  // 0 for an empty table).
97 
98  if (size1 == -1 || size2 == -1)
99  throw new InvalidOperationException("Incorrect format in table union");
100 
101  // We don't need information in 'raw_info' vector anymore so clear it.
102  // This may help garbage collection.
103 
104  var resultItems = new List<RawTableItem>();
105 
106  // Merge the two together into a new list of RawRowElement[]
107 
108  int mergeSize = size1 + size2;
109  var elems = new RawRowItem[mergeSize];
110  int elemsIndex = 0;
111 
112  for (int i = 0; i < size1; ++i) {
113  var itemRows = new int[colCount];
114 
115  for (int n = 0; n < colCount; ++n) {
116  itemRows[n] = merge1[n].Rows[i];
117  }
118 
119  elems[elemsIndex] = new RawRowItem(itemRows);
120  ++elemsIndex;
121  }
122 
123  for (int i = 0; i < size2; ++i) {
124  var itemRows = new int[colCount];
125 
126  for (int n = 0; n < colCount; ++n) {
127  itemRows[n] = merge2[n].Rows[i];
128  }
129 
130  elems[elemsIndex] = new RawRowItem(itemRows);
131  ++elemsIndex;
132  }
133 
134  // Now sort the row elements into order.
135 
136  Array.Sort(elems);
137 
138  // Remove any duplicate rows.
139 
140  for (int i = 0; i < colCount; ++i) {
141  merge1[i].Rows.Clear();
142  }
143 
144  RawRowItem previous = null;
145  for (int n = 0; n < mergeSize; ++n) {
146  var current = elems[n];
147 
148  // Check that the current element in the set is not a duplicate of the
149  // previous.
150 
151  if (previous == null || previous.CompareTo(current) != 0) {
152  for (int i = 0; i < colCount; ++i) {
153  merge1[i].Rows.Add(current.RowValues[i]);
154  }
155  previous = current;
156  }
157  }
158 
159  for (int i = 0; i < colCount; ++i) {
160  resultItems.Add(merge1[i]);
161  }
162 
163  return new RawTableInfo(resultItems.ToArray());
164  }
readonly List< RawTableItem > tableItems
Definition: RawTableInfo.cs:23
A TABLE object in a database.

Member Data Documentation

readonly List<RawTableItem> Deveel.Data.Sql.Tables.RawTableInfo.tableItems
private

Definition at line 23 of file RawTableInfo.cs.


The documentation for this class was generated from the following file: