Ejemplo n.º 1
0
        protected override IRow InternalGetKey()
        {
            IRow key = _sourceTable.GetKey();

            try
            {
                if (_keyRowType == null)
                {
                    _keyRowType = new Schema.RowType();
                    for (int index = 0; index < key.DataType.Columns.Count; index++)
                    {
                        _keyRowType.Columns.Add(DataType.Columns[_sourceTable.DataType.Columns.IndexOfName(key.DataType.Columns[index].Name)].Copy());
                    }
                }
                Row row = new Row(Manager, _keyRowType);
                for (int index = 0; index < key.DataType.Columns.Count; index++)
                {
                    if (key.HasValue(index))
                    {
                        row[index] = key[index];
                    }
                }
                return(row);
            }
            finally
            {
                key.Dispose();
            }
        }
Ejemplo n.º 2
0
        public TableBufferIndex
        (
            ServerProcess AProcess,
            Schema.Order AKey,
            Schema.RowType AKeyRowType,
            Schema.RowType ADataRowType,
            bool AIsClustered,
            int AFanout,
            int ACapacity
        ) : base(AFanout, ACapacity, AKeyRowType.StaticByteSize, ADataRowType.StaticByteSize)
        {
            FKey = AKey;
                        #if DEBUG
            for (int LIndex = 0; LIndex < FKey.Columns.Count; LIndex++)
            {
                if (FKey.Columns[LIndex].Sort == null)
                {
                    throw new Exception("Sort is null");
                }
            }
                        #endif

            FKeyRowType  = AKeyRowType;
            FDataRowType = ADataRowType;
            FIsClustered = AIsClustered;
            Create(AProcess);
        }
Ejemplo n.º 3
0
 private Schema.RowType GetBookmarkRowType()
 {
     if (FBookmarkRowType == null)
     {
         FBookmarkRowType = new Schema.RowType();
         FBookmarkRowType.Columns.Add(new Schema.Column(String.Empty, Schema.DataType.SystemGuid));
     }
     return(FBookmarkRowType);
 }
