public override StoredProcedureResult Generate() { var delim = "," + Environment.NewLine; string Schema = Atom.AdditionalInfo.Schema, Params = string.Empty, SprocSuffix = "GetAll", TableName = Atom.Name; var plan = new QueryPlan { QueryMembers = Atom.Members.Where(IsQueryableColumn).Select(AliasedAtomMemberInfo.FromAtomMemberInfo), References = { new SimpleReference(Atom) } }; var template = GenerateQuerySproc(Schema, TableName, SprocSuffix, Params, plan); var name = $"{Schema}.{TableName}_GetAll"; return(new StoredProcedureResult { Name = name, Sql = template, AccessorMetadata = new SqlAccessorMetadata { BaseAtom = ProjectedAtomRoot.FromAtom(Atom), QueryType = QueryType.GetAll, QueryKey = null, Name = name } }); }
private void HandleDMLPlan(QueryPlan plan, ref string resultString, ref bool planFailed, List <Row> rowList, ref int rows, ref int totalRows) { resultString += " ------------ " + Environment.NewLine; StepResult stepResult = null; if (!(plan.OriginalStatement is UpdateStatement)) { plan.Steps.Reverse(); } foreach (var step in plan.Steps) { stepResult = ExecuteStep(step, plan.DatabaseName, out rows); if (stepResult.IsValid == false) { planFailed = true; resultString = stepResult.ErrorMessage; break; } else { if (stepResult.RowsAffected > 0) { rows = stepResult.RowsAffected; } } totalRows += rows; rowList.AddRange(stepResult.Rows); } }
private PartialFindResult <Album> FindAdvanced( ISession session, QueryPlan <Album> queryPlan, PagingProperties paging, AlbumSortRule sortRule) { if (!queryPlan.Any()) { return(new PartialFindResult <Album>(new Album[] {}, 0)); } IQueryable <Album> albums = null; foreach (var filter in queryPlan) { if (albums == null) { albums = filter.Query(session); } else { albums = filter.Filter(albums, session); } } var result = albums .Skip(paging.Start) .Take(paging.MaxEntries) .ToArray(); return(new PartialFindResult <Album>(result, albums.Count())); }
public QueryPlan GeneratePlan(FrostIDMLStatement statement) { var plan = new QueryPlan(); if (statement is SelectStatement) { plan = new SelectQueryPlanGenerator(_process).GeneratePlan((statement as SelectStatement)); } if (statement is InsertStatement) { plan = new InsertQueryPlanGenerator(_process).GeneratePlan((statement as InsertStatement)); } if (statement is UpdateStatement) { plan = new UpdateQueryPlanGenerator(_process).GeneratePlan((statement as UpdateStatement)); } if (statement is DeleteStatement) { plan = new DeleteQueryPlanGenerator(_process).GeneratePlan((statement as DeleteStatement)); } return(plan); }
public void Enqueue_And_Copy() { // arrange var queue = new SuspendedWorkQueue(); var task1 = new MockExecutionTask(); var task2 = new MockExecutionTask(); // act queue.Enqueue(task1); queue.Enqueue(task2); // assert var work = new WorkQueue(); var plan = new QueryPlan(new MockQueryPlanStep()); var state = new Mock <IQueryPlanState>(); var stateMachine = new QueryPlanStateMachine(); stateMachine.Initialize(state.Object, plan); queue.CopyTo(work, work, stateMachine); Assert.True(work.TryTake(out IExecutionTask task)); Assert.Same(task1, task); Assert.True(work.TryTake(out task)); Assert.Same(task2, task); }
public static void Run( [QueueTrigger("WebPlans", Connection = "AzureWebJobsStorage")] QueryPlan queryPlan, TraceWriter log, IBinder binder) { log.Info($"Received an query plan: Plan {queryPlan.PlanId} from Product {queryPlan.ProductId}"); var blob = new BlobAttribute($"parsedplans/{queryPlan.PlanId}.txt") { Connection = "AzureWebJobsStorage" }; using (var outputBlob = binder.Bind <TextWriter>(blob)) { outputBlob.WriteLine($"PlanId: {queryPlan.PlanId}"); outputBlob.WriteLine($"ProductId: {queryPlan.ProductId}"); outputBlob.WriteLine($"Email: {queryPlan.Email}"); outputBlob.WriteLine($"Plan: {queryPlan.Plan}"); outputBlob.WriteLine($"PurchaseDate: {System.DateTime.UtcNow}"); var md5 = System.Security.Cryptography.MD5.Create(); var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(queryPlan.Email + "secret")); outputBlob.WriteLine($"SecretCode: {System.BitConverter.ToString(hash).Replace("-", "")}"); } }
public QueryPlan GeneratePlan(FrostIDMLStatement statement, string databaseName) { QueryPlan plan = GeneratePlan(statement); plan.DatabaseName = databaseName; return(plan); }
/// <summary> /// Subscribes to the pub/sub-system and creates a new <see cref="Subscription"/> /// instance representing that subscriptions. /// </summary> /// <param name="operationContextPool"> /// The operation context pool to rent context pools for execution. /// </param> /// <param name="queryExecutor"> /// The query executor to process event payloads. /// </param> /// <param name="requestContext"> /// The original request context. /// </param> /// <param name="queryPlan"> /// The subscription query plan. /// </param> /// <param name="subscriptionType"> /// The object type that represents the subscription. /// </param> /// <param name="rootSelections"> /// The operation selection set. /// </param> /// <param name="resolveQueryRootValue"> /// A delegate to resolve the subscription instance. /// </param> /// <param name="executionDiagnosticsEvents"> /// The internal diagnostic events to report telemetry. /// </param> /// <returns> /// Returns a new subscription instance. /// </returns> public static async ValueTask <Subscription> SubscribeAsync( ObjectPool <OperationContext> operationContextPool, QueryExecutor queryExecutor, IRequestContext requestContext, QueryPlan queryPlan, ObjectType subscriptionType, ISelectionSet rootSelections, Func <object?> resolveQueryRootValue, IExecutionDiagnosticEvents executionDiagnosticsEvents) { var subscription = new Subscription( operationContextPool, queryExecutor, requestContext, queryPlan, subscriptionType, rootSelections, resolveQueryRootValue, executionDiagnosticsEvents); subscription._subscriptionScope = executionDiagnosticsEvents.ExecuteSubscription(subscription); subscription._sourceStream = await subscription.SubscribeAsync().ConfigureAwait(false); return(subscription); }
public static void CompareQueryPlans(QueryPlan expectedPlan, QueryPlan actualPlan) { IDictionary <TableLookupIndexReqKey, TableLookupIndexReqKey> indexNameMapping = new Dictionary <TableLookupIndexReqKey, TableLookupIndexReqKey>(); CompareIndexes(expectedPlan.IndexSpecs, actualPlan.IndexSpecs, indexNameMapping); CompareExecNodeSpecs(expectedPlan.ExecNodeSpecs, actualPlan.ExecNodeSpecs, indexNameMapping); }
/// <summary> /// Executes the given query plan over the dataset, iterating over and returning the /// results. /// </summary> /// <param name="plan">The descriptive query plan to execute.</param> /// <param name="materialize">if set to <c>true</c>, materialize the external representation of the results produced.</param> /// <returns> /// An iterator over the query results. /// </returns> public IEnumerable <BindingSet> Query(QueryPlan plan, bool materialize = true) { if (m_state == State.Open) { var rootOperator = GetOperator(plan.Root); BindingSet next = null; while (rootOperator.HasNext) { next = rootOperator.Next(); if (materialize) { foreach (var item in next.Bindings) { item.Value.SetTextValue(m_dict); } } yield return(next); } rootOperator.Dispose(); } else { throw new InvalidOperationException("Database is not in open state!"); } }
public JoinSetComposerPrototypeImpl(string statementName, string statementId, OuterJoinDesc[] outerJoinDescList, ExprNode optionalFilterNode, EventType[] streamTypes, string[] streamNames, StreamJoinAnalysisResult streamJoinAnalysisResult, Attribute[] annotations, HistoricalViewableDesc historicalViewableDesc, ExprEvaluatorContext exprEvaluatorContext, QueryPlanIndex[] indexSpecs, QueryPlan queryPlan, HistoricalStreamIndexList[] historicalStreamIndexLists, bool joinRemoveStream, bool isOuterJoins, TableService tableService) { _statementName = statementName; _statementId = statementId; _outerJoinDescList = outerJoinDescList; _optionalFilterNode = optionalFilterNode; _streamTypes = streamTypes; _streamNames = streamNames; _streamJoinAnalysisResult = streamJoinAnalysisResult; _annotations = annotations; _historicalViewableDesc = historicalViewableDesc; _exprEvaluatorContext = exprEvaluatorContext; _indexSpecs = indexSpecs; _queryPlan = queryPlan; _historicalStreamIndexLists = historicalStreamIndexLists; _joinRemoveStream = joinRemoveStream; _isOuterJoins = isOuterJoins; _tableService = tableService; }
/// <summary> /// 替换查询参数中的上下文参数 /// </summary> /// <param name="queryPlan"></param> public void ReplaceQueryVariableParam(QueryPlan queryPlan) { if (queryPlan == null) { return; } if (queryPlan.Fields != null) { foreach (var queryPlanField in queryPlan.Fields) { if (queryPlanField.FieldQueryType == FieldQueryType.Fixed) { queryPlanField.FieldValue = queryPlanField.Value; } else { var contextParamValue = _pageContext.GetContextParamValue(queryPlanField.Value.Replace("@", "")); if (contextParamValue == null) { queryPlanField.FieldValue = queryPlanField.Value; } else { queryPlanField.FieldValue = contextParamValue; } } } } }
// TO DO: refactor public QueryPlan GeneratePlan(SelectStatement statement) { _statement = statement; var plan = new QueryPlan(); if (statement.HasWhereClause) { var whereClauseGenerator = new WhereClausePlanGenerator(_process, _level); plan.Steps.AddRange(whereClauseGenerator.GetPlanSteps(statement.WhereClause)); } else { plan.Steps.Add(GetTableStep(statement)); } // TO DO: We should make the final rows equal the columns in the SELECT statement plan.Columns = statement.SelectList; int maxStep = 0; var columnOutput = new ColumnOutputStep(); foreach (var step in plan.Steps) { if (step.Level > maxStep) { maxStep = step.Level; } } columnOutput.Level = maxStep + 1; return(plan); }
public static QueryPlan AssertJoinAndReset() { Assert.IsTrue(Joins.Count == 1); QueryPlan join = Joins[0]; Reset(); return(join); }
public QueryPlan GeneratePlan(DeleteStatement statement) { _plan = new QueryPlan(); _plan.Steps.AddRange(GetWhereClauseSteps(statement)); _plan.Steps.AddRange(GetDeleteSteps(statement)); return(_plan); }
private PartialFindResult <Album> FindAdvanced( ISession session, QueryPlan <Album> queryPlan, PagingProperties paging, AlbumSortRule sortRule) { var querySource = new QuerySourceSession(session); var processor = new QueryProcessor <Album>(querySource); return(processor.Query(queryPlan, paging, q => AlbumSearchSort.AddOrder(q, sortRule, LanguagePreference))); }
/// <summary> /// Selects a join type (merge or hash) for the given join edge, and returns a join node /// which merges the left and right nodes of the given join edge. /// </summary> /// <param name="joinEdge">The join edge.</param> /// <returns> /// The join node merging the left and right nodes from the given join edge. /// </returns> public jg::Node ChooseJoinType(jg::Edge joinEdge) { // // get the operators for the left and right nodes. if a node does not have an operator, // then it must have an SAP and we select a scan operator for it here. Operator leftOp, rightOp; if (joinEdge.Left.HasOperator) { leftOp = joinEdge.Left.Operator; } else { leftOp = ChooseScan(joinEdge.Left); } if (joinEdge.Right.HasOperator) { rightOp = joinEdge.Right.Operator; } else { rightOp = ChooseScan(joinEdge.Right); } // // create a new, empty join node var joinNode = new jg::Node(null, null); if (CanDoMergeJoin(leftOp, rightOp)) { // // heuristic: if we can do a merge join, do so var leftSortOrder = leftOp.GetOutputSortOrder(); var rightSortOrder = rightOp.GetOutputSortOrder(); var joinVars = new HashSet <long>(leftSortOrder); joinVars.IntersectWith(rightSortOrder); // // the merge joinoperator is then constructed in the Datastructures.Queries.QueryPlan // class. joinNode.Operator = QueryPlan.GetMergeJoin(leftOp, rightOp, joinVars.ToArray()); } else { // // if we cannot do a merge join, do a hash join instead. the hash join operator is // then constructed in the Datastructures.Queries.QueryPlan class. joinNode.Operator = QueryPlan.GetHashJoin(leftOp, rightOp); } return(joinNode); }
public override StoredProcedureResult Generate() { var delim = "," + Environment.NewLine; var queryKey = _byKey; if (_byKey.HasReference && _byKey.Reference.IsReferenceToHiddenPrimaryKey) { queryKey = queryKey.Reference.TargetAtomAlternateKey; } string sprocSuffix = _isUnique ? $"GetOneBy{queryKey.Name}" : $"GetBy{queryKey.Name}"; string Schema = Atom.AdditionalInfo.Schema, Params = GetTypedSprocParam(queryKey), TableName = Atom.Name, Key = queryKey.Name; var plan = new QueryPlan { QueryMembers = Atom.Members.Where(IsQueryableColumn).Select(AliasedAtomMemberInfo.FromAtomMemberInfo), References = { new SimpleReference(Atom) }, Filters = { new AtomFilter { FilterValue = "@" + Key, Member = queryKey } } }; if (queryKey != _byKey) { var simpleRef = new SimpleReference(queryKey.Atom); plan.References = new List <Reference> { simpleRef, new ResolvedReference(Atom, new List <Reference> { simpleRef }) }; } var template = GenerateQuerySproc(Schema, TableName, sprocSuffix, Params, plan); var name = $"{Schema}.{TableName}_{sprocSuffix}"; return(new StoredProcedureResult { Name = name, Sql = template, AccessorMetadata = new SqlAccessorMetadata { BaseAtom = ProjectedAtomRoot.FromAtom(Atom), QueryType = _isUnique ? QueryType.GetOne : QueryType.GetBy, QueryKey = queryKey, Name = name } }); }
public void GetText_Returns_SelectText() { var mapping = new PersonMap(); mapping.ExecuteMapping(); var select = new QueryPlan(mapping, null, null); select.CreatePlanParameter().SqlText.ToUpper().Should().Be("SELECT ID, NAME, AGE FROM PERSON"); }
private SupportQueryPlanBuilder(int numStreams) { QueryPlanIndex[] indexes = new QueryPlanIndex[numStreams]; for (int i = 0; i < indexes.Length; i++) { indexes[i] = new QueryPlanIndex(new LinkedHashMap <TableLookupIndexReqKey, QueryPlanIndexItem>()); } _queryPlan = new QueryPlan(indexes, new QueryPlanNode[numStreams]); }
public QueryPlan BuildExecutionPlan(ParsedQuery parsedQuery, bool freeCache) { lock (_gate) { BornOrRessurectIfDead(); QueryPlan queryPlan = _documentIndex.BuildExecutionPlan(parsedQuery, freeCache); queryPlan.AddLock(this); return(queryPlan); } }
public static string AsString(this QueryPlan queryPlan) { if (queryPlan == null) throw new ArgumentNullException(nameof(queryPlan)); using (var writer = new StringWriter()) { writer.WriteLine($"QueryPlan: '{queryPlan.Alias}' NodeType: '{queryPlan.NodeType}' PlanRows:{queryPlan.PlanRows} PlanWidth:{queryPlan.PlanWidth} RelationName: '{queryPlan.RelationName}' StartupCost:{queryPlan.StartupCost} TotalCost:{queryPlan.TotalCost}"); return writer.ToString(); } }
public static void ShouldNotHaveAnyTableScans(this QueryPlan queryPlan, string?customMessage = null) { var flattenedRelOps = queryPlan.GetFlattenedRelOps(); var tablesScans = flattenedRelOps.Where(i => i.PhysicalOp == PhysicalOp.TableScan).ToList(); if (tablesScans.Any()) { throw new ShouldAssertException(new ExpectedActualShouldlyMessage("PhysicalOp == PhysicalOp.TableScan", tablesScans, customMessage).ToString()); } }
public void TestTypedExplainFromLinqQueryDetectsIndexedCursor() { mongo.PeopleCollection.CreateIndex(IndexKeys <Person> .Ascending(c => c.Age)); QueryPlan typedExplain = mongo.People .Where(p => p.Age > 30) .Take(1) .ExplainTyped(); Assert.AreEqual(CursorType.BtreeCursor, typedExplain.CursorType); }
public void TestTypedExplainVerbose() { SafeDropIndex(IndexKeys <Person> .Ascending(c => c.Age)); QueryPlan typedExplain = mongo.People .Where(p => p.Age > 30) .Take(1) .ExplainTyped(verbose: true); Assert.AreEqual(CursorType.BasicCursor, typedExplain.CursorType); }
public void GetText_Returns_SelectFormatedText() { var mapping = new FormatedPersonMap(); mapping.ExecuteMapping(); var select = new QueryPlan(mapping, null, null); select.CreatePlanParameter().SqlText.ToUpper().Should().Be("SELECT ID, ASBINARY(NAME) AS NAME, AGE FROM PERSON"); }
public static void AssertJoinOneStreamAndReset(bool unique) { Assert.IsTrue(Joins.Count == 1); QueryPlan join = Joins[0]; QueryPlanIndex first = join.IndexSpecs[1]; TableLookupIndexReqKey firstName = first.Items.Keys.First(); QueryPlanIndexItem index = first.Items.Get(firstName); Assert.AreEqual(unique, index.IsUnique); Reset(); }
protected override void ExecuteStatement(ExecutionContext context) { // We have to execute the plan to get the TableInfo that represents the // result of the view execution. var table = QueryPlan.Evaluate(context.Request); var tableInfo = table.TableInfo.Alias(ViewName); var viewInfo = new ViewInfo(tableInfo, QueryExpression, QueryPlan); context.Request.Query.DefineView(viewInfo, ReplaceIfExists); }
private void TryAssertion(EPServiceProvider epService, string epl, QueryPlan expectedPlan) { SupportQueryPlanIndexHook.Reset(); epl = INDEX_CALLBACK_HOOK + epl; epService.EPAdministrator.CreateEPL(epl); var actualPlan = SupportQueryPlanIndexHook.AssertJoinAndReset(); SupportQueryPlanIndexHelper.CompareQueryPlans(expectedPlan, actualPlan); epService.EPAdministrator.DestroyAllStatements(); }
/// <summary> /// 查詢條件擴展呼叫 /// </summary> /// <param name="query">查詢計劃</param> /// <param name="name">查詢條件擴展方法名</param> /// <param name="parms">其他傳入參數</param> private void ExtensionQuery(QueryPlan <T> query, string name, params string[] parms) { MethodInfo method = GetType().GetMethod(name, BindingFlags.Instance | BindingFlags.Public); if (method == null) { throw new Exception(string.Format("在DataAccess找不到方法{0}", name)); } method.Invoke(this, new object[] { query, parms }); }
public static FrostPromptPlan Convert(this QueryPlan plan) { var result = new FrostPromptPlan(); foreach (var step in plan.Steps) { result.PlanText += step.GetResultText() + Environment.NewLine; } return(result); }
private static void PrettyPrint(QueryPlan queryPlan) { var json = Newtonsoft.Json.JsonConvert.DeserializeObject(queryPlan.ToString()); Console.WriteLine(json); }
/// <summary> /// Get select plan for a given type /// </summary> /// <param name="type">Type</param> /// <returns>plan</returns> public virtual IQueryPlan GetQueryPlan(Type type) { var map = this._mappingManager.GetMapping(type); var query = new QueryPlan(map, this._queryTranslator, this._typeRegister); return query; }