private void RefreshData() { if (_dataLock.TryEnterWriteLock(1000)) { try { Stopwatch watch = Stopwatch.StartNew(); _attributes = new AttributeTable(); _attributes.ConnectionString = _connString; _attributes.Load(); _facts = new FactTable(); _facts.ConnectionString = _connString; _facts.Load(); _contexts = new ContextTable(); _contexts.ConnectionString = _connString; _contexts.Load(); _resources = new ResourceTable(); _resources.ConnectionString = _connString; _resources.Load(); _lastUpdate = DateTime.UtcNow; watch.Stop(); Trace.WriteLine("QueryEngin.RefreshData: " + watch.ElapsedMilliseconds + "ms"); } finally { _dataLock.ExitWriteLock(); } } }
public void SimpleSelectFrom() { EvalStore c = new EvalStore(); Parser p = new Parser(); Expression e; Expression r; Stopwatch watch = Stopwatch.StartNew(); ContextTable contexts = new ContextTable(); contexts.Load(); AttributeTable attributes = new AttributeTable(); attributes.Load(); FactTable fact = new FactTable(); fact.Load(); watch.Stop(); Trace.WriteLine("LoadStaticData : " + watch.ElapsedMilliseconds + "ms"); StringBuilder q = new StringBuilder(); //q.AppendLine("SELECT Context, time, format('%2.2f', avg(value)), format('%2.2f', min(value)), format('%2.2f', max(value)), format('%2.2f', stdv(value)), count(value), HostName"); //q.AppendLine("FROM 277"); //q.AppendLine("WHERE time between now()-5d and now(), ResID=33, Context='C:' or Context='D:'"); //q.AppendLine("GROUP BY Context, time(24h)"); //q.AppendLine("ORDER by Context, time"); //q.AppendLine("LIMIT 30"); //q.AppendLine("FROM 'growth_rate_running_average' as V, 'growth_space' as V, 'journal_file_size' as V, 'journal_secondary_directory' as V"); q.AppendLine("SELECT HostName, AttrName, time, format('%2.2f',avg(value))"); q.AppendLine("FROM /^CPU/"); q.AppendLine("WHERE time BETWEEN now(-1d) AND now()"); q.AppendLine("GROUP BY HostName, AttrName, time(24h)"); q.AppendLine("HAVING avg(value)>30"); //q.AppendLine("ORDER BY HostName DESC, AttrName, time DESC"); //q.AppendLine("LIMIT 10 OFFSET 5"); //q.AppendLine("SELECT AttrID, time, min(value), max(value), mean(value), stdv(value)"); //q.AppendLine("FROM 79,80"); //q.AppendLine("WHERE time BETWEEN now(-7d) AND now(), ResID=15"); //q.AppendLine("GROUP BY AttrID, time(4h)"); //q.AppendLine("ORDER BY AttrID, time DESC"); //q.AppendLine("SELECT Context, time, AVG(value)"); //q.AppendLine("FROM \*\"); //q.AppendLine("WHERE time >= now()-5d and time < now(), ResID=23, AttrID=4125 | AttrID=123, hour(time) between '08' and '21' "); //q.AppendLine("GROUP BY Context, time(1d)"); //q.AppendLine("SELECT Context, time, AVG(value)"); //q.AppendLine("FROM \^CPU\"); //q.AppendLine("WHERE time >= now()-5d and time < now(), ResID=23, AttrID=4125 | AttrID=123, hour(time) between '08' and '21' "); //q.AppendLine("GROUP BY AttrID, Context, time(1d)"); //q.AppendLine("GROUP BY time(1d)"); // show peak avg group by day of the week for the past 30 day // peak time range // average on all Mondays, Tues, ..., of a month // concepts day of week // typical 9-noon monday cpu 50% //q.AppendLine("SELECT time, AVG(value)"); //q.AppendLine("FROM 101"); //q.AppendLine("WHERE time >= now()-10d and time < now(), ResID=3"); //q.AppendLine("GROUP BY time(4h)"); //q.AppendLine("SELECT time, AVG(value)"); //q.AppendLine("FROM 365,359"); //q.AppendLine("WHERE time >= now()-10d and time < now(), ResID=3"); //q.AppendLine("GROUP BY HostName, time(1d)"); e = p.Parse(q.ToString()); c.Enter(); c.Put<Table>(fact.Name, fact); c.Put<Table>(attributes.Name, attributes); c.Put<Table>(contexts.Name, contexts); //Dictionary<string, string> validFields = new Dictionary<string, string>(); //for (int i = 0; i < fact.Cols; i++) { // validFields.Add(fact.Schema[i].Name, null); //} //validFields.Add("contextid", null); //validFields.Add("time", null); //validFields.Add("value", null); //validFields.Add("severity", null); //c.Add(SelectStatement.VALID_FIELDS_KEY, validFields); r = e.Evaluate(c); Table t = (Table) r.Value; List<string> data = t.Print(); for (int i = 0; i < data.Count; i++) { Trace.WriteLine(data[i]); } c.Exit(); }
private void InitializeData(Object threadContext) { Stopwatch watch = Stopwatch.StartNew(); _parser = new Parser(); _store = new EvalStore(); StringBuilder cmd = new StringBuilder(); _attributes = new AttributeTable(); _attributes.Load(); statusStrip.Text = "Loading Attributes..."; _facts = new FactTable(); _facts.Load(); statusStrip.Text = "Loading Facts..."; _contexts = new ContextTable(); _contexts.Load(); statusStrip.Text = "Loading Contexts..."; _resources = new ResourceTable(); _resources.Load(); statusStrip.Text = "Loading Resources..."; watch.Stop(); _popupMenu = new AutocompleteMenu(queryCode); _popupMenu.SearchPattern = @"[\w\.:=!<>]"; _popupMenu.AllowTabKey = true; List<AutocompleteItem> items = new List<AutocompleteItem>(); for (int i = 0; i < _facts.ColumnDefinitions.Count; i++) { items.Add(new AutocompleteItem(_facts.ColumnDefinitions[i].Name)); } items.Add(new AutocompleteItem("select")); items.Add(new AutocompleteItem("where")); items.Add(new AutocompleteItem("order")); items.Add(new AutocompleteItem("group")); items.Add(new AutocompleteItem("by")); items.Add(new AutocompleteItem("limit")); items.Add(new AutocompleteItem("desc")); items.Add(new AutocompleteItem("asc")); items.Add(new AutocompleteItem("between")); for (int i=0; i<_resources.Cols; i++) { items.Add(new AutocompleteItem(_resources.ColumnDefinitions[i].Name)); } items.Add(new AutocompleteItem("Context")); items.Add(new AutocompleteItem("value")); items.Add(new AutocompleteItem("time")); foreach (string func in _parser.GetFunctionNames()) { SnippetAutocompleteItem n = new SnippetAutocompleteItem(func + "(^)"); n.ToolTipText = n.Text; n.ToolTipTitle = ""; items.Add(n); } _popupMenu.Items.SetAutocompleteItems(items); queryCode.Language = FastColoredTextBoxNS.Language.SQL; _store.Enter(); _store.Put<Element>("pi", new Element(3.131492653586)); _store.Put<Element>("e", new Element(2.71828183)); _store.Put<Table>(_facts.Name, _facts); _store.Put<Table>(_attributes.Name, _attributes); _store.Put<Table>(_contexts.Name, _contexts); _store.Put<Table>(_resources.Name, _resources); Trace.WriteLine("InitializeData : " + watch.ElapsedMilliseconds + "ms"); toolStrip1.Enabled = true; statusStrip.Text = "OK"; }
public void FactTableLoadTest() { FactTable f = new FactTable(); f.Load(); }
//static MemoryStream CreateStringStream(string value) //{ // byte[] bytes = System.Text.Encoding.UTF8.GetBytes(value); // MemoryStream ms = new MemoryStream(); // ms.Write(bytes, 0, bytes.Length); // ms.Seek(0, SeekOrigin.Begin); // return ms; //} //static void TestParser() //{ // Console.WriteLine("Enter statements followed by a ; and enter 'bye' to exit:"); // while (true) { // StringBuilder sb = new StringBuilder(); // while (true) { // string line = Console.ReadLine(); // if (line.ToUpper() == "BYE") return; // if (line == ";") break; // if (line.EndsWith(";")) { // sb.AppendLine(line.Substring(0, line.Length - 1)); // break; // } // sb.AppendLine(line); // } // using (MemoryStream ms = CreateStringStream(sb.ToString())) { // Parser p = new Parser(); // //Expression e = p.GetExpression(); // } // } //} //static string indent(int level) //{ // string x = ""; // for (int i = 0; i < level; i++) { // x = x + " "; // } // return x; //} static void TestParser() { Parser p = new Parser(); EvalStore c = new EvalStore(); StringBuilder cmd = new StringBuilder(); Stopwatch watch = Stopwatch.StartNew(); ContextTable contexts = new ContextTable(); contexts.Load(); AttributeTable attributes = new AttributeTable(); attributes.Load(); FactTable fact = new FactTable(); fact.Load(); watch.Stop(); Trace.WriteLine("LoadStaticData : " + watch.ElapsedMilliseconds + "ms"); try { c.Enter(); c.Put<Element>("pi", new Element(3.131492653586)); c.Put<Element>("e", new Element(2.71828183)); c.Put<Table>(fact.Name, fact); c.Put<Table>(attributes.Name, attributes); c.Put<Table>(contexts.Name, contexts); while (true) { while (true) { string v = Console.ReadLine(); v = v.Trim(); if (v.StartsWith(".")) { v = v.ToUpper(); switch (v) { case ".EXIT": return; } } if (v.EndsWith(";")) { v = v.Substring(0, v.Length - 1); cmd.AppendLine(v); break; } cmd.AppendLine(v); } string query = cmd.ToString(); cmd.Clear(); Expression s = null; try { s = p.Parse(query); } catch (Exception ex) { Console.WriteLine("Invalid syntax: " + ex.Message); } Expression r = null; try { r = s.Evaluate(c); Table t = (Table) r.Value; List<string> data = t.Print(); for (int i = 0; i < data.Count; i++) { Console.WriteLine(data[i]); } } catch (Exception ex) { Console.WriteLine("Error evaluating statement: " + ex.Message); } //Console.WriteLine(r); } } finally { c.Exit(); } }
private static void TestLoadTable() { FactTable ft = new FactTable(); ft.Load(); }