/// <summary>
 /// adds the table metadata to the internal list
 /// </summary>
 /// <param name="tableMetadata"></param>
 public void Add(TableMetadata tableMetadata)
 {
     if (!_tables.ContainsKey(tableMetadata.name))
     {
         _tables.Add(tableMetadata.name, tableMetadata);
     }
 }
 private ITableMetadata GetPrimaryTable(IForeignKeyColumnInfo[] iForeignKeyColumnInfo)
 {
     //we should have only one table as primary
     ITableMetadata pname = null;
     foreach (var s in iForeignKeyColumnInfo)
     {
         if (pname != null && s.PrimaryKeyTableName != pname.Name)
         {
             logger.Warn(string.Format("Inconsistent key definition. Set not created"));
             return null;
         }
         pname = new TableMetadata(s.PrimaryKeyTableCatalog,s.PrimaryKeyTableSchema,s.PrimaryKeyTableName);
     }
     return pname;
 }
Beispiel #3
0
 public TableOnMergeViewChangeHandler(TableMetadata tableMetadata)
 {
     _tableMetadata = tableMetadata;
 }
 public AggSvcGroupByWTableRollupSingleKeyImpl(TableMetadata tableMetadata, TableColumnMethodPair[] methodPairs, AggregationAccessorSlotPair[] accessors, bool join, TableStateInstanceGrouped tableStateInstance, int[] targetStates, ExprNode[] accessStateExpr, AggregationAgent[] agents)
     : base(tableMetadata, methodPairs, accessors, join, tableStateInstance, targetStates, accessStateExpr, agents)
 {
 }
Beispiel #5
0
        public static void SchemaCheck(Table table)
        {
            var changes = TableMetadata.GetChanges(table.Partitions[0]);

            ReportSchemaCheckChanges(changes);
        }
Beispiel #6
0
 private string GenerateFileName(TableMetadata tableMetadata)
 {
     return(string.IsNullOrWhiteSpace(tableMetadata.Schema.Database)
         ? $"{tableMetadata.Schema.Table}"
         : $"{tableMetadata.Schema.Database}.{tableMetadata.Schema.Table}");
 }
Beispiel #7
0
        public static void BuildDataFromTable(IQueryHelper queryHelper, IDbTransaction transaction, Int16 serverId, string database, string schema, TableMetadata table, object[] dataRow)
        {
            if (table.ColumnsDefinition.Count != dataRow.Length)
            {
                throw new ArgumentException($"The number of columns defined in the cached table {table.Name} '{table.ColumnsDefinition.Count}' " +
                                            "is different from the current row '{dataRow.Length}'.");
            }

            for (var i = 0; i < table.ColumnsDefinition.Count; i++)
            {
                var col = table.ColumnsDefinition[i];
                dataRow[i] = BuildDataColumn(queryHelper, transaction, serverId, database, schema, table, col);
            }
        }
Beispiel #8
0
 public AggregationAccessorMinMaxByTable(bool max, TableMetadata tableMetadata)
     : base(max)
 {
     _tableMetadata = tableMetadata;
 }
