예제 #1
0
            Grouping.GroupCollection Grouping.IGroupAlgorithm.Group(Column sourceColumn, ArrayRange indices, SortOrder order)
            {
                DupCollection coll = new DupCollection();

                if (order == SortOrder.None)
                {
                    order = SortOrder.Ascending;
                }
                coll.m_sortedIndex = sourceColumn.GetSortIndex(order, indices, false);
                System.Collections.Generic.List <DupGroup> groups = new System.Collections.Generic.List <DupGroup>();
                int iGroupFirst = 0;

                for (int i = 1, j = 0; i < coll.m_sortedIndex.Length; j = i++)
                {
                    if (sourceColumn.CompareRow(coll.m_sortedIndex[j], coll.m_sortedIndex[i]) != 0)
                    {
                        //create group;
                        Range range = Range.FirstToLast(iGroupFirst, i);
                        groups.Add(new DupGroup(range));
                        iGroupFirst = i;
                    }
                }
                Range rangeLast = Range.FirstToLast(iGroupFirst, coll.m_sortedIndex.Length);

                if (rangeLast.Length > 0)
                {
                    groups.Add(new DupGroup(rangeLast));
                }
                coll.m_Groups = groups.ToArray();

                return(coll);
            }
예제 #2
0
 public IComparable Merge(Column sourceColumn, ArrayRange sourceIndices)
 {
     return(GroupTyped(sourceColumn as ColumnTyped <DataT>, sourceIndices));
 }
예제 #3
0
 //returning indice array is always in ascending index order
 public abstract long[] GetMatchIndex(ArrayRange rowRange, Operation.Operator op, Operation.Expression exp, long expRowFirst, bool rowToRow);
예제 #4
0
 public Group(ArrayRange indices)
 {
     m_GroupIndice = indices;
 }
예제 #5
0
 protected override IComparable GroupTyped(ColumnTyped <DataT> sourceColumn, ArrayRange sourceIndices)
 {
     return(sourceColumn.GetRowValue(sourceIndices[0]));
 }
예제 #6
0
 protected override void GroupTyped(ColumnTyped <DataT> destColumn, long destRow, ColumnTyped <DataT> sourceColumn, ArrayRange sourceIndices)
 {
     destColumn.SetRowValue(destRow, (DataT)GroupTyped(sourceColumn, sourceIndices));
 }
 public override long[] GetMatchIndex(ArrayRange indices, Database.Operation.Matcher matcher)
 {
     return(GetMatchIndex(indices, matcher, new Database.Operation.ExpColumn <DataT>(this)));
 }
예제 #8
0
 protected abstract void GroupTyped(ColumnTyped <DataT> destColumn, long destRow, ColumnTyped <DataT> sourceColumn, ArrayRange sourceIndices);
예제 #9
0
 public abstract Database.Table CreateFilter(Database.Table tableIn, ArrayRange range);
