public ITable GetGroupValue(long rowid) { long n = (rowid * 2); // Get the group position and size in the index long groupPos = childGroupsIndex[n]; long groupSize = childGroupsIndex[n + 1]; // Create an interator over this subset of the filter index SubsetRowCursor subset = new SubsetRowCursor(BaseTable.GetRowCursor(), groupPos, groupSize); // Return the table subset SubsetTable groupTable = new SubsetTable(BaseTable, subset); // The subset retains the order of the child groupTable.SetOrderCompositeIsChild(); // Return the group return groupTable; }
internal ITable FilterByScan(ITable table, Expression op) { // Default is to match table, ITable resultTable = table; long rowCount = table.RowCount; // If the table is not empty, if (rowCount > 0) { // Put the table on the stack, PushTable(table); // The working set, IIndex<RowId> workingSet = transaction.CreateTemporaryIndex<RowId>(rowCount); // TODO: Common expression scans should be optimized // Default scan (works for everything) // Fetch the table's row iterator IRowCursor cursor = table.GetRowCursor(); // Wrap in a forward prefetch iterator cursor = new PrefetchRowCursor(cursor, table); // True if all matched bool allMatched = true; // For each value, while (cursor.MoveNext()) { // Fetch the next row_id from the iterator RowId rowid = cursor.Current; // Set the top of stack table row_id UpdateTableRow(rowid); // Execute the expression, ITable expResult = DoExecute(op); // If it's true, add the row_id to the working set if (BooleanResult(expResult)) { // Note, we preserve the ordering of the table being filtered workingSet.Add(rowid); } else { // Wasn't a true result, so we didn't all match. allMatched = false; } } // If we matched nothing if (workingSet.Count == 0) { // Return a subset of the given table that is empty SubsetTable subsetTable = new SubsetTable(table); // We inherit the order composite description from the child. subsetTable.SetOrderCompositeIsChild(); resultTable = subsetTable; } // If we matched something else { // If all matched we return the table if (allMatched) { // Clear the working set and set the result table workingSet.Clear(); resultTable = table; } else { // Something in working set, and we didn't match everything, IRowCursor setCursor = new DefaultRowCursor(workingSet.GetCursor()); SubsetTable subsetTable = new SubsetTable(table, setCursor); // We inherit the order composite description from the child. subsetTable.SetOrderCompositeIsChild(); resultTable = subsetTable; } } // Pop the current table from the stack PopTable(); } return resultTable; }