Beispiel #9
0
        /// <summary>
        /// Returns a random INSERT command
        /// </summary> 
        public DbCommand GetInsertCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("INSERT INTO \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" (");

            StringBuilder valuesText = new StringBuilder();
            valuesText.Append(") VALUES (");

            List<TableColumn> columns = table.Columns;
            int numColumns = rnd.Next(2, columns.Count);
            bool mostlyNull = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName.ToUpper() == "PRIMARYKEY") continue;

                if (i > 1)
                {
                    cmdText.Append(", ");
                    valuesText.Append(", ");
                }

                cmdText.Append(columns[i].ColumnName);

                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD")
                {
                    valuesText.Append("DEFAULT"); // Cannot insert an explicit value in a timestamp field
                }
                else if (mostlyNull && rnd.NextBool(0.9))
                {
                    valuesText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", i + 1), columns[i]);

                    valuesText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            // To deal databases that do not support auto-incremented columns (Oracle?)
            // if (!columns["PrimaryKey"].AutoIncrement)
            if (PrimaryKeyValueIsRequired)
            {
                DbParameter param = CreateRandomParameter(rnd, "P0", table.GetColumn("PrimaryKey"));
                cmdText.Append(", PrimaryKey");
                valuesText.Append(", ");
                valuesText.Append(param.ParameterName);
                com.Parameters.Add(param);
            }

            valuesText.Append(")");
            cmdText.Append(valuesText);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
        public static TableMetadata ReadMetadata(JsonData jObject)
        {
            var target = new TableMetadata();

            if (jObject["table"] != null)
                target.name = jObject["table"].ToString();
            if (jObject["name"] != null)
                target.name = jObject["name"].ToString();
            if (jObject["creationDate"] != null)
                target.creationDate = DateTime.FromFileTimeUtc((long)jObject["creationDate"]);
            if (jObject["status"] != null)
                target.status = (TableMetadata.Status)Enum.Parse(typeof(TableMetadata.Status), jObject["status"].ToString().ToUpper());
            if (jObject["itemCount"] != null)
                target.itemCount = (int)jObject["itemCount"];
            if (jObject["key"] != null)
                target.key = JsonMapper.ToObject<TableKey>(jObject["key"].ToJson());
            if (jObject["size"] != null)
                target.size = (int)jObject["size"];
            if (jObject["throughput"] != null)
                target.throughput = JsonMapper.ToObject<TableThroughput>(jObject["throughput"].ToJson());
            //
            if (jObject["provisionType"] != null)
            {
                var p1 = JsonMapper.ToObject<ProvisionMeta>(jObject["provisionType"].ToJson());
                target.provisionType = (ProvisionType)p1.id;
            }
            if (jObject["provisionLoad"] != null)
            {
                var p2 = JsonMapper.ToObject<ProvisionMeta>(jObject["provisionLoad"].ToJson());
                target.provisionLoad = (ProvisionLoad)p2.id;
            }

            return target;
        }
Beispiel #11
0
        public StatementAgentInstanceFactoryOnTriggerTable(StatementContext statementContext, StatementSpecCompiled statementSpec, EPServicesContext services, ViewableActivator activator, SubSelectStrategyCollection subSelectStrategyCollection, ResultSetProcessorFactoryDesc resultSetProcessorPrototype, ExprNode validatedJoin, TableOnViewFactory onExprFactory, EventType activatorResultEventType, TableMetadata tableMetadata, ResultSetProcessorFactoryDesc outputResultSetProcessorPrototype, OutputProcessViewFactory outputProcessViewFactory)
            : base(statementContext, statementSpec, services, activator, subSelectStrategyCollection)
        {
            _resultSetProcessorPrototype = resultSetProcessorPrototype;
            _onExprFactory = onExprFactory;
            _outputResultSetProcessorPrototype = outputResultSetProcessorPrototype;
            _outputProcessViewFactory          = outputProcessViewFactory;

            var pair            = StatementAgentInstanceFactoryOnTriggerNamedWindow.GetIndexHintPair(statementContext, statementSpec);
            var indexHint       = pair.IndexHint;
            var excludePlanHint = pair.ExcludePlanHint;

            _queryPlanResult = SubordinateQueryPlanner.PlanOnExpression(
                validatedJoin, activatorResultEventType, indexHint, true, -1, excludePlanHint,
                false, tableMetadata.EventTableIndexMetadataRepo, tableMetadata.InternalEventType,
                tableMetadata.UniqueKeyProps, true, statementContext.StatementName, statementContext.StatementId, statementContext.Annotations);
            if (_queryPlanResult.IndexDescs != null)
            {
                for (var i = 0; i < _queryPlanResult.IndexDescs.Length; i++)
                {
                    tableMetadata.AddIndexReference(_queryPlanResult.IndexDescs[i].IndexName, statementContext.StatementName);
                }
            }
            SubordinateQueryPlannerUtil.QueryPlanLogOnExpr(tableMetadata.IsQueryPlanLogging, TableServiceImpl.QueryPlanLog,
                                                           _queryPlanResult, statementContext.Annotations);
        }
Beispiel #12
0
        /// <summary>
        /// Returns a random SELECT command
        /// </summary>
        public DbCommand GetSelectCommand(Random rnd, TableMetadata tableMetadata, DataStressConnection conn, bool isXml = false)
        {
            DbCommand com = CreateCommand(rnd, conn);
            StringBuilder cmdText = new StringBuilder();
            cmdText.Append(GetSelectCommandForMultipleRows(rnd, com, tableMetadata, isXml));

            // 33% of the time, we also want to add another batch to the select command to allow for
            // multiple result sets.
            if ((!isXml) && (rnd.Next(0, 3) == 0))
            {
                cmdText.Append(";").Append(GetSelectCommandForScalarValue(com));
            }

            if ((!isXml) && ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
Beispiel #13
0
        private static bool MergeTable(TableModifierModel mergedTable,
                                       List <TableModifier> userConfigTables,
                                       TableMetadata defaultTable)
        {
            var hasChange       = false;
            var userConfigTable = userConfigTables.FirstOrDefault(t => t.Name == mergedTable.Name);

            if (defaultTable == null)
            {
                hasChange = true;
            }

            //Add new
            if (userConfigTable == null)
            {
                userConfigTable = new TableModifier {
                    Name = mergedTable.Name
                };
                userConfigTables.Add(userConfigTable);
            }

            userConfigTable.IsStatic = mergedTable.IsStatic;
            userConfigTable.DerativeTables.GlobalAccess  = mergedTable.DerativeTablesGlobalAccess;
            userConfigTable.DerativeTables.GlobalCascade = mergedTable.DerativeTablesGlobalCascade;

            if (mergedTable.IsStatic ||
                mergedTable.DerativeTablesGlobalAccess != DerivativeTableAccess.NotSet ||
                mergedTable.DerativeTablesGlobalCascade == true)
            {
                hasChange = true;
            }

            //Clear
            userConfigTable.ForeignKeys.ForeignKeyAdd        = new List <ForeignKeyAdd>();
            userConfigTable.ForeignKeys.ForeignKeyRemove     = new ForeignKeyRemove();
            userConfigTable.DerativeTables.DerativeSubTables = new List <DerivativeSubTable>();
            userConfigTable.DataBuilders = new List <DataBuilder>();

            //Merge FK
            for (int i = mergedTable.ForeignKeys.Count - 1; i >= 0; i--)
            {
                var mergedFk  = mergedTable.ForeignKeys[i];
                var defaultFk = defaultTable.ForeignKeys.FirstOrDefault(f => f.ServerIdTo.ToString() == mergedFk.ServerIdTo &&
                                                                        f.DatabaseTo == mergedFk.DatabaseTo &&
                                                                        f.SchemaTo == mergedFk.SchemaTo &&
                                                                        f.TableTo == mergedFk.TableTo);
                if (MergeForeignKey(mergedFk, mergedTable.ForeignKeys, userConfigTable.ForeignKeys, defaultFk, defaultTable.ColumnsDefinition))
                {
                    hasChange = true;
                }
            }

            //Merge derivative table
            for (int i = mergedTable.DerivativeTables.Count - 1; i >= 0; i--)
            {
                var mergedDerivativeTable = mergedTable.DerivativeTables[i];
                var defaultDt             = defaultTable.DerivativeTables.FirstOrDefault(d => d.ServerId.ToString() == mergedDerivativeTable.ServerId &&
                                                                                         d.Database == mergedDerivativeTable.Database &&
                                                                                         d.Schema == mergedDerivativeTable.Schema &&
                                                                                         d.Table == mergedDerivativeTable.Table);
                if (MergedDerivativeTable(mergedDerivativeTable, mergedTable.DerivativeTables, userConfigTable.DerativeTables, defaultDt))
                {
                    hasChange = true;
                }
            }

            //Merge data builders
            foreach (var mergedDataBuilder in mergedTable.DataBuilders)
            {
                if (MergeDataBuilders(mergedDataBuilder, userConfigTable.DataBuilders))
                {
                    hasChange = true;
                }
            }

            //Cleaning
            if (!userConfigTable.DataBuilders.Any())
            {
                userConfigTable.DataBuilders = null;
            }
            if (!userConfigTable.ForeignKeys.ForeignKeyAdd.Any())
            {
                userConfigTable.ForeignKeys.ForeignKeyAdd = null;
            }
            if (!userConfigTable.ForeignKeys.ForeignKeyRemove.Columns.Any())
            {
                userConfigTable.ForeignKeys.ForeignKeyRemove = null;
            }
            if (userConfigTable.ForeignKeys.ForeignKeyAdd == null &&
                userConfigTable.ForeignKeys.ForeignKeyRemove == null)
            {
                userConfigTable.ForeignKeys = null;
            }
            if (mergedTable.DerativeTablesGlobalAccess == DerivativeTableAccess.NotSet &&
                mergedTable.DerativeTablesGlobalCascade == false &&
                !userConfigTable.DerativeTables.DerativeSubTables.Any())
            {
                userConfigTable.DerativeTables = null;
            }

            //If no change has been detected with the default config
            if (!hasChange)
            {
                userConfigTables.Remove(userConfigTable);
            }

            return(hasChange);
        }
Beispiel #14
0
        IEnumerator TestRestTableAsync()
        {
            Terminal.LogImportant("TestRestTableAsync (This is really slow)");

            // Make Table
            var tableName = Strings.RandomString(10);
            var meta1     = new TableMetadata
            {
                name          = tableName,
                provisionLoad = ProvisionLoad.Balanced,
                provisionType = ProvisionType.Custom,
                throughput    = new TableThroughput(1, 1),
                key           = new TableKey(new Key("ID1", Key.DataType.STRING), new Key("ID2", Key.DataType.NUMBER)),
            };


            //CREATE
            Terminal.Log("CREATE " + tableName);
            var result1 = Repository.CreateTable(meta1);

            yield return(StartCoroutine(result1.WaitRoutine()));

            result1.ThrowIfFaulted();
            if (result1.Result.hasError)
            {
                throw new Exception(result1.Result.error.message);
            }

            //wait...
            var meta2 = WaitForTable(Repository, tableName);

            yield return(StartCoroutine(meta2.WaitRoutine()));

            meta2.ThrowIfFaulted();

            //LIST
            Terminal.Log("LIST");
            var result4 = Repository.ListTables();

            yield return(StartCoroutine(result4.WaitRoutine()));

            result4.ThrowIfFaulted();
            if (result4.Result.hasError)
            {
                throw new Exception(result4.Result.error.message);
            }
            Assert.IsTrue(result4.Result.data.tables.Any(), "request returned no results");

            //UPDATE
            Terminal.Log("UPDATE");
            meta2.Result.throughput    = new TableThroughput(2, 2);
            meta2.Result.provisionType = ProvisionType.Custom;
            var result3 = Repository.UpdateTable(meta2.Result);

            yield return(StartCoroutine(result3.WaitRoutine()));

            result3.ThrowIfFaulted();
            if (result3.Result.hasError)
            {
                throw new Exception(result3.Result.error.message);
            }

            //wait...
            var meta3 = WaitForTable(Repository, tableName, 5000);

            yield return(StartCoroutine(meta3.WaitRoutine()));

            meta3.ThrowIfFaulted();

            //DELETE
            Terminal.Log("DELETE");
            var result5 = Repository.DeleteTable(tableName);

            yield return(StartCoroutine(result5.WaitRoutine()));

            result5.ThrowIfFaulted();
            if (result5.Result.hasError)
            {
                throw new Exception(result5.Result.error.message);
            }

            Terminal.LogSuccess("Test Success");
        }
Beispiel #15
0
        public void checkPureMetadata(string TableName = null, string KeyspaceName = null, TableOptions tableOptions = null)
        {
            var columns = new Dictionary
                          <string, ColumnTypeCode>
            {
                { "q0uuid", ColumnTypeCode.Uuid },
                { "q1timestamp", ColumnTypeCode.Timestamp },
                { "q2double", ColumnTypeCode.Double },
                { "q3int32", ColumnTypeCode.Int },
                { "q4int64", ColumnTypeCode.Bigint },
                { "q5float", ColumnTypeCode.Float },
                { "q6inet", ColumnTypeCode.Inet },
                { "q7boolean", ColumnTypeCode.Boolean },
                { "q8inet", ColumnTypeCode.Inet },
                { "q9blob", ColumnTypeCode.Blob },
                { "q10varint", ColumnTypeCode.Varint },
                { "q11decimal", ColumnTypeCode.Decimal },
                { "q12list", ColumnTypeCode.List },
                { "q13set", ColumnTypeCode.Set },
                { "q14map", ColumnTypeCode.Map }
                //{"q12counter", Metadata.ColumnTypeCode.Counter}, A table that contains a counter can only contain counters
            };

            string tablename = TableName ?? "table" + Guid.NewGuid().ToString("N");
            var    sb        = new StringBuilder(@"CREATE TABLE " + tablename + " (");

            foreach (KeyValuePair <string, ColumnTypeCode> col in columns)
            {
                sb.Append(col.Key + " " + col.Value +
                          (((col.Value == ColumnTypeCode.List) ||
                            (col.Value == ColumnTypeCode.Set) ||
                            (col.Value == ColumnTypeCode.Map))
                               ? "<int" + (col.Value == ColumnTypeCode.Map ? ",varchar>" : ">")
                               : "") + ", ");
            }

            sb.Append("PRIMARY KEY(");
            int rowKeys = Randomm.Instance.Next(1, columns.Count - 3);

            for (int i = 0; i < rowKeys; i++)
            {
                sb.Append(columns.Keys.First(key => key.StartsWith("q" + i.ToString(CultureInfo.InvariantCulture))) + ((i == rowKeys - 1) ? "" : ", "));
            }

            string opt = tableOptions != null ? " WITH " + tableOptions : "";

            sb.Append("))" + opt + ";");

            Session.WaitForSchemaAgreement(
                QueryTools.ExecuteSyncNonQuery(Session, sb.ToString())
                );

            TableMetadata table = Cluster.Metadata.GetTable(KeyspaceName ?? Keyspace, tablename);

            foreach (TableColumn metaCol in table.TableColumns)
            {
                Assert.True(columns.Keys.Contains(metaCol.Name));
                Assert.True(metaCol.TypeCode == columns.First(tpc => tpc.Key == metaCol.Name).Value);
                Assert.True(metaCol.Table == tablename);
                Assert.True(metaCol.Keyspace == (KeyspaceName ?? Keyspace));
            }

            if (tableOptions != null)
            {
                Assert.True(tableOptions.Equals(table.Options));
            }
        }
        public static OutputProcessViewFactory Make(StatementSpecCompiled statementSpec, InternalEventRouter internalEventRouter, StatementContext statementContext, EventType resultEventType, OutputProcessViewCallback optionalOutputProcessViewCallback, TableService tableService, ResultSetProcessorType resultSetProcessorType, ResultSetProcessorHelperFactory resultSetProcessorHelperFactory, StatementVariableRef statementVariableRef)
        {
            // determine direct-callback
            if (optionalOutputProcessViewCallback != null)
            {
                return(new OutputProcessViewFactoryCallback(optionalOutputProcessViewCallback));
            }

            // determine routing
            bool isRouted     = false;
            bool routeToFront = false;

            if (statementSpec.InsertIntoDesc != null)
            {
                isRouted     = true;
                routeToFront = statementContext.NamedWindowMgmtService.IsNamedWindow(statementSpec.InsertIntoDesc.EventTypeName);
            }

            OutputStrategyPostProcessFactory outputStrategyPostProcessFactory = null;

            if ((statementSpec.InsertIntoDesc != null) || (statementSpec.SelectStreamSelectorEnum == SelectClauseStreamSelectorEnum.RSTREAM_ONLY))
            {
                SelectClauseStreamSelectorEnum?insertIntoStreamSelector = null;
                string tableName = null;

                if (statementSpec.InsertIntoDesc != null)
                {
                    insertIntoStreamSelector = statementSpec.InsertIntoDesc.StreamSelector;
                    TableMetadata tableMetadata = tableService.GetTableMetadata(statementSpec.InsertIntoDesc.EventTypeName);
                    if (tableMetadata != null)
                    {
                        tableName = tableMetadata.TableName;
                        EPLValidationUtil.ValidateContextName(true, tableName, tableMetadata.ContextName, statementSpec.OptionalContextName, true);
                        statementVariableRef.AddReferences(statementContext.StatementName, tableMetadata.TableName);
                    }
                }

                outputStrategyPostProcessFactory = new OutputStrategyPostProcessFactory(isRouted, insertIntoStreamSelector, statementSpec.SelectStreamSelectorEnum, internalEventRouter, statementContext.EpStatementHandle, routeToFront, tableService, tableName);
            }

            // Do we need to enforce an output policy?
            int             streamCount     = statementSpec.StreamSpecs.Length;
            OutputLimitSpec outputLimitSpec = statementSpec.OutputLimitSpec;
            bool            isDistinct      = statementSpec.SelectClauseSpec.IsDistinct;
            bool            isGrouped       = statementSpec.GroupByExpressions != null && statementSpec.GroupByExpressions.GroupByNodes.Length > 0;

            OutputProcessViewFactory outputProcessViewFactory;

            if (outputLimitSpec == null)
            {
                if (!isDistinct)
                {
                    outputProcessViewFactory = new OutputProcessViewDirectFactory(statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory);
                }
                else
                {
                    outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory(statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct, null, null, resultEventType);
                }
            }
            else if (outputLimitSpec.RateType == OutputLimitRateType.AFTER)
            {
                outputProcessViewFactory = new OutputProcessViewDirectDistinctOrAfterFactory(statementContext, outputStrategyPostProcessFactory, resultSetProcessorHelperFactory, isDistinct, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType);
            }
            else
            {
                try {
                    bool isWithHavingClause         = statementSpec.HavingExprRootNode != null;
                    bool isStartConditionOnCreation = HasOnlyTables(statementSpec.StreamSpecs);
                    OutputConditionFactory outputConditionFactory = OutputConditionFactoryFactory.CreateCondition(outputLimitSpec, statementContext, isGrouped, isWithHavingClause, isStartConditionOnCreation, resultSetProcessorHelperFactory);
                    bool hasOrderBy = statementSpec.OrderByList != null && statementSpec.OrderByList.Length > 0;
                    OutputProcessViewConditionFactory.ConditionType conditionType;
                    bool hasAfter = outputLimitSpec.AfterNumberOfEvents != null || outputLimitSpec.AfterTimePeriodExpr != null;
                    bool isUnaggregatedUngrouped = resultSetProcessorType == ResultSetProcessorType.HANDTHROUGH || resultSetProcessorType == ResultSetProcessorType.UNAGGREGATED_UNGROUPED;

                    // hint checking with order-by
                    bool hasOptHint = HintEnum.ENABLE_OUTPUTLIMIT_OPT.GetHint(statementSpec.Annotations) != null;
                    if (hasOptHint && hasOrderBy)
                    {
                        throw new ExprValidationException("The " + HintEnum.ENABLE_OUTPUTLIMIT_OPT + " hint is not supported with order-by");
                    }

                    if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.SNAPSHOT)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.SNAPSHOT;
                    }
                    // For FIRST without groups we are using a special logic that integrates the first-flag, in order to still conveniently use all sorts of output conditions.
                    // FIRST with group-by is handled by setting the output condition to null (OutputConditionNull) and letting the ResultSetProcessor handle first-per-group.
                    // Without having-clause there is no required order of processing, thus also use regular policy.
                    else if (outputLimitSpec.DisplayLimit == OutputLimitLimitType.FIRST && statementSpec.GroupByExpressions == null)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_FIRST;
                    }
                    else if (isUnaggregatedUngrouped && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.ALL && !hasOrderBy)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else if (hasOptHint && outputLimitSpec.DisplayLimit == OutputLimitLimitType.LAST && !hasOrderBy)
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_LASTALL_UNORDERED;
                    }
                    else
                    {
                        conditionType = OutputProcessViewConditionFactory.ConditionType.POLICY_NONFIRST;
                    }

                    SelectClauseStreamSelectorEnum selectClauseStreamSelectorEnum = statementSpec.SelectStreamSelectorEnum;
                    bool terminable = outputLimitSpec.RateType == OutputLimitRateType.TERM || outputLimitSpec.IsAndAfterTerminate;
                    outputProcessViewFactory = new OutputProcessViewConditionFactory(statementContext, outputStrategyPostProcessFactory, isDistinct, outputLimitSpec.AfterTimePeriodExpr, outputLimitSpec.AfterNumberOfEvents, resultEventType, outputConditionFactory, streamCount, conditionType, outputLimitSpec.DisplayLimit, terminable, hasAfter, isUnaggregatedUngrouped, selectClauseStreamSelectorEnum, resultSetProcessorHelperFactory);
                }
                catch (Exception ex) {
                    throw new ExprValidationException("Error in the output rate limiting clause: " + ex.Message, ex);
                }
            }

            return(outputProcessViewFactory);
        }
 protected abstract void ValidateBindingInternal(ExprValidationContext validationContext, TableMetadata tableMetadata);