Ejemplo n.º 4
0
 private bool GetIsIndexAffected(Schema.RowType ARowType, Row ARow)
 {
     foreach (Schema.Column LColumn in ARowType.Columns)
     {
         if (ARow.DataType.Columns.Contains(LColumn.Name))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        protected Row BuildSourceKey(IRow key)
        {
            Schema.RowType rowType = new Schema.RowType();
            for (int index = 0; index < key.DataType.Columns.Count; index++)
            {
                rowType.Columns.Add(_sourceTable.DataType.Columns[DataType.Columns.IndexOfName(key.DataType.Columns[index].Name)].Copy());
            }
            Row localKey = new Row(Manager, rowType);

            for (int index = 0; index < key.DataType.Columns.Count; index++)
            {
                if (key.HasValue(index))
                {
                    localKey[index] = key[index];
                }
            }
            return(localKey);
        }
Ejemplo n.º 6
0
        private Row GetIndexData(ServerProcess AProcess, Schema.RowType ARowType, Row[] ASourceRows)
        {
            Row LRow = AProcess.RowManager.RequestRow(AProcess, ARowType);

            try
            {
                int  LColumnIndex;
                bool LFound;
                for (int LIndex = 0; LIndex < LRow.DataType.Columns.Count; LIndex++)
                {
                    LFound = false;
                    foreach (Row LSourceRow in ASourceRows)
                    {
                        LColumnIndex = LSourceRow.DataType.Columns.IndexOf(LRow.DataType.Columns[LIndex].Name);
                        if (LColumnIndex >= 0)
                        {
                            if (LSourceRow.HasValue(LColumnIndex))
                            {
                                LRow[LIndex] = LSourceRow[LColumnIndex];
                            }
                            else
                            {
                                LRow.ClearValue(LIndex);
                            }
                            LFound = true;
                            break;
                        }
                    }
                    if (LFound)
                    {
                        continue;
                    }

                    throw new RuntimeException(RuntimeException.Codes.UnableToConstructIndexKey);
                }
                return(LRow);
            }
            catch
            {
                AProcess.RowManager.ReleaseRow(LRow);
                throw;
            }
        }
Ejemplo n.º 7
0
        public override void JoinApplicationTransaction(Program program, IRow row)
        {
            Schema.RowType rowType = new Schema.RowType();
            foreach (Schema.Column column in row.DataType.Columns)
            {
                rowType.Columns.Add(SourceNode.DataType.Columns[DataType.Columns.IndexOfName(column.Name)].Copy());
            }

            Row localRow = new Row(program.ValueManager, rowType, (NativeRow)row.AsNative);

            try
            {
                SourceNode.JoinApplicationTransaction(program, localRow);
            }
            finally
            {
                localRow.Dispose();
            }
        }
Ejemplo n.º 8
0
        public IRowType CreateRowType(string prefix, bool includeColumns)
        {
            if (IsGeneric)
            {
                Schema.RowType rowType = new RowType();
                rowType.IsGeneric = true;
                return(rowType);
            }

            if ((prefix == null) || (prefix == String.Empty))
            {
                if (includeColumns)
                {
                    return(new RowType(Columns));
                }
                return(new RowType());
            }

            return(new RowType(Columns, prefix));
        }
Ejemplo n.º 9
0
        public static DataParams SerializableParamDataToDataParams(Alphora.Dataphor.DAE.IServerProcess process, SerializableParamData paramsValue)
        {
            if ((paramsValue.Params != null) && (paramsValue.Params.Length > 0))
            {
                DataParams     localParamsValue = new DataParams();
                Schema.RowType rowType          = new Schema.RowType();
                for (int index = 0; index < paramsValue.Params.Length; index++)
                {
                    rowType.Columns.Add(new Schema.Column(paramsValue.Params[index].Name, (Schema.ScalarType)process.Session.Server.Catalog[paramsValue.Params[index].TypeName]));
                }

                Data.Row row = new Data.Row(process.ValueManager, rowType);
                try
                {
                    row.ValuesOwned = false;
                    row.AsPhysical  = paramsValue.Data.Data;

                    for (int index = 0; index < paramsValue.Params.Length; index++)
                    {
                        if (row.HasValue(index))
                        {
                            localParamsValue.Add(new DataParam(row.DataType.Columns[index].Name, row.DataType.Columns[index].DataType, SerializableModifierToModifier(paramsValue.Params[index].Modifier), Data.DataValue.CopyValue(process.ValueManager, row[index])));
                        }
                        else
                        {
                            localParamsValue.Add(new DataParam(row.DataType.Columns[index].Name, row.DataType.Columns[index].DataType, SerializableModifierToModifier(paramsValue.Params[index].Modifier), null));
                        }
                    }

                    return(localParamsValue);
                }
                finally
                {
                    row.Dispose();
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
        public static SerializableParamData DataParamsToSerializableParamData(Alphora.Dataphor.DAE.IServerProcess process, DataParams paramsValue)
        {
            int paramCount = paramsValue != null ? paramsValue.Count : 0;

            if (paramCount > 0)
            {
                Schema.RowType rowType = new Schema.RowType();
                if (paramsValue != null)
                {
                    foreach (DataParam param in paramsValue)
                    {
                        rowType.Columns.Add(new Schema.Column(param.Name, param.DataType));
                    }
                }
                using (Data.Row row = new Data.Row(process.ValueManager, rowType))
                {
                    row.ValuesOwned = false;
                    SerializableParamData localParamsValue = new SerializableParamData();
                    localParamsValue.Params = new SerializableParam[paramCount];
                    for (int index = 0; index < paramCount; index++)
                    {
                        localParamsValue.Params[index].Name     = paramsValue[index].Name;
                        localParamsValue.Params[index].TypeName = paramsValue[index].DataType.Name;
                        localParamsValue.Params[index].Modifier = ModifierToSerializableModifier(paramsValue[index].Modifier);
                        if (paramsValue[index].Value != null)
                        {
                            row[index] = paramsValue[index].Value;
                        }
                    }
                    // TODO: Not able to adapt this without adding a common StreamManager public property
                    //EnsureOverflowReleased(AProcess, LRow);
                    localParamsValue.Data.Data = row.AsPhysical;
                    return(localParamsValue);
                }
            }
            else                // optimization
            {
                return(new SerializableParamData());
            }
        }
Ejemplo n.º 11
0
        public override void JoinApplicationTransaction(Program program, IRow row)
        {
            Schema.RowType rowType = new Schema.RowType();

            foreach (Schema.Column column in row.DataType.Columns)
            {
                rowType.Columns.Add(column.Copy());
            }
            foreach (Schema.Column column in SourceNode.DataType.Columns)
            {
                if (!DataType.Columns.ContainsName(column.Name))
                {
                    rowType.Columns.Add(column.Copy());
                }
            }
            Row localRow = new Row(program.ValueManager, rowType);

            try
            {
                row.CopyTo(localRow);

                // Get the SourceNode select set for this row, and join on each result
                foreach (var sourceRow in SourceNode.SelectAll(program, localRow))
                {
                    try
                    {
                        base.JoinApplicationTransaction(program, sourceRow);
                    }
                    finally
                    {
                        sourceRow.Dispose();
                    }
                }
            }
            finally
            {
                localRow.Dispose();
            }
        }
Ejemplo n.º 12
0
        public override void JoinApplicationTransaction(Program program, IRow row)
        {
            // Exclude any columns from AKey which were included by this node
            Schema.RowType rowType = new Schema.RowType();
            foreach (Schema.Column column in row.DataType.Columns)
            {
                if (!((IList)_redefineColumnOffsets).Contains(_tableVar.DataType.Columns.IndexOfName(column.Name)))
                {
                    rowType.Columns.Add(column.Copy());
                }
            }

            Row localRow = new Row(program.ValueManager, rowType);

            try
            {
                row.CopyTo(localRow);
                SourceNode.JoinApplicationTransaction(program, localRow);
            }
            finally
            {
                localRow.Dispose();
            }
        }
Ejemplo n.º 13
0
        public override void DetermineDataType(Plan plan)
        {
            DetermineModifiers(plan);
            _dataType = plan.DataTypes.SystemBoolean;

            if (!Nodes[0].DataType.IsGeneric && !Nodes[1].DataType.IsGeneric)             // Generic row comparison must be done at run-time
            {
                if (Nodes[0].DataType.Is(Nodes[1].DataType))
                {
                    Nodes[0] = Compiler.Upcast(plan, Nodes[0], Nodes[1].DataType);
                }
                else if (Nodes[1].DataType.Is(Nodes[0].DataType))
                {
                    Nodes[1] = Compiler.Upcast(plan, Nodes[1], Nodes[0].DataType);
                }
                else
                {
                    ConversionContext context = Compiler.FindConversionPath(plan, Nodes[0].DataType, Nodes[1].DataType);
                    if (context.CanConvert)
                    {
                        Nodes[0] = Compiler.Upcast(plan, Compiler.ConvertNode(plan, Nodes[0], context), Nodes[1].DataType);
                    }
                    else
                    {
                        context = Compiler.FindConversionPath(plan, Nodes[1].DataType, Nodes[0].DataType);
                        Compiler.CheckConversionContext(plan, context);
                        Nodes[1] = Compiler.Upcast(plan, Compiler.ConvertNode(plan, Nodes[1], context), Nodes[0].DataType);
                    }
                }

                plan.Symbols.PushWindow(0);
                try
                {
                    plan.EnterRowContext();
                    try
                    {
                                                #if USENAMEDROWVARIABLES
                        plan.Symbols.Push(new Symbol(Keywords.Left, (Schema.RowType)Nodes[0].DataType));
                                                #else
                        Schema.RowType leftRowType = new Schema.RowType(((Schema.RowType)Nodes[0].DataType).Columns, Keywords.Left);
                        APlan.Symbols.Push(new Symbol(String.Empty, leftRowType));
                                                #endif
                        try
                        {
                                                        #if USENAMEDROWVARIABLES
                            plan.Symbols.Push(new Symbol(Keywords.Right, (Schema.RowType)Nodes[1].DataType));
                                                        #else
                            Schema.RowType rightRowType = new Schema.RowType(((Schema.RowType)Nodes[1].DataType).Columns, Keywords.Right);
                            APlan.Symbols.Push(new Symbol(String.Empty, rightRowType));
                                                        #endif
                            try
                            {
                                _comparisonNode =
                                                                        #if USENAMEDROWVARIABLES
                                    Compiler.CompileExpression(plan, Compiler.BuildRowEqualExpression(plan, Keywords.Left, Keywords.Right, ((Schema.RowType)Nodes[0].DataType).Columns, ((Schema.RowType)Nodes[1].DataType).Columns));
                                                                        #else
                                    Compiler.CompileExpression(APlan, Compiler.BuildRowEqualExpression(APlan, leftRowType.Columns, rightRowType.Columns));
                                                                        #endif
                            }
                            finally
                            {
                                plan.Symbols.Pop();
                            }
                        }
                        finally
                        {
                            plan.Symbols.Pop();
                        }
                    }
                    finally
                    {
                        plan.ExitRowContext();
                    }
                }
                finally
                {
                    plan.Symbols.PopWindow();
                }
            }
        }
Ejemplo n.º 14
0
        // AggregateNode
        //		Nodes[0] = Project over {by Columns}
        //			Nodes[0] = ASourceNode
        //		Nodes[1..AggregateExpression.Count] = PlanNode - class determined by lookup from the server catalog
        //			Nodes[0] = Project over {aggregate columns for this expression}
        //				Nodes[0] = Restrict
        //					Nodes[0] = ASourceNode
        //					Nodes[1] = Condition over the first key in the project of the aggregate source (AggregateNode.Nodes[0]);
        public override void DetermineDataType(Plan plan)
        {
            DetermineModifiers(plan);
            _dataType       = new Schema.TableType();
            _tableVar       = new Schema.ResultTableVar(this);
            _tableVar.Owner = plan.User;
            _tableVar.InheritMetaData(SourceTableVar.MetaData);

            _sourceNode = SourceNode;

            // TODO: Aggregation source is required to be deterministic because it is long handed, we should do something that allows non-deterministic sources for aggregation
            if (!_sourceNode.IsRepeatable)
            {
                throw new CompilerException(CompilerException.Codes.InvalidAggregationSource, plan.CurrentStatement());
            }

            if (_columns.Count > 0)
            {
                ProjectNode projectNode = (ProjectNode)Compiler.EmitProjectNode(plan, SourceNode, _columns, true);
                Nodes[0] = projectNode;
            }
            else
            {
                Schema.TableType  tableType = new Schema.TableType();
                TableSelectorNode node      = new TableSelectorNode(tableType);
                node.TableVar.Keys.Add(new Schema.Key());
                node.Nodes.Add(new RowSelectorNode(new Schema.RowType()));
                node.DetermineCharacteristics(plan);
                Nodes[0] = node;
            }

            CopyTableVarColumns(SourceTableVar.Columns);
            CopyKeys(SourceTableVar.Keys);
            CopyOrders(SourceTableVar.Orders);
            if (SourceNode.Order != null)
            {
                Order = CopyOrder(SourceNode.Order);
            }

                        #if UseReferenceDerivation
                        #if UseElaborable
            if (plan.CursorContext.CursorCapabilities.HasFlag(CursorCapability.Elaborable))
                        #endif
            CopyReferences(plan, SourceTableVar);
                        #endif

            _aggregateColumnOffset = TableVar.Columns.Count;

            Schema.Key compareKey = Compiler.FindClusteringKey(plan, TableVar);

            // Add the computed columns
            plan.EnterRowContext();
            try
            {
                plan.Symbols.Push(new Symbol(String.Empty, DataType.CreateRowType(Keywords.Source)));
                try
                {
                    Schema.RowType        rowType       = new Schema.RowType(compareKey.Columns);
                    Schema.RowType        sourceRowType = new Schema.RowType(compareKey.Columns, Keywords.Source);
                    Schema.TableVarColumn newColumn;
                    foreach (AggregateColumnExpression expression in _computeColumns)
                    {
                        PlanNode sourceNode  = null;
                        string[] columnNames = new string[expression.Columns.Count];
                        for (int index = 0; index < expression.Columns.Count; index++)
                        {
                            columnNames[index] = expression.Columns[index].ColumnName;
                        }

                        if (expression.Distinct)
                        {
                            sourceNode = Compiler.EmitProjectNode(plan, _sourceNode, columnNames, true);
                        }
                        else
                        {
                            sourceNode = _sourceNode;
                        }

                        for (int index = 0; index < columnNames.Length; index++)
                        {
                            if (((TableNode)sourceNode).TableVar.Columns.IndexOf(columnNames[index]) < 0)
                            {
                                throw new Schema.SchemaException(Schema.SchemaException.Codes.ObjectNotFound, columnNames[index]);
                            }
                        }

                        OperatorBindingContext context = new OperatorBindingContext(expression, expression.AggregateOperator, plan.NameResolutionPath, Compiler.AggregateSignatureFromArguments(sourceNode, columnNames, true), false);
                        PlanNode aggregateNode         = Compiler.EmitAggregateCallNode(plan, context, sourceNode, columnNames, expression.HasByClause ? expression.OrderColumns : null);
                        Compiler.CheckOperatorResolution(plan, context);
                        sourceNode = aggregateNode.Nodes[0];                                                                      // Make sure to preserve any conversion and casting done by the operator resolution

                        int stackDisplacement = ((AggregateCallNode)aggregateNode).Operator.Initialization.StackDisplacement + 1; // add 1 to account for the result variable
                        stackDisplacement += columnNames.Length;
                        for (int index = 0; index < stackDisplacement; index++)
                        {
                            plan.Symbols.Push(new Symbol(String.Empty, plan.DataTypes.SystemScalar));
                        }
                        try
                        {
                            // Walk sourceNode (assuming an n-length list of unary table operators) until _sourceNode is found
                            // Insert a restriction between it and a recompile of _sourceNode (to account for possible context changes)

                            if (sourceNode == _sourceNode)
                            {
                                sourceNode = Compiler.EmitRestrictNode(plan, Compiler.CompileExpression(plan, (Expression)_sourceNode.EmitStatement(EmitMode.ForCopy)), Compiler.BuildRowEqualExpression(plan, sourceRowType.Columns, rowType.Columns));
                            }
                            else
                            {
                                PlanNode currentNode = sourceNode;
                                while (currentNode != null)
                                {
                                    if (currentNode.NodeCount >= 1)
                                    {
                                        if (currentNode.Nodes[0] == _sourceNode)
                                        {
                                            currentNode.Nodes[0] = Compiler.EmitRestrictNode(plan, Compiler.CompileExpression(plan, (Expression)_sourceNode.EmitStatement(EmitMode.ForCopy)), Compiler.BuildRowEqualExpression(plan, sourceRowType.Columns, rowType.Columns));
                                            break;
                                        }
                                        currentNode = currentNode.Nodes[0];
                                    }
                                    else
                                    {
                                        Error.Fail("Internal Error: Original source node not found in aggregate invocation argument.");
                                    }
                                }
                            }

                            if (expression.HasByClause)
                            {
                                sourceNode = Compiler.EmitOrderNode(plan, (TableNode)sourceNode, Compiler.CompileOrderColumnDefinitions(plan, ((TableNode)sourceNode).TableVar, expression.OrderColumns, null, false), false);
                            }
                            aggregateNode.Nodes[0] = sourceNode;
                        }
                        finally
                        {
                            for (int index = 0; index < stackDisplacement; index++)
                            {
                                plan.Symbols.Pop();
                            }
                        }

                        newColumn =
                            new Schema.TableVarColumn
                            (
                                new Schema.Column
                                (
                                    expression.ColumnAlias,
                                    aggregateNode.DataType
                                ),
                                expression.MetaData,
                                Schema.TableVarColumnType.Virtual
                            );

                        DataType.Columns.Add(newColumn.Column);
                        TableVar.Columns.Add(newColumn);
                        newColumn.IsNilable = aggregateNode.IsNilable;
                        Nodes.Add(aggregateNode);
                    }

                    DetermineRemotable(plan);
                }
                finally
                {
                    plan.Symbols.Pop();
                }
            }
            finally
            {
                plan.ExitRowContext();
            }
        }
Ejemplo n.º 15
0
        // TODO: Compile row types for each index, saving column indexes to prevent the need for lookup during insert, update, and delete.
        private void InternalInitialize(ServerProcess AProcess)
        {
            Schema.RowType LKeyRowType;
            Schema.RowType LDataRowType;

            // Create the indexes required to store data as described by the given table type
            // Determine Fanout, Capacity, Clustering Key, KeyLength, DataLength
            FClusteringKey = TableVar.FindClusteringOrder(AProcess.Plan);
            //Schema.Key LClusteringKey = TableVar.FindClusteringKey();
            //FClusteringKey = new Schema.Order(LClusteringKey, AProcess.Plan);
            LKeyRowType  = new Schema.RowType(FClusteringKey.Columns);
            LDataRowType = new Schema.RowType();
            foreach (Schema.Column LColumn in TableVar.DataType.Columns)
            {
                if (!FClusteringKey.Columns.Contains(LColumn.Name))
                {
                    LDataRowType.Columns.Add(new Schema.Column(LColumn.Name, LColumn.DataType));
                }
            }

            // Add an internal identifier for uniqueness of keys in nonunique indexes
                        #if USEINTERNALID
            FInternalIDColumn = new Schema.TableVarColumn(new Schema.Column(CInternalIDColumnName, AProcess.Plan.Catalog.DataTypes.SystemGuid), Schema.TableVarColumnType.InternalID);
            LDataRowType.Columns.Add(FInternalIDColumn.Column);
                        #endif

            // Create the Clustered index
            FClusteredIndex =
                new TableBufferIndex
                (
                    AProcess,
                    FClusteringKey,
                    LKeyRowType,
                    LDataRowType,
                    true,
                    FFanout,
                    FCapacity
                );
            Indexes.Add(FClusteredIndex);

            // DataLength and DataColumns for all non clustered indexes is the key length and columns of the clustered key
            LDataRowType = LKeyRowType;

            // Create non clustered indexes for each key and order (unique sets)
            Schema.Order LKey;
            foreach (Schema.Key LNonClusteredKey in TableVar.Keys)
            {
                if (!FClusteringKey.Includes(LNonClusteredKey))
                {
                    LKey = new Schema.Order(LNonClusteredKey, AProcess.Plan);
                    if (!Indexes.Contains(LKey))
                    {
                        LKeyRowType = new Schema.RowType(LKey.Columns);

                        Indexes.Add
                        (
                            new TableBufferIndex
                            (
                                AProcess,
                                LKey,
                                LKeyRowType,
                                LDataRowType,
                                false,
                                FFanout,
                                FCapacity
                            )
                        );
                    }
                }
            }

            foreach (Schema.Order LOrder in TableVar.Orders)
            {
                // This is a potentially non-unique index, so add a GUID to ensure uniqueness of the key in the BTree
                LKey = new Schema.Order(LOrder);
                                #if USEINTERNALID
                if (!LKey.Includes(LClusteringKey))
                {
                    Schema.OrderColumn LUniqueColumn = new Schema.OrderColumn(FInternalIDColumn, true);
                    LUniqueColumn.Sort = ((Schema.ScalarType)LUniqueColumn.Column.DataType).GetUniqueSort(AProcess.Plan);
                    LKey.Columns.Add(LUniqueColumn);
                }
                                #endif

                if (!Indexes.Contains(LKey))
                {
                    LKeyRowType = new Schema.RowType(LKey.Columns);

                    Indexes.Add
                    (
                        new TableBufferIndex
                        (
                            AProcess,
                            LKey,
                            LKeyRowType,
                            LDataRowType,
                            false,
                            FFanout,
                            FCapacity
                        )
                    );
                }
            }
        }
Ejemplo n.º 16
0
 protected IRow BuildUniqueKeyRow()
 {
     Schema.RowType rowType = new Schema.RowType(_browseTable.Order.Columns);
     return(new Row(_browseTable.Manager, rowType));
 }