public GroupedTable(Database.Table table, ArrayRange range, int colToGroupFirst, int colToGroupLast, int[] colGroupOrder, SortOrder[] sortOrder) : base(table.Schema) { m_table = table; if (m_table is ExpandTable) { m_expandTable = (ExpandTable)m_table; } m_Meta = m_table.GetMetaData(); m_GroupedColumnFirst = colToGroupFirst; m_GroupedColumnLast = colToGroupLast; m_ColumnOrder = colGroupOrder; m_SortOrder = sortOrder; int sourceGroupedColumnIndex = m_ColumnOrder[colToGroupFirst]; var col = m_table.GetColumnByIndex(sourceGroupedColumnIndex); var metaCol = m_Meta.GetColumnByIndex(sourceGroupedColumnIndex); if (metaCol.DefaultGroupAlgorithm != null) { m_GroupCollection = metaCol.DefaultGroupAlgorithm.Group(col, range, m_SortOrder[colToGroupFirst]); } else { throw new Exception("Trying to group a column without grouping algorithm. Column '" + metaCol.Name + "' from table '" + m_table.GetName() + "'"); } InitializeFromGroupCollection(col, sourceGroupedColumnIndex); }
// colToGroup is an index from aNewColumnOrder. public GroupedTable(Database.Table table, ArrayRange range, int colToGroup, SortOrder sortOrder, FnCreateGroupTable subTable) : base(table.Schema) { m_table = table; if (m_table is ExpandTable) { m_expandTable = (ExpandTable)m_table; } m_Meta = m_table.GetMetaData(); m_GroupedColumnFirst = 0; m_GroupedColumnLast = 0; m_ColumnOrder = new int[] { colToGroup };// colGroupOrder; m_SortOrder = new SortOrder[1] { sortOrder }; m_createGroupTable = subTable; var col = m_table.GetColumnByIndex(colToGroup); var metaCol = m_Meta.GetColumnByIndex(colToGroup); if (metaCol.DefaultGroupAlgorithm != null) { m_GroupCollection = metaCol.DefaultGroupAlgorithm.Group(col, range, sortOrder); } else { throw new Exception("Trying to group a column without grouping algorithm. Column '" + metaCol.Name + "' from table '" + m_table.GetName() + "'"); } InitializeFromGroupCollection(col, colToGroup); }
public static Value Expand(IList <Value> parameters) { var validate = Expression.ValidateHelper("Expand", parameters, 2, new List <ValueType>() { ValueType.Object, ValueType.Object }); if (validate != null) { return(validate); } if (!(parameters[0].Object is SimpleTable)) { return(Value.CreateErrorValue("Expand() parameter #1 is not a table")); } else if (!(parameters[1].Object is SimpleTable)) { return(Value.CreateErrorValue("Expand() parameter #2 is not a table")); } var sourceTable = parameters[0].Object as SimpleTable; var mapTable = parameters[1].Object as SimpleTable; try { var result = ExpandTable.Execute(sourceTable, mapTable); if (result.HasError) { return(Value.CreateErrorValue(result.ErrorMessage, result.Exception)); } return(new Value(result.Result)); } catch (System.Exception e) { return(Value.CreateErrorValue("Expand() unable to expand table: " + e.ToString(), e)); } }
/// <summary> /// Create a new entry in the expansion table that contains the orderings /// for the given characers. If anOrder is valid, it is added to the /// beginning of the expanded list of orders. /// </summary> private int AddExpansion(int anOrder, String expandChars) { if (ExpandTable == null) { ExpandTable = new List <>(INITIALTABLESIZE); } // If anOrder is valid, we want to add it at the beginning of the list int offset = (anOrder == RBCollationTables.UNMAPPED) ? 0 : 1; int[] valueList = new int[expandChars.Length() + offset]; if (offset == 1) { valueList[0] = anOrder; } int j = offset; for (int i = 0; i < expandChars.Length(); i++) { char ch0 = expandChars.CharAt(i); char ch1; int ch; if (char.IsHighSurrogate(ch0)) { if (++i == expandChars.Length() || !char.IsLowSurrogate(ch1 = expandChars.CharAt(i))) { //ether we are missing the low surrogate or the next char //is not a legal low surrogate, so stop loop break; } ch = Character.ToCodePoint(ch0, ch1); } else { ch = ch0; } int mapValue = GetCharOrder(ch); if (mapValue != RBCollationTables.UNMAPPED) { valueList[j++] = mapValue; } else { // can't find it in the table, will be filled in by commit(). valueList[j++] = CHARINDEX + ch; } } if (j < valueList.Length) { //we had at least one supplementary character, the size of valueList //is bigger than it really needs... int[] tmpBuf = new int[j]; while (--j >= 0) { tmpBuf[j] = valueList[j]; } valueList = tmpBuf; } // Add the expanding char list into the expansion table. int tableIndex = RBCollationTables.EXPANDCHARINDEX + ExpandTable.Count; ExpandTable.Add(valueList); return(tableIndex); }