Beispiel #18
0
        /// <summary>
        /// Returns a random existing Primary Key value
        /// </summary>
        private int GetRandomPK(Random rnd, TableMetadata table)
        {
            using (DataStressConnection conn = CreateConnection())
            {
                conn.Open();

                // This technique to get a random row comes from http://www.4guysfromrolla.com/webtech/042606-1.shtml
                // When you set rowcount and then select into a scalar value, then the query is optimised so that
                // just the last value is selected. So if n = ROWCOUNT then the query returns the n'th row.

                int rowNumber = rnd.Next(Depth);

                DbCommand com = conn.CreateCommand();
                string cmdText = string.Format(
                    @"SET ROWCOUNT {0};
                          DECLARE @PK INT;
                          SELECT @PK = PrimaryKey FROM {1} WITH(NOLOCK)
                          SELECT @PK", rowNumber, table.TableName);

                com.CommandText = cmdText;

                object result = com.ExecuteScalarSyncOrAsync(CancellationToken.None, rnd).Result;
                if (result == DBNull.Value)
                {
                    throw DataStressErrors.TestError(string.Format("Table {0} returned DBNull for primary key", table.TableName));
                }
                else
                {
                    int primaryKey = (int)result;
                    return primaryKey;
                }
            }
        }
Beispiel #19
0
 public EPStatementDestroyCallbackTableUpdStr(TableService tableService, TableMetadata tableMetadata, string statementName)
 {
     _tableService  = tableService;
     _tableMetadata = tableMetadata;
     _statementName = statementName;
 }
Beispiel #20
0
        // method used to create stress tables in the database
        protected void BuildUserTables(List<TableMetadata> TableMetadataList)
        {
            string CreateTable1 =
            "CREATE TABLE stress_test_table_1 (PrimaryKey int identity(1,1) primary key, int_FLD int, smallint_FLD smallint, real_FLD real, float_FLD float, decimal_FLD decimal(28,4), " +
            "smallmoney_FLD smallmoney, bit_FLD bit, tinyint_FLD tinyint, uniqueidentifier_FLD uniqueidentifier, varbinary_FLD varbinary(756), binary_FLD binary(756), " +
            "image_FLD image, varbinarymax_FLD varbinary(max), timestamp_FLD timestamp, char_FLD char(756), text_FLD text, varcharmax_FLD varchar(max), " +
            "varchar_FLD varchar(756), nchar_FLD nchar(756), ntext_FLD ntext, nvarcharmax_FLD nvarchar(max), nvarchar_FLD nvarchar(756), datetime_FLD datetime, " +
            "smalldatetime_FLD smalldatetime);" +
            "CREATE UNIQUE INDEX stress_test_table_1 on stress_test_table_1 ( PrimaryKey );" +
            "insert into stress_test_table_1(int_FLD, smallint_FLD, real_FLD, float_FLD, decimal_FLD, " +
            "smallmoney_FLD, bit_FLD, tinyint_FLD, uniqueidentifier_FLD, varbinary_FLD, binary_FLD, " +
            "image_FLD, varbinarymax_FLD, char_FLD, text_FLD, varcharmax_FLD, " +
            "varchar_FLD, nchar_FLD, ntext_FLD, nvarcharmax_FLD, nvarchar_FLD, datetime_FLD, " +
            "smalldatetime_FLD) values ( 0, 0, 0, 0, 0, $0, 0, 0, '00000000-0000-0000-0000-000000000000', " +
            "0x00, 0x00, 0x00, 0x00, '0', '0', '0', '0', N'0', N'0', N'0', N'0', '01/11/2000 12:54:01', '01/11/2000 12:54:00' );"
            ;

            string CreateTable2 =
            "CREATE TABLE stress_test_table_2 (PrimaryKey int identity(1,1) primary key, bigint_FLD bigint, money_FLD money, numeric_FLD numeric, " +
            "time_FLD time, date_FLD date, datetimeoffset_FLD datetimeoffset, sql_variant_FLD sql_variant, " +
            "datetime2_FLD datetime2, xml_FLD xml);" +
            "CREATE UNIQUE INDEX stress_test_table_2 on stress_test_table_2 ( PrimaryKey );" +
            "insert into stress_test_table_2(bigint_FLD, money_FLD, numeric_FLD, " +
            "time_FLD, date_FLD, datetimeoffset_FLD, sql_variant_FLD, " +
            "datetime2_FLD, xml_FLD) values ( 0, $0, 0, '01/11/2015 12:54:01', '01/11/2015 12:54:01', '01/11/2000 12:54:01 -08:00', 0, '01/11/2000 12:54:01', '0' );"
            ;

            if (TableMetadataList == null)
            {
                TableMetadataList = new List<TableMetadata>();
            }

            List<TableColumn> tableColumns1 = new List<TableColumn>();
            tableColumns1.Add(new TableColumn("PrimaryKey", -1));
            tableColumns1.Add(new TableColumn("int_FLD", -1));
            tableColumns1.Add(new TableColumn("smallint_FLD", -1));
            tableColumns1.Add(new TableColumn("real_FLD", -1));
            tableColumns1.Add(new TableColumn("float_FLD", -1));
            tableColumns1.Add(new TableColumn("decimal_FLD", -1));
            tableColumns1.Add(new TableColumn("smallmoney_FLD", -1));
            tableColumns1.Add(new TableColumn("bit_FLD", -1));
            tableColumns1.Add(new TableColumn("tinyint_FLD", -1));
            tableColumns1.Add(new TableColumn("uniqueidentifier_FLD", -1));
            tableColumns1.Add(new TableColumn("varbinary_FLD", 756));
            tableColumns1.Add(new TableColumn("binary_FLD", 756));
            tableColumns1.Add(new TableColumn("image_FLD", -1));
            tableColumns1.Add(new TableColumn("varbinarymax_FLD", -1));
            tableColumns1.Add(new TableColumn("timestamp_FLD", -1));
            tableColumns1.Add(new TableColumn("char_FLD", -1));
            tableColumns1.Add(new TableColumn("text_FLD", -1));
            tableColumns1.Add(new TableColumn("varcharmax_FLD", -1));
            tableColumns1.Add(new TableColumn("varchar_FLD", 756));
            tableColumns1.Add(new TableColumn("nchar_FLD", 756));
            tableColumns1.Add(new TableColumn("ntext_FLD", -1));
            tableColumns1.Add(new TableColumn("nvarcharmax_FLD", -1));
            tableColumns1.Add(new TableColumn("nvarchar_FLD", 756));
            tableColumns1.Add(new TableColumn("datetime_FLD", -1));
            tableColumns1.Add(new TableColumn("smalldatetime_FLD", -1));
            TableMetadata tableMeta1 = new TableMetadata("stress_test_table_1", tableColumns1);
            TableMetadataList.Add(tableMeta1);

            List<TableColumn> tableColumns2 = new List<TableColumn>();
            tableColumns2.Add(new TableColumn("PrimaryKey", -1));
            tableColumns2.Add(new TableColumn("bigint_FLD", -1));
            tableColumns2.Add(new TableColumn("money_FLD", -1));
            tableColumns2.Add(new TableColumn("numeric_FLD", -1));
            tableColumns2.Add(new TableColumn("time_FLD", -1));
            tableColumns2.Add(new TableColumn("date_FLD", -1));
            tableColumns2.Add(new TableColumn("datetimeoffset_FLD", -1));
            tableColumns2.Add(new TableColumn("sql_variant_FLD", -1));
            tableColumns2.Add(new TableColumn("datetime2_FLD", -1));
            tableColumns2.Add(new TableColumn("xml_FLD", -1));
            TableMetadata tableMeta2 = new TableMetadata("stress_test_table_2", tableColumns2);
            TableMetadataList.Add(tableMeta2);

            using (DataStressConnection conn = CreateConnection(null))
            {
                conn.Open();
                using (DbCommand com = conn.CreateCommand())
                {
                    try
                    {
                        com.CommandText = CreateTable1;
                        com.ExecuteNonQuery();
                    }
                    catch (DbException de)
                    {
                        // This can be improved by doing a Drop Table if exists.
                        if (de.Message.Contains("There is already an object named \'" + tableMeta1.TableName + "\' in the database."))
                        {
                            CleanupUserTables(tableMeta1);
                            com.ExecuteNonQuery();
                        }
                        else
                        {
                            throw de;
                        }
                    }

                    try
                    {
                        com.CommandText = CreateTable2;
                        com.ExecuteNonQuery();
                    }
                    catch (DbException de)
                    {
                        // This can be improved by doing a Drop Table if exists in the query itself.
                        if (de.Message.Contains("There is already an object named \'" + tableMeta2.TableName + "\' in the database."))
                        {
                            CleanupUserTables(tableMeta2);
                            com.ExecuteNonQuery();
                        }
                        else
                        {
                            throw de;
                        }
                    }

                    for (int i = 0; i < Depth; i++)
                    {
                        TrackedRandom randomInstance = new TrackedRandom();
                        randomInstance.Mark();

                        DbCommand comInsert1 = GetInsertCommand(randomInstance, tableMeta1, conn);
                        comInsert1.ExecuteNonQuery();

                        DbCommand comInsert2 = GetInsertCommand(randomInstance, tableMeta2, conn);
                        comInsert2.ExecuteNonQuery();
                    }
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// 生成创建表的 SQL 语句
        /// </summary>
        /// <param name="tableMetadata">表元数据</param>
        /// <returns>SQL 语句</returns>
        protected virtual string GenerateCreateTableSql(TableMetadata tableMetadata)
        {
            var isAutoIncrementPrimary = tableMetadata.IsAutoIncrementPrimary;

            var tableName = GetNameSql(tableMetadata.Schema.Table);
            var database  = GetNameSql(tableMetadata.Schema.Database);

            var builder = string.IsNullOrWhiteSpace(database)
                                ? new StringBuilder($"IF OBJECT_ID('{tableName}', 'U') IS NULL BEGIN CREATE table {tableName} (")
                                : new StringBuilder(
                $"USE {database}; IF OBJECT_ID('{tableName}', 'U') IS NULL BEGIN CREATE table {tableName} (");

            foreach (var column in tableMetadata.Columns)
            {
                var isPrimary = tableMetadata.IsPrimary(column.Key);

                var columnSql = GenerateColumnSql(column.Value, isPrimary);

                if (isAutoIncrementPrimary && isPrimary)
                {
                    builder.Append($"{columnSql} IDENTITY(1,1), ");
                }
                else
                {
                    builder.Append($"{columnSql}, ");
                }
            }

            builder.Remove(builder.Length - 2, 2);

            if (tableMetadata.HasPrimary)
            {
                var primaryKeys = string.Join(", ", tableMetadata.Primary.Select(c => $"[{GetNameSql(c)}]"));
                builder.Append(
                    $", CONSTRAINT [PK_{tableName}] PRIMARY KEY CLUSTERED ({primaryKeys}) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = ON , ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON[PRIMARY]) ON[PRIMARY];");
            }
            else
            {
                builder.Append(") ON [PRIMARY];");
            }

            if (tableMetadata.Indexes.Count > 0)
            {
                foreach (var index in tableMetadata.Indexes)
                {
                    var name        = index.Name;
                    var columnNames = string.Join(", ", index.Columns.Select(c => $"[{GetNameSql(c)}]"));
                    if (index.IsUnique)
                    {
                        builder.Append(
                            $"CREATE UNIQUE NONCLUSTERED INDEX [INDEX_{name}] ON {tableName} ({columnNames}) {(StorageType == StorageType.InsertIgnoreDuplicate ? "WITH (IGNORE_DUP_KEY = ON)" : "")};");
                    }
                    else
                    {
                        builder.Append(
                            $"CREATE NONCLUSTERED INDEX [INDEX_{name}] ON {tableName} ({columnNames});");
                    }
                }
            }

            builder.AppendLine(" END");
            var sql = builder.ToString();

            return(sql);
        }
 /// <summary>
 /// 获取数据文件路径
 /// </summary>
 /// <param name="dfc">数据上下文件</param>
 /// <param name="tableMetadata">表元数据</param>
 /// <param name="extension">文件扩展名</param>
 /// <returns></returns>
 protected virtual string GetDataFile(DataFlowContext dfc, TableMetadata tableMetadata, string extension)
 {
     return(Path.Combine(GetDataFolder(dfc.Response.Request.OwnerId),
                         $"{GenerateFileName(tableMetadata)}.{extension}"));
 }
Beispiel #23
0
 protected override string GenerateCreateDatabaseSql(TableMetadata tableMetadata)
 {
     return(string.IsNullOrWhiteSpace(tableMetadata.Schema.Database)
                         ? ""
                         : $"CREATE DATABASE {Escape}{GetNameSql(tableMetadata.Schema.Database)}{Escape} with encoding 'UTF-8';");
 }
Beispiel #24
0
        public static object BuildDataColumn(IQueryHelper queryHelper, IDbTransaction transaction, Int16 serverId, string database, string schema, TableMetadata table, ColumnDefinition col)
        {
            IDataBuilder builder      = null;
            var          mustGenerate = false;

            if (!string.IsNullOrWhiteSpace(col.BuilderName))
            {
                mustGenerate = true;

                if (!CachedBuilders.ContainsKey(col.BuilderName))
                {
                    var t = Type.GetType(col.BuilderName);
                    builder = FastActivator.CreateInstance(t) as IDataBuilder;
                    CachedBuilders.Add(col.BuilderName, builder);
                }
                else
                {
                    builder = CachedBuilders[col.BuilderName];
                }
            }
            else if (((col.IsPrimary && !col.IsAutoIncrement) || col.IsUniqueKey) && !col.IsForeignKey)
            {
                mustGenerate = true;
                switch (col.DbType)
                {
                case DbType.Date:
                case DbType.DateTime:
                case DbType.DateTime2:
                    return(DateTime.Now);

                case DbType.Byte:
                case DbType.Decimal:
                case DbType.Double:
                case DbType.SByte:
                case DbType.Single:
                case DbType.Int16:
                case DbType.Int32:
                case DbType.Int64:
                case DbType.UInt16:
                case DbType.UInt32:
                case DbType.UInt64:
                    builder = CachedBuilders["AutoIncrementDataBuilder"];
                    break;

                case DbType.AnsiString:
                case DbType.AnsiStringFixedLength:
                case DbType.Guid:
                case DbType.String:
                case DbType.StringFixedLength:
                    builder = CachedBuilders["StringDataBuilder"];
                    break;

                default:
                    throw new NotSupportedException($"The generation of the key failed. Please specify a databuilder " +
                                                    "in the configuration for {database}.{table}.{col.Name}");
                }
            }

            //Generate data
            if (mustGenerate)
            {
                if (builder == null)
                {
                    throw new NullReferenceException($"Builder '{col.BuilderName}' for column '{col.Name}' is not found. Watch configuration file.");
                }
                return(builder.BuildData(queryHelper.Connection, transaction, queryHelper.Engine, serverId, database, schema, table, col));
            }
            return(null);
        }
        public static EPStatementStartMethodSelectDesc Prepare(StatementSpecCompiled statementSpec,
                                                               EPServicesContext services,
                                                               StatementContext statementContext,
                                                               bool recoveringResilient,
                                                               AgentInstanceContext defaultAgentInstanceContext,
                                                               bool queryPlanLogging,
                                                               ViewableActivatorFactory optionalViewableActivatorFactory,
                                                               OutputProcessViewCallback optionalOutputProcessViewCallback,
                                                               SelectExprProcessorDeliveryCallback selectExprProcessorDeliveryCallback)
        {
            // define stop and destroy
            List <StopCallback>            stopCallbacks    = new List <StopCallback>();
            EPStatementDestroyCallbackList destroyCallbacks = new EPStatementDestroyCallbackList();

            // determine context
            var contextName             = statementSpec.OptionalContextName;
            var contextPropertyRegistry = (contextName != null) ? services.ContextManagementService.GetContextDescriptor(contextName).ContextPropertyRegistry : null;

            // Determine stream names for each stream - some streams may not have a name given
            var streamNames = EPStatementStartMethodHelperUtil.DetermineStreamNames(statementSpec.StreamSpecs);
            var numStreams  = streamNames.Length;

            if (numStreams == 0)
            {
                throw new ExprValidationException("The from-clause is required but has not been specified");
            }
            var isJoin     = statementSpec.StreamSpecs.Length > 1;
            var hasContext = statementSpec.OptionalContextName != null;

            // First we create streams for subselects, if there are any
            var subSelectStreamDesc = EPStatementStartMethodHelperSubselect.CreateSubSelectActivation(services, statementSpec, statementContext, destroyCallbacks);

            // Create streams and views
            var eventStreamParentViewableActivators = new ViewableActivator[numStreams];
            var unmaterializedViewChain             = new ViewFactoryChain[numStreams];
            var eventTypeNames           = new String[numStreams];
            var isNamedWindow            = new bool[numStreams];
            var historicalEventViewables = new HistoricalEventViewable[numStreams];

            // verify for joins that required views are present
            var joinAnalysisResult   = VerifyJoinViews(statementSpec, statementContext.NamedWindowService, defaultAgentInstanceContext);
            var evaluatorContextStmt = new ExprEvaluatorContextStatement(statementContext, false);

            for (var i = 0; i < statementSpec.StreamSpecs.Length; i++)
            {
                var streamSpec = statementSpec.StreamSpecs[i];

                var isCanIterateUnbound = streamSpec.ViewSpecs.Length == 0 &&
                                          (services.ConfigSnapshot.EngineDefaults.ViewResourcesConfig.IsIterableUnbound ||
                                           AnnotationUtil.FindAttribute(statementSpec.Annotations, typeof(IterableUnboundAttribute)) != null);

                // Create view factories and parent view based on a filter specification
                if (streamSpec is FilterStreamSpecCompiled)
                {
                    var filterStreamSpec = (FilterStreamSpecCompiled)streamSpec;
                    eventTypeNames[i] = filterStreamSpec.FilterSpec.FilterForEventTypeName;

                    // Since only for non-joins we get the existing stream's lock and try to reuse it's views
                    var filterSubselectSameStream = EPStatementStartMethodHelperUtil.DetermineSubquerySameStream(statementSpec, filterStreamSpec);

                    // create activator
                    ViewableActivator activatorDeactivator;
                    if (optionalViewableActivatorFactory != null)
                    {
                        activatorDeactivator = optionalViewableActivatorFactory.CreateActivatorSimple(filterStreamSpec);
                        if (activatorDeactivator == null)
                        {
                            throw new IllegalStateException("Viewable activate is null for " + filterStreamSpec.FilterSpec.FilterForEventType.Name);
                        }
                    }
                    else
                    {
                        if (!hasContext)
                        {
                            activatorDeactivator = services.ViewableActivatorFactory.CreateStreamReuseView(
                                services, statementContext, statementSpec, filterStreamSpec, isJoin,
                                evaluatorContextStmt, filterSubselectSameStream, i, isCanIterateUnbound);
                        }
                        else
                        {
                            InstrumentationAgent instrumentationAgentFilter = null;
                            if (InstrumentationHelper.ENABLED)
                            {
                                var eventTypeName = filterStreamSpec.FilterSpec.FilterForEventType.Name;
                                var streamNumber  = i;
                                instrumentationAgentFilter = new ProxyInstrumentationAgent()
                                {
                                    ProcIndicateQ = () => InstrumentationHelper.Get().QFilterActivationStream(eventTypeName, streamNumber),
                                    ProcIndicateA = () => InstrumentationHelper.Get().AFilterActivationStream(),
                                };
                            }

                            activatorDeactivator = services.ViewableActivatorFactory.CreateFilterProxy(
                                services, filterStreamSpec.FilterSpec, statementSpec.Annotations, false,
                                instrumentationAgentFilter, isCanIterateUnbound);
                        }
                    }
                    eventStreamParentViewableActivators[i] = activatorDeactivator;

                    var resultEventType = filterStreamSpec.FilterSpec.ResultEventType;
                    unmaterializedViewChain[i] = services.ViewService.CreateFactories(i, resultEventType, streamSpec.ViewSpecs, streamSpec.Options, statementContext);
                }
                // Create view factories and parent view based on a pattern expression
                else if (streamSpec is PatternStreamSpecCompiled)
                {
                    var patternStreamSpec = (PatternStreamSpecCompiled)streamSpec;
                    var usedByChildViews  = streamSpec.ViewSpecs.Length > 0 || (statementSpec.InsertIntoDesc != null);
                    var patternTypeName   = statementContext.StatementId + "_pattern_" + i;
                    var eventType         = services.EventAdapterService.CreateSemiAnonymousMapType(patternTypeName, patternStreamSpec.TaggedEventTypes, patternStreamSpec.ArrayEventTypes, usedByChildViews);
                    unmaterializedViewChain[i] = services.ViewService.CreateFactories(i, eventType, streamSpec.ViewSpecs, streamSpec.Options, statementContext);

                    var rootFactoryNode = services.PatternNodeFactory.MakeRootNode(patternStreamSpec.EvalFactoryNode);
                    var patternContext  = statementContext.PatternContextFactory.CreateContext(statementContext, i, rootFactoryNode, patternStreamSpec.MatchedEventMapMeta, true);

                    // create activator
                    ViewableActivator patternActivator = services.ViewableActivatorFactory.CreatePattern(
                        patternContext, rootFactoryNode, eventType,
                        EPStatementStartMethodHelperUtil.IsConsumingFilters(patternStreamSpec.EvalFactoryNode),
                        patternStreamSpec.IsSuppressSameEventMatches, patternStreamSpec.IsDiscardPartialsOnMatch,
                        isCanIterateUnbound);
                    eventStreamParentViewableActivators[i] = patternActivator;
                }
                // Create view factories and parent view based on a database SQL statement
                else if (streamSpec is DBStatementStreamSpec)
                {
                    ValidateNoViews(streamSpec, "Historical data");

                    var sqlStreamSpec                  = (DBStatementStreamSpec)streamSpec;
                    var typeConversionHook             = (SQLColumnTypeConversion)TypeHelper.GetAnnotationHook(statementSpec.Annotations, HookType.SQLCOL, typeof(SQLColumnTypeConversion), statementContext.MethodResolutionService);
                    var outputRowConversionHook        = (SQLOutputRowConversion)TypeHelper.GetAnnotationHook(statementSpec.Annotations, HookType.SQLROW, typeof(SQLOutputRowConversion), statementContext.MethodResolutionService);
                    var epStatementAgentInstanceHandle = defaultAgentInstanceContext.EpStatementAgentInstanceHandle;
                    var historicalEventViewable        = DatabasePollingViewableFactory.CreateDBStatementView(
                        statementContext.StatementId, i, sqlStreamSpec,
                        services.DatabaseRefService,
                        services.EventAdapterService,
                        epStatementAgentInstanceHandle,
                        statementContext.Annotations,
                        typeConversionHook,
                        outputRowConversionHook,
                        statementContext.ConfigSnapshot.EngineDefaults.LoggingConfig.IsEnableADO);
                    historicalEventViewables[i]            = historicalEventViewable;
                    unmaterializedViewChain[i]             = ViewFactoryChain.FromTypeNoViews(historicalEventViewable.EventType);
                    eventStreamParentViewableActivators[i] = new ProxyViewableActivator(
                        (agentInstanceContext, isSubselect, isRecoveringResilient) => new ViewableActivationResult(historicalEventViewable, CollectionUtil.STOP_CALLBACK_NONE, null, null, null, false, false, null));
                    stopCallbacks.Add(historicalEventViewable.Stop);
                }
                else if (streamSpec is MethodStreamSpec)
                {
                    ValidateNoViews(streamSpec, "Method data");

                    var methodStreamSpec = (MethodStreamSpec)streamSpec;
                    var epStatementAgentInstanceHandle = defaultAgentInstanceContext.EpStatementAgentInstanceHandle;
                    var historicalEventViewable        = MethodPollingViewableFactory.CreatePollMethodView(i, methodStreamSpec, services.EventAdapterService, epStatementAgentInstanceHandle, statementContext.MethodResolutionService, services.EngineImportService, statementContext.SchedulingService, statementContext.ScheduleBucket, evaluatorContextStmt, statementContext.VariableService, statementContext.ContextName);
                    historicalEventViewables[i]            = historicalEventViewable;
                    unmaterializedViewChain[i]             = ViewFactoryChain.FromTypeNoViews(historicalEventViewable.EventType);
                    eventStreamParentViewableActivators[i] = new ProxyViewableActivator(
                        (agentInstanceContext, isSubselect, isRecoveringResilient) => new ViewableActivationResult(historicalEventViewable, CollectionUtil.STOP_CALLBACK_NONE, null, null, null, false, false, null));
                    stopCallbacks.Add(historicalEventViewable.Stop);
                }
                else if (streamSpec is TableQueryStreamSpec)
                {
                    ValidateNoViews(streamSpec, "Table data");
                    TableQueryStreamSpec tableStreamSpec = (TableQueryStreamSpec)streamSpec;
                    if (isJoin && tableStreamSpec.FilterExpressions.Count > 0)
                    {
                        throw new ExprValidationException("Joins with tables do not allow table filter expressions, please add table filters to the where-clause instead");
                    }
                    TableMetadata   metadata         = services.TableService.GetTableMetadata(tableStreamSpec.TableName);
                    ExprEvaluator[] tableFilterEvals = null;
                    if (tableStreamSpec.FilterExpressions.Count > 0)
                    {
                        tableFilterEvals = ExprNodeUtility.GetEvaluators(tableStreamSpec.FilterExpressions);
                    }
                    EPLValidationUtil.ValidateContextName(true, metadata.TableName, metadata.ContextName, statementSpec.OptionalContextName, false);
                    eventStreamParentViewableActivators[i] = new ViewableActivatorTable(metadata, tableFilterEvals);
                    unmaterializedViewChain[i]             = ViewFactoryChain.FromTypeNoViews(metadata.InternalEventType);
                    eventTypeNames[i] = tableStreamSpec.TableName;
                    joinAnalysisResult.SetTablesForStream(i, metadata);
                    if (tableStreamSpec.Options.IsUnidirectional)
                    {
                        throw new ExprValidationException("Tables cannot be marked as unidirectional");
                    }
                    if (tableStreamSpec.Options.IsRetainIntersection || tableStreamSpec.Options.IsRetainUnion)
                    {
                        throw new ExprValidationException("Tables cannot be marked with retain");
                    }
                    if (isJoin)
                    {
                        destroyCallbacks.AddCallback(EPStatementDestroyCallbackTableIdxRef.New(services.TableService, metadata, statementContext.StatementName));
                    }
                }
                else if (streamSpec is NamedWindowConsumerStreamSpec)
                {
                    var namedSpec       = (NamedWindowConsumerStreamSpec)streamSpec;
                    var processor       = services.NamedWindowService.GetProcessor(namedSpec.WindowName);
                    var namedWindowType = processor.TailView.EventType;
                    if (namedSpec.OptPropertyEvaluator != null)
                    {
                        namedWindowType = namedSpec.OptPropertyEvaluator.FragmentEventType;
                    }

                    eventStreamParentViewableActivators[i] = services.ViewableActivatorFactory.CreateNamedWindow(processor, namedSpec.FilterExpressions, namedSpec.OptPropertyEvaluator);
                    unmaterializedViewChain[i]             = services.ViewService.CreateFactories(i, namedWindowType, namedSpec.ViewSpecs, namedSpec.Options, statementContext);
                    joinAnalysisResult.SetNamedWindow(i);
                    eventTypeNames[i] = namedSpec.WindowName;
                    isNamedWindow[i]  = true;

                    // Consumers to named windows cannot declare a data window view onto the named window to avoid duplicate remove streams
                    EPStatementStartMethodHelperValidate.ValidateNoDataWindowOnNamedWindow(unmaterializedViewChain[i].FactoryChain);
                }
                else
                {
                    throw new ExprValidationException("Unknown stream specification type: " + streamSpec);
                }
            }

            // handle match-recognize pattern
            if (statementSpec.MatchRecognizeSpec != null)
            {
                if (isJoin)
                {
                    throw new ExprValidationException("Joins are not allowed when using match-recognize");
                }
                if (joinAnalysisResult.TablesPerStream[0] != null)
                {
                    throw new ExprValidationException("Tables cannot be used with match-recognize");
                }
                var isUnbound = (unmaterializedViewChain[0].FactoryChain.IsEmpty()) && (!(statementSpec.StreamSpecs[0] is NamedWindowConsumerStreamSpec));
                var factory   = services.RegexHandlerFactory.MakeViewFactory(unmaterializedViewChain[0], statementSpec.MatchRecognizeSpec, defaultAgentInstanceContext, isUnbound, statementSpec.Annotations, services.ConfigSnapshot.EngineDefaults.MatchRecognizeConfig);
                unmaterializedViewChain[0].FactoryChain.Add(factory);

                EPStatementStartMethodHelperAssignExpr.AssignAggregations(factory.AggregationService, factory.AggregationExpressions);
            }

            // Obtain event types from view factory chains
            var streamEventTypes = new EventType[statementSpec.StreamSpecs.Length];

            for (var i = 0; i < unmaterializedViewChain.Length; i++)
            {
                streamEventTypes[i] = unmaterializedViewChain[i].EventType;
            }

            // Add uniqueness information useful for joins
            joinAnalysisResult.AddUniquenessInfo(unmaterializedViewChain, statementSpec.Annotations);

            // Validate sub-select views
            var subSelectStrategyCollection = EPStatementStartMethodHelperSubselect.PlanSubSelect(services, statementContext, queryPlanLogging, subSelectStreamDesc, streamNames, streamEventTypes, eventTypeNames, statementSpec.DeclaredExpressions, contextPropertyRegistry);

            // Construct type information per stream
            StreamTypeService typeService      = new StreamTypeServiceImpl(streamEventTypes, streamNames, EPStatementStartMethodHelperUtil.GetHasIStreamOnly(isNamedWindow, unmaterializedViewChain), services.EngineURI, false);
            var viewResourceDelegateUnverified = new ViewResourceDelegateUnverified();

            // Validate views that require validation, specifically streams that don't have
            // sub-views such as DB SQL joins
            var historicalViewableDesc = new HistoricalViewableDesc(numStreams);

            for (var stream = 0; stream < historicalEventViewables.Length; stream++)
            {
                var historicalEventViewable = historicalEventViewables[stream];
                if (historicalEventViewable == null)
                {
                    continue;
                }
                historicalEventViewable.Validate(
                    services.EngineImportService,
                    typeService,
                    statementContext.MethodResolutionService,
                    statementContext.TimeProvider,
                    statementContext.VariableService,
                    statementContext.TableService,
                    statementContext.ScriptingService,
                    evaluatorContextStmt,
                    services.ConfigSnapshot,
                    services.SchedulingService,
                    services.EngineURI,
                    statementSpec.SqlParameters,
                    statementContext.EventAdapterService,
                    statementContext.StatementName,
                    statementContext.StatementId,
                    statementContext.Annotations);
                historicalViewableDesc.SetHistorical(stream, historicalEventViewable.RequiredStreams);
                if (historicalEventViewable.RequiredStreams.Contains(stream))
                {
                    throw new ExprValidationException("Parameters for historical stream " + stream + " indicate that the stream is subordinate to itself as stream parameters originate in the same stream");
                }
            }

            // unidirectional is not supported with into-table
            if (joinAnalysisResult.IsUnidirectional && statementSpec.IntoTableSpec != null)
            {
                throw new ExprValidationException("Into-table does not allow unidirectional joins");
            }

            // Construct a processor for results posted by views and joins, which takes care of aggregation if required.
            // May return null if we don't need to post-process results posted by views or joins.
            var resultSetProcessorPrototypeDesc = ResultSetProcessorFactoryFactory.GetProcessorPrototype(
                statementSpec, statementContext, typeService, viewResourceDelegateUnverified, joinAnalysisResult.UnidirectionalInd, true, contextPropertyRegistry, selectExprProcessorDeliveryCallback, services.ConfigSnapshot);

            // Validate where-clause filter tree, outer join clause and output limit expression
            EPStatementStartMethodHelperValidate.ValidateNodes(statementSpec, statementContext, typeService, viewResourceDelegateUnverified);

            // Handle 'prior' function nodes in terms of view requirements
            var viewResourceDelegateVerified = EPStatementStartMethodHelperViewResources.VerifyPreviousAndPriorRequirements(unmaterializedViewChain, viewResourceDelegateUnverified);

            // handle join
            JoinSetComposerPrototype joinSetComposerPrototype = null;

            if (numStreams > 1)
            {
                var selectsRemoveStream = statementSpec.SelectStreamSelectorEnum.IsSelectsRStream() ||
                                          statementSpec.OutputLimitSpec != null;
                var hasAggregations = !resultSetProcessorPrototypeDesc.AggregationServiceFactoryDesc.Expressions.IsEmpty();
                joinSetComposerPrototype = JoinSetComposerPrototypeFactory.MakeComposerPrototype(
                    statementContext.StatementName,
                    statementContext.StatementId,
                    statementSpec.OuterJoinDescList,
                    statementSpec.FilterRootNode,
                    typeService.EventTypes, streamNames,
                    joinAnalysisResult, queryPlanLogging,
                    statementContext,
                    historicalViewableDesc,
                    defaultAgentInstanceContext,
                    selectsRemoveStream,
                    hasAggregations,
                    services.TableService,
                    false);
            }

            // obtain factory for output limiting
            var outputViewFactory = OutputProcessViewFactoryFactory.Make(
                statementSpec, services.InternalEventRouter,
                statementContext,
                resultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultEventType,
                optionalOutputProcessViewCallback,
                services.TableService,
                resultSetProcessorPrototypeDesc.ResultSetProcessorFactory.ResultSetProcessorType);

            // Factory for statement-context instances
            var factoryX = new StatementAgentInstanceFactorySelect(
                numStreams, eventStreamParentViewableActivators,
                statementContext, statementSpec, services,
                typeService, unmaterializedViewChain, resultSetProcessorPrototypeDesc, joinAnalysisResult, recoveringResilient,
                joinSetComposerPrototype, subSelectStrategyCollection, viewResourceDelegateVerified, outputViewFactory);

            EPStatementStopMethod stopMethod = new EPStatementStopMethodImpl(statementContext, stopCallbacks).Stop;

            return(new EPStatementStartMethodSelectDesc(factoryX, subSelectStrategyCollection, viewResourceDelegateUnverified, resultSetProcessorPrototypeDesc, stopMethod, destroyCallbacks));
        }
Beispiel #26
0
        public static void SchemaCheck(Partition partition)
        {
            var changes = TableMetadata.GetChanges(partition);

            ReportSchemaCheckChanges(changes);
        }
 public BookPersistentObject(TableMetadata mainTable)
     : base(mainTable)
 {
 }
Beispiel #28
0
        public static void SchemaCheck(ProviderDataSource source)
        {
            var changes = TableMetadata.GetChanges(source);

            ReportSchemaCheckChanges(changes);
        }
 public BookPersistentObject(DatabaseServer database, string connectionString, TableMetadata mainTable)
     : base(database, connectionString, mainTable)
 {
 }
Beispiel #30
0
        /// <summary>
        /// Load the result of an Sql query into the metadatas object.
        /// </summary>
        /// <param name="reader">Result of an Sql query defined in <see cref="MetadataProvider.SqlGetColumns"/></param>
        /// <param name="metadata">Metadatas container</param>
        /// <param name="serverId">ServerId loaded from</param>
        /// <param name="database">Database loaded from</param>
        /// <param name="typeConverter">Classe performing type conversion between database and .NET.</param>
        internal static void LoadColumns(IDataReader reader, Metadatas metadata, string serverId, string database, ISqlTypeConverter typeConverter)
        {
            var    schemaMetadata  = new SchemaMetadata();
            var    lstSchemaColumn = new List <ColumnDefinition>();
            string currentSchema;

            if (!reader.Read())
            {
                return;
            }

            //Init first row
            var previousSchema = reader.GetString(0);
            var previousTable  = new TableMetadata(reader.GetString(1));

            //Pour chaque ligne
            do
            {
                currentSchema = reader.GetString(0);
                var currentTable = reader.GetString(1);

                //Si on change de table
                if (currentSchema != previousSchema || currentTable != previousTable.Name)
                {
                    previousTable.ColumnsDefinition = lstSchemaColumn;
                    schemaMetadata.Add(previousTable);

                    lstSchemaColumn = new List <ColumnDefinition>();
                    previousTable   = new TableMetadata(currentTable);
                }

                //Si on change de schema
                if (currentSchema != previousSchema)
                {
                    metadata[serverId, database, currentSchema] = schemaMetadata;
                    schemaMetadata = new SchemaMetadata();
                }

                //Ajoute la colonne
                var col = new ColumnDefinition
                {
                    Name    = reader.GetString(2),
                    SqlType = new SqlType
                    {
                        DataType   = reader.GetString(3),
                        Precision  = reader.GetInt32(4),
                        Scale      = reader.GetInt32(5),
                        IsUnsigned = reader.GetBoolean(6)
                    },
                    IsPrimary       = reader.GetBoolean(7),
                    IsAutoIncrement = reader.GetBoolean(8)
                };
                col.DbType = typeConverter.ConvertFromSql(col.SqlType);

                lstSchemaColumn.Add(col);
            } while (reader.Read());

            //Ajoute la dernière table / schema
            if (lstSchemaColumn.Count > 0)
            {
                previousTable.ColumnsDefinition = lstSchemaColumn;
                schemaMetadata.Add(previousTable);
                metadata[serverId, database, currentSchema] = schemaMetadata;
            }
        }
Beispiel #31
0
 public void SetTablesForStream(int streamNum, TableMetadata metadata)
 {
     this._tablesPerStream[streamNum] = metadata;
 }
Beispiel #32
0
        private LinearAggregationFactoryDesc HandleNonIntoTable(ExprNode[] childNodes, AggregationStateType stateType, ExprValidationContext validationContext)
        {
            var           streamTypeService = validationContext.StreamTypeService;
            int           streamNum;
            Type          resultType;
            ExprEvaluator evaluator;
            ExprNode      evaluatorIndex = null;
            bool          istreamOnly;
            EventType     containedType;
            Type          scalarCollectionComponentType = null;

            // validate wildcard use
            var isWildcard = childNodes.Length == 0 || childNodes.Length > 0 && childNodes[0] is ExprWildcard;

            if (isWildcard)
            {
                ExprAggMultiFunctionUtil.ValidateWildcardStreamNumbers(validationContext.StreamTypeService, stateType.ToString().ToLower());
                streamNum     = 0;
                containedType = streamTypeService.EventTypes[0];
                resultType    = containedType.UnderlyingType;
                TableMetadata tableMetadata = validationContext.TableService.GetTableMetadataFromEventType(containedType);
                evaluator   = ExprNodeUtility.MakeUnderlyingEvaluator(0, resultType, tableMetadata);
                istreamOnly = GetIstreamOnly(streamTypeService, 0);
                if ((stateType == AggregationStateType.WINDOW) && istreamOnly && !streamTypeService.IsOnDemandStreams)
                {
                    throw MakeUnboundValidationEx(stateType);
                }
            }
            // validate "stream.*"
            else if (childNodes.Length > 0 && childNodes[0] is ExprStreamUnderlyingNode)
            {
                streamNum   = ExprAggMultiFunctionUtil.ValidateStreamWildcardGetStreamNum(childNodes[0]);
                istreamOnly = GetIstreamOnly(streamTypeService, streamNum);
                if ((stateType == AggregationStateType.WINDOW) && istreamOnly && !streamTypeService.IsOnDemandStreams)
                {
                    throw MakeUnboundValidationEx(stateType);
                }
                var type = streamTypeService.EventTypes[streamNum];
                containedType = type;
                resultType    = type.UnderlyingType;
                TableMetadata tableMetadata = validationContext.TableService.GetTableMetadataFromEventType(type);
                evaluator = ExprNodeUtility.MakeUnderlyingEvaluator(streamNum, resultType, tableMetadata);
            }
            // validate when neither wildcard nor "stream.*"
            else
            {
                var child   = childNodes[0];
                var streams = ExprNodeUtility.GetIdentStreamNumbers(child);
                if ((streams.IsEmpty() || (streams.Count > 1)))
                {
                    throw new ExprValidationException(GetErrorPrefix(stateType) + " requires that any child expressions evaluate properties of the same stream; Use 'firstever' or 'lastever' or 'nth' instead");
                }
                streamNum   = streams.First();
                istreamOnly = GetIstreamOnly(streamTypeService, streamNum);
                if ((stateType == AggregationStateType.WINDOW) && istreamOnly && !streamTypeService.IsOnDemandStreams)
                {
                    throw MakeUnboundValidationEx(stateType);
                }
                resultType = childNodes[0].ExprEvaluator.ReturnType;
                evaluator  = childNodes[0].ExprEvaluator;
                if (streamNum >= streamTypeService.EventTypes.Length)
                {
                    containedType = streamTypeService.EventTypes[0];
                }
                else
                {
                    containedType = streamTypeService.EventTypes[streamNum];
                }
                scalarCollectionComponentType = resultType;
            }

            if (childNodes.Length > 1)
            {
                if (stateType == AggregationStateType.WINDOW)
                {
                    throw new ExprValidationException(GetErrorPrefix(stateType) + " does not accept an index expression; Use 'first' or 'last' instead");
                }
                evaluatorIndex = childNodes[1];
                if (evaluatorIndex.ExprEvaluator.ReturnType != typeof(int?))
                {
                    throw new ExprValidationException(GetErrorPrefix(stateType) + " requires an index expression that returns an integer value");
                }
            }

            // determine accessor
            AggregationAccessor accessor;

            if (evaluatorIndex != null)
            {
                var isFirst  = stateType == AggregationStateType.FIRST;
                var constant = -1;
                if (evaluatorIndex.IsConstantResult)
                {
                    constant = evaluatorIndex.ExprEvaluator.Evaluate(new EvaluateParams(null, true, null)).AsInt();
                }
                accessor = new AggregationAccessorFirstLastIndexWEval(streamNum, evaluator, evaluatorIndex.ExprEvaluator, constant, isFirst);
            }
            else
            {
                if (stateType == AggregationStateType.FIRST)
                {
                    accessor = new AggregationAccessorFirstWEval(streamNum, evaluator);
                }
                else if (stateType == AggregationStateType.LAST)
                {
                    accessor = new AggregationAccessorLastWEval(streamNum, evaluator);
                }
                else if (stateType == AggregationStateType.WINDOW)
                {
                    accessor = new AggregationAccessorWindowWEval(streamNum, evaluator, resultType);
                }
                else
                {
                    throw new IllegalStateException("Access type is undefined or not known as code '" + stateType + "'");
                }
            }

            var accessorResultType = resultType;

            if (stateType == AggregationStateType.WINDOW)
            {
                accessorResultType = TypeHelper.GetArrayType(resultType);
            }

            var           isFafWindow    = streamTypeService.IsOnDemandStreams && stateType == AggregationStateType.WINDOW;
            TableMetadata tableMetadataX = validationContext.TableService.GetTableMetadataFromEventType(containedType);

            if (tableMetadataX == null && !isFafWindow && (istreamOnly || streamTypeService.IsOnDemandStreams))
            {
                var factoryX = new ExprAggMultiFunctionLinearAccessNodeFactoryMethod(this, containedType, accessorResultType, streamNum);
                return(new LinearAggregationFactoryDesc(factoryX, containedType, scalarCollectionComponentType));
            }

            var stateKey = new AggregationStateKeyWStream(streamNum, containedType, AggregationStateTypeWStream.DATAWINDOWACCESS_LINEAR, new ExprNode[0]);

            ExprNode me           = this;
            var      theStreamNum = streamNum;
            AggregationStateFactory stateFactory = new ProxyAggregationStateFactory
            {
                ProcCreateAccess = (methodResolutionService, agentInstanceId, groupId, aggregationId, join, groupKey, passThru) =>
                {
                    if (join)
                    {
                        return(methodResolutionService.MakeAccessAggLinearJoin(agentInstanceId, groupId, aggregationId, theStreamNum, passThru));
                    }
                    return(methodResolutionService.MakeAccessAggLinearNonJoin(agentInstanceId, groupId, aggregationId, theStreamNum, passThru));
                },

                ProcAggregationExpression = () => me
            };

            var factory = new ExprAggMultiFunctionLinearAccessNodeFactoryAccess(this, accessor, accessorResultType, containedType,
                                                                                stateKey, stateFactory, AggregationAgentDefault.INSTANCE);
            var enumerationType = scalarCollectionComponentType == null ? containedType : null;

            return(new LinearAggregationFactoryDesc(factory, enumerationType, scalarCollectionComponentType));
        }
Beispiel #33
0
 public TableOnUpdateView(SubordWMatchExprLookupStrategy lookupStrategy, TableStateInstance rootView, ExprEvaluatorContext exprEvaluatorContext, TableMetadata metadata, TableOnUpdateViewFactory parent)
     : base(lookupStrategy, rootView, exprEvaluatorContext, metadata, true)
 {
     this.parent = parent;
 }
Beispiel #34
0
        /// <summary>
        /// Returns a random command object
        /// </summary>
        public DbCommand GetCommand(Random rnd, TableMetadata table, DataStressConnection conn, bool query, bool isXml = false)
        {
            if (query)
            {
                return GetSelectCommand(rnd, table, conn, isXml);
            }
            else
            {
                // make sure arguments are correct
                DataStressErrors.Assert(!isXml, "wrong usage of GetCommand: cannot create command with FOR XML that is not query");

                int select = rnd.Next(4);
                switch (select)
                {
                    case 0:
                        return GetUpdateCommand(rnd, table, conn);
                    case 1:
                        return GetInsertCommand(rnd, table, conn);
                    case 2:
                        return GetDeleteCommand(rnd, table, conn);
                    default:
                        return GetSelectCommand(rnd, table, conn);
                }
            }
        }
Beispiel #35
0
 public OrderPersistentObject(Session session, TableMetadata mainTable) : base(session, mainTable)
 {
 }
Beispiel #36
0
        /// <summary>
        /// Returns a SELECT command that retrieves data from a table
        /// </summary>
        private String GetSelectCommandForMultipleRows(Random rnd, DbCommand com, TableMetadata inputTable, bool isXml)
        {
            int rowcount = rnd.Next(Depth);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("SELECT TOP ");
            cmdText.Append(rowcount); //Jonfo added this to prevent table scan of 75k row tables
            cmdText.Append(" PrimaryKey");

            List<TableColumn> columns = inputTable.Columns;
            int colindex = rnd.Next(0, columns.Count);

            for (int i = 0; i <= colindex; i++)
            {
                if (columns[i].ColumnName == "PrimaryKey") continue;
                cmdText.Append(", ");
                cmdText.Append(columns[i].ColumnName);
            }

            cmdText.Append(" FROM \"");
            cmdText.Append(inputTable.TableName);
            cmdText.Append("\" WITH(NOLOCK) WHERE PrimaryKey ");

            // We randomly pick an operator from '>' or '=' to allow for randomization
            // of possible rows returned by this query. This approach *may* help 
            // in reducing the likelihood of multiple threads accessing same rows.
            // If multiple threads access same rows, there may be locking issues
            // which may be avoided because of this randomization.
            string op = rnd.NextBool() ? ">" : "=";
            cmdText.Append(op).Append(" ");

            string pName = GetParameterName("P0");
            cmdText.Append(pName);

            DbParameter param = DbFactory.CreateParameter();
            param.ParameterName = pName;
            param.Value = GetRandomPK(rnd, inputTable);
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            return cmdText.ToString();
        }
Beispiel #37
0
 public OrderPersistentObject(EDatabase database, string connectionString, TableMetadata mainTable) : base(database, connectionString, mainTable)
 {
 }
Beispiel #38
0
        /// <summary>
        /// Returns a random UPDATE command
        /// </summary>  
        public DbCommand GetUpdateCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("UPDATE \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" SET ");

            List<TableColumn> columns = table.Columns;
            int numColumns = rnd.Next(2, columns.Count);
            bool mostlyNull = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName == "PrimaryKey") continue;
                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD") continue;

                if (i > 1) cmdText.Append(", ");
                cmdText.Append(columns[i].ColumnName);
                cmdText.Append(" = ");

                if (mostlyNull && rnd.NextBool(0.9))
                {
                    cmdText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", (i + 1)), columns[i]);
                    cmdText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            cmdText.Append(" WHERE PrimaryKey = ");
            string pName = GetParameterName("P0");
            cmdText.Append(pName);
            DbParameter keyParam = DbFactory.CreateParameter();
            keyParam.ParameterName = pName;
            keyParam.Value = GetRandomPK(rnd, table);
            com.Parameters.Add(keyParam);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString(); ;
            return com;
        }
 protected virtual string GenerateCreateDatabaseSql(TableMetadata tableMetadata)
 {
     return(string.IsNullOrWhiteSpace(tableMetadata.Schema.Database)
         ? ""
         : $"CREATE SCHEMA IF NOT EXISTS `{GetNameSql(tableMetadata.Schema.Database)}` DEFAULT CHARACTER SET utf8mb4;");
 }
Beispiel #40
0
        /// <summary>
        /// Returns a random DELETE command
        /// </summary>    
        public DbCommand GetDeleteCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("DELETE FROM \"");

            List<TableColumn> columns = table.Columns;
            string pName = GetParameterName("P0");
            cmdText.Append(table.TableName);
            cmdText.Append("\" WHERE PrimaryKey = ");
            cmdText.Append(pName);

            DbParameter param = DbFactory.CreateParameter();
            param.ParameterName = pName;
            param.Value = GetRandomPK(rnd, table);
            com.Parameters.Add(param);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
Beispiel #41
0
 public SqlQuery From(TableMetadata table, string alias = null)
 {
     return(new SqlQuery(table, Transaction(TransactionType.NoTransaction), alias));
 }
Beispiel #42
0
        // method used to delete stress tables in the database
        protected void CleanupUserTables(TableMetadata tableMetadata)
        {
            string DropTable = "drop TABLE " + tableMetadata.TableName + ";";

            using (DataStressConnection conn = CreateConnection(null))
            {
                conn.Open();
                using (DbCommand com = conn.CreateCommand())
                {
                    try
                    {
                        com.CommandText = DropTable;
                        com.ExecuteNonQuery();
                    }
                    catch (Exception) { }
                }
            }
        }
Beispiel #43
0
        IEnumerator TestRestTableAsync()
        {
            Terminal.LogImportant("TestRestTableAsync (This is really slow)");

            // Make Table
            var tableName = Strings.RandomString(10);
            var meta1 = new TableMetadata
            {
                name = tableName,
                provisionLoad = ProvisionLoad.Balanced,
                provisionType = ProvisionType.Custom,
                throughput = new TableThroughput(1, 1),
                key = new TableKey(new Key("ID1", Key.DataType.STRING), new Key("ID2", Key.DataType.NUMBER)),
            };

            //CREATE
            Terminal.Log("CREATE " + tableName);
            var result1 = Repository.CreateTable(meta1);
            yield return StartCoroutine(result1.WaitRoutine());
            result1.ThrowIfFaulted();
            if (result1.Result.hasError)
                throw new Exception(result1.Result.error.message);

            //wait...
            var meta2 = WaitForTable(Repository, tableName);
            yield return StartCoroutine(meta2.WaitRoutine());
            meta2.ThrowIfFaulted();

            //LIST
            Terminal.Log("LIST");
            var result4 = Repository.ListTables();
            yield return StartCoroutine(result4.WaitRoutine());
            result4.ThrowIfFaulted();
            if (result4.Result.hasError)
                throw new Exception(result4.Result.error.message);
            Assert.IsTrue(result4.Result.data.tables.Any(), "request returned no results");

            //UPDATE
            Terminal.Log("UPDATE");
            meta2.Result.throughput = new TableThroughput(2, 2);
            meta2.Result.provisionType = ProvisionType.Custom;
            var result3 = Repository.UpdateTable(meta2.Result);
            yield return StartCoroutine(result3.WaitRoutine());
            result3.ThrowIfFaulted();
            if (result3.Result.hasError)
                throw new Exception(result3.Result.error.message);

            //wait...
            var meta3 = WaitForTable(Repository, tableName, 5000);
            yield return StartCoroutine(meta3.WaitRoutine());
            meta3.ThrowIfFaulted();

            //DELETE
            Terminal.Log("DELETE");
            var result5 = Repository.DeleteTable(tableName);
            yield return StartCoroutine(result5.WaitRoutine());
            result5.ThrowIfFaulted();
            if (result5.Result.hasError)
                throw new Exception(result5.Result.error.message);

            Terminal.LogSuccess("Test Success");
        }