예제 #10
0
 private static int RenderCore(
     HtmlRenderingContext context,
     ArrayRange <RenderTreeFrame> frames,
     int position)
 {
     ref var frame = ref frames.Array[position];
예제 #11
0
            /// <summary>
            /// returns undo <see cref="Query"/> corresponding to query performed on
            /// <paramref name="auditedTableName"/>, where <paramref name="auditTableRow"/> contains
            /// the data required to undo a single row in <paramref name="auditedTableName"/>,
            /// which was affected by the query.
            /// </summary>
            /// <param name="auditTableRow"></param>
            /// <param name="auditedTableName"></param>
            /// <param name="queryTypeIdToQueryType"></param>
            /// <returns>
            /// undo <see cref="Query"/> corresponding to query performed on
            /// <paramref name="auditedTableName"/>, where <paramref name="auditTableRow"/> contains
            /// the data required to undo a single row in <paramref name="auditedTableName"/>,
            /// which was affected by the query
            /// </returns>
            /// <exception cref="UnsupportedAuditQueryTypeException">
            /// thrown if <see cref="Query.eQueryType"/> specified in <paramref name="auditTableRow"/>
            /// is not supported for audit
            /// </exception>
            private static WriteQuery getUndoQuery(
                ResultSet.Row auditTableRow,
                string auditedTableName,
                Dictionary <long, Query.eQueryType> queryTypeIdToQueryType)
            {
                WriteQuery undoQuery;

                // type of query that was originally performed on audited table
                long queryTypeId = auditTableRow.GetColumnValue <long>(
                    AuditTableStructure.QUERY_ID_COLUMN_INDEX);

                Query.eQueryType queryType = queryTypeIdToQueryType[queryTypeId];

                // value of _id column of modified row in audit table
                long auditedTableRowId = auditTableRow.GetColumnValue <long>(
                    AuditTableStructure.AUDITED_TABLE_ROW_ID_COLUMN_INDEX);

                // get undo query based on query type
                if (queryType == Query.eQueryType.Insert)
                {
                    undoQuery = new DeleteQuery(
                        auditedTableName,
                        new BasicCondition(
                            new ValuedTableColumn(
                                DatabaseStructure.ID_COLUMN_NAME,
                                auditedTableName,
                                auditedTableRowId),
                            BasicCondition.eOperatorType.Equal
                            )
                        );
                }
                else if (queryType == Query.eQueryType.Update || queryType == Query.eQueryType.Delete)
                {
                    // ValuedColumn of _id column of modified row in audited table
                    ArrayRange <ValuedColumn> auditedTableRowIdArrayRange =
                        new ArrayRange <ValuedColumn>(
                            new ValuedColumn(DatabaseStructure.ID_COLUMN_NAME, auditedTableRowId)
                            );

                    // ValueColumn of columns other than _id of modified row in audited table
                    ArrayRange <ValuedColumn> auditedTableRowValuesArrayRange =
                        new ArrayRange <ValuedColumn>(
                            ValuedColumn.Parse(auditTableRow.ColumnNames, auditTableRow.ColumnValues),
                            AuditTableStructure.AUDITED_TABLE_DATA_COLUMNS_START_INDEX);

                    // unified ValuedColumn list for undo query
                    List <ValuedColumn> queryValuedColumns
                        = ListUtils.ListFromArrayRanges(
                              auditedTableRowIdArrayRange,
                              auditedTableRowValuesArrayRange);

                    if (queryType == Query.eQueryType.Update)
                    {
                        undoQuery = new UpdateQuery(
                            auditedTableName,
                            queryValuedColumns,
                            new BasicCondition(
                                new ValuedTableColumn(
                                    DatabaseStructure.ID_COLUMN_NAME,
                                    auditedTableName,
                                    auditedTableRowId),
                                BasicCondition.eOperatorType.Equal
                                )
                            );
                    }
                    else // queryType == Query.eQueryType.Delete
                    {
                        undoQuery = new InsertQuery(auditedTableName, queryValuedColumns);
                    }
                }
                else
                {
                    throw new UnsupportedAuditQueryTypeException(queryType);
                }

                return(undoQuery);
            }
예제 #12
0
 public long[] GetMatchIndex(long row, ArrayRange range)
 {
     return(m_Comparison.GetMatchIndex(row, range));
 }
예제 #13
0
 public abstract long[] GetMatchIndex(ArrayRange indices, Operation.Matcher matcher);
예제 #14
0
 LinkRequest IMergeAlgorithm.GetLink(Column sourceColumn, ArrayRange sourceIndices)
 {
     return(this.GetLink(sourceColumn, sourceIndices));
 }
예제 #15
0
            protected override long[] GetSortIndex(IComparer <DataT> comparer, ArrayRange indices, bool relativeIndex)
            {
                if (indices.array != null)
                {
                    return(base.GetSortIndex(comparer, indices, relativeIndex));
                }
                long count = indices.indexCount;

                DataT[] k = new DataT[count];

                long firstChunkSubIndex = indices.directIndexFirst % m_Cache.m_DataSet.ChunkSize;
                long lastChunkSubIndex  = indices.directIndexLast % m_Cache.m_DataSet.ChunkSize;

                long firstChunkIndex = indices.directIndexFirst / m_Cache.m_DataSet.ChunkSize;
                long lastChunkIndex  = indices.directIndexLast / m_Cache.m_DataSet.ChunkSize;

                long firstChunkLength = m_Cache.m_DataSet.ChunkSize - firstChunkSubIndex;
                long lastChunkLength  = lastChunkSubIndex;

                long firstFullChunk = firstChunkIndex + 1;
                long lastFullChunk  = lastChunkIndex;
                long fullChunkCount = lastFullChunk - firstFullChunk;

                if (firstChunkLength > m_Cache.m_DataSet.DataCount)
                {
                    firstChunkLength = m_Cache.m_DataSet.DataCount;
                    lastChunkLength  = 0;
                }
                //copy first chunk
                if (firstChunkLength > 0)
                {
                    var c = m_Cache.GetChunk(firstChunkIndex);
                    System.Array.Copy(c.m_Data, 0, k, 0, firstChunkLength);
                }

                //copy full chunks
                for (long i = 0; i < fullChunkCount; ++i)
                {
                    long chunkIndex    = i + firstFullChunk;
                    long chunkRowFirst = chunkIndex * m_Cache.m_DataSet.ChunkSize;
                    var  c             = m_Cache.GetChunk(chunkIndex);
                    System.Array.Copy(c.m_Data, 0, k, chunkRowFirst - indices.directIndexFirst, m_Cache.m_DataSet.ChunkSize);
                }

                //copy last chunk
                if (lastChunkLength > 0)
                {
                    long chunkRowFirst = lastChunkIndex * m_Cache.m_DataSet.ChunkSize;
                    var  c             = m_Cache.GetChunk(lastChunkIndex);
                    System.Array.Copy(c.m_Data, 0, k, chunkRowFirst - indices.directIndexFirst, lastChunkLength);
                }

                //create index array
                long[] index = new long[count];
                if (relativeIndex)
                {
                    for (long i = 0; i != count; ++i)
                    {
                        index[i] = i;
                        k[i]     = GetRowValue(i + indices.directIndexFirst);
                    }
                }
                else
                {
                    for (long i = 0; i != count; ++i)
                    {
                        index[i] = i + indices.directIndexFirst;
                        k[i]     = GetRowValue(i + indices.directIndexFirst);
                    }
                }


#if (PROFILER_DEBUG_TEST)
                //Test if data is good against a simple un-optimized query loop

                for (long i = 0; i != count; ++i)
                {
                    var  v = GetRowValue(i + indices.directIndexFirst);
                    long c = k[i].CompareTo(v);
                    UnityEngine.Debug.Assert(c == 0);
                }
#endif
                System.Array.Sort(k, index, comparer);
                return(index);
            }
예제 #16
0
 protected virtual LinkRequest GetLink(Column sourceColumn, ArrayRange sourceIndices)
 {
     return(null);
 }
예제 #17
0
            public override long[] GetMatchIndex(ArrayRange rowRange, Operation.Operator operation, Operation.Expression expression, long expressionRowFirst, bool rowToRow)
            {
                if (expression.type != type)
                {
                    return(base.GetMatchIndex(rowRange, operation, expression, expressionRowFirst, rowToRow));
                }
                using (Profiling.GetMarker(Profiling.MarkerId.ColumnMatchQueryInt).Auto())
                {
                    Update();
                    Operation.TypedExpression <int> typedExpression = expression as Operation.TypedExpression <int>;
                    long count          = rowRange.indexCount;
                    var  matchedIndices = new List <long>(128);
                    if (rowToRow)
                    {
                        for (long i = 0; i != count; ++i)
                        {
                            var lhs = m_Cache[rowRange[i]];
                            var rhs = typedExpression.GetValue(expressionRowFirst + i);
                            if (Operation.Operation.Match(operation, lhs, rhs))
                            {
                                matchedIndices.Add(rowRange[i]);
                            }
                        }
                    }
                    else
                    {
                        if (Operation.Operation.IsOperatorOneToMany(operation))
                        {
                            for (int i = 0; i != count; ++i)
                            {
                                var leftValue = m_Cache[rowRange[i]];
                                if (Operation.Operation.Match(operation, leftValue, typedExpression, expressionRowFirst))
                                {
                                    matchedIndices.Add(rowRange[i]);
                                }
                            }
                        }
                        else
                        {
                            var valueRight = typedExpression.GetValue(expressionRowFirst);
                            //Optimization for equal operation when querying on all data
                            if (rowRange.array == null && operation == Operation.Operator.Equal)
                            {
                                //use the sorted index to trim down invalid values
                                long[] sortedIndex     = GetSortIndexAsc();
                                int    lowerIndexIndex = LowerBoundIndex(sortedIndex, (int)rowRange.directIndexFirst, (int)rowRange.indexCount, valueRight);
                                int    upperIndexIndex = (int)rowRange.directIndexLast;
                                for (int i = lowerIndexIndex; i < upperIndexIndex; ++i)
                                {
                                    if (m_Cache[sortedIndex[i]] == valueRight)
                                    {
                                        matchedIndices.Add(sortedIndex[i]);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
#if PROFILER_DEBUG_TEST
                                {
                                    //Test to validate if optimization works
                                    int matchCount = 0;
                                    for (int i = 0; i != count; ++i)
                                    {
                                        var leftValue = m_Cache[rowRange[i]];
                                        if (Operation.Operation.Match(operation, leftValue, valueRight))
                                        {
                                            ++matchCount;
                                            if (matchedIndices.FindIndex(x => x == rowRange[i]) < 0)
                                            {
                                                UnityEngine.Debug.LogError("GetMatchIndex Optimization failure on index " + rowRange[i]);
                                            }
                                        }
                                    }
                                    if (matchCount != matchedIndices.Count)
                                    {
                                        UnityEngine.Debug.LogError("GetMatchIndex Optimization failure on match count " + matchCount + " != " + matchedIndices.Count);
                                    }
                                }
#endif
                            }
                            else
                            {
                                for (int i = 0; i != count; ++i)
                                {
                                    var leftValue = m_Cache[rowRange[i]];
                                    if (Operation.Operation.Match(operation, leftValue, valueRight))
                                    {
                                        matchedIndices.Add(rowRange[i]);
                                    }
                                }
                            }
                        }
                    }

                    var matchedIndicesArray = matchedIndices.ToArray();

#if MEMPROFILER_DEBUG_INFO
                    Algorithm.DebugLog("GetMatchIndex : indexCount " + rowRange.indexCount
                                       + " op:" + Operation.Operation.OperatorToString(operation)
                                       + " Exp():" + expression.GetValueString(expressionRowFirst)
                                       + " expRowFirst:" + expressionRowFirst
                                       + " Column:" + this.GetDebugString(rowRange[0])
                                       + " Expression:" + expression.GetDebugString(expressionRowFirst)
                                       + " Result Count:" + (matchedIndices != null ? matchedIndices.Length : 0));
#endif

                    return(matchedIndicesArray);
                }
            }
예제 #18
0
 protected abstract IComparable GroupTyped(ColumnTyped <DataT> sourceColumn, ArrayRange sourceIndices);
예제 #19
0
 public override System.Collections.Generic.IEnumerable <DataOutT> VisitRows(ArrayRange indices)
 {
     for (long i = 0; i != indices.indexCount; ++i)
     {
         yield return(m_Transformer(m_Cache[indices[i]]));
     }
 }
예제 #20
0
 protected override LinkRequest GetLink(Column sourceColumn, ArrayRange sourceIndices)
 {
     return(sourceColumn.GetRowLink(sourceIndices[0]));
 }
예제 #21
0
 public static IEnumerable <T> AsEnumerable <T>(this ArrayRange <T> source)
 {
     return(new ArraySegment <T>(source.Array, 0, source.Count));
 }
예제 #22
0
 protected override IComparable GroupTyped(ColumnTyped <DataT> sourceColumn, ArrayRange sourceIndices)
 {
     return(math.Make(sourceIndices.Count));
 }
예제 #23
0
 public abstract long[] GetSortIndex(SortOrder order, ArrayRange indices, bool relativeIndex);