Example #1
0
        /// <summary>
        /// Parser for evaluating a txp expression.
        /// </summary>
        internal ExpressionParser(TStoreProcessor processor)
        {
            _executionOperators = new List<ExecutionOperator>();
            _processor = processor;

            #region OPERATORS
            _executionOperators.Add(new InputOp());
            _executionOperators.Add(new FilterFileOp());
            _executionOperators.Add(new SortOp());
            _executionOperators.Add(new ReduceOp());
            _executionOperators.Add(new WhereClauseOp());
            _executionOperators.Add(new SearchOp());
            _executionOperators.Add(new TableOp());
            _executionOperators.Add(new CountOp());
            _executionOperators.Add(new DataOp());
            _executionOperators.Add(new HeadOp());
            _executionOperators.Add(new RandomOp());
            _executionOperators.Add(new AboutOp());
            _executionOperators.Add(new InnerJoinOp());
            _executionOperators.Add(new LeftOuterJoinOp());
            _executionOperators.Add(new FilterLeftInRightOp());
            _executionOperators.Add(new FilterLeftNotInRightOp());
            _executionOperators.Add(new SortedMergeOp());
            _executionOperators.Add(new ConcatOp());
            #endregion
        }
Example #2
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = sortReduceRegex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("Syntax error in Sort()");
                    Environment.Exit(1);
                }

                string direction = m.Groups["d"].ToString().Trim();
                bool ascending = true;
                if (direction.Equals("-")) {
                    ascending = false;
                }

                RecordSource source = stack.Pop();
                source.SortReduce(ascending, false); // default to no reduction.  If reduction comes next, this is updated.
                stack.Push(source);
            }
Example #3
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in Merge()");
                    Environment.Exit(0);
                }

                string direction = m.Groups["d"].ToString().Trim();
                bool ascending = true;
                if (direction.Equals("-")) {
                    ascending = false;
                }

                int nary = int.Parse(m.Groups["n"].ToString());

                // set the direction of the empty source so that a sorter doesn't get inserted
                // to sort nothing.

                RecordSource source = processor.EmptySource(true, ascending);
                for (int i = 0; i < nary; i++) {
                    RecordSource next = stack.Pop();
                    if (ascending) source = processor.Pair(next, source, PairOperation.MergeAscend);
                    else source = processor.Pair(next, source, PairOperation.MergeDescend);
                }

                stack.Push(source);
            }
Example #4
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     RecordSource source = stack.Pop();
     token = token.Trim("'".ToCharArray());
     source = processor.QueryKey(source, token);
     stack.Push(source);
 }
Example #5
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     Match m = sortReduceRegex.Match(token);
     if (!m.Success) {
         Console.WriteLine("Syntax error in Reduce");
         Environment.Exit(1);
     }
     RecordSource source = stack.Pop();
     source.Reduce();
     stack.Push(source);
 }
Example #6
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in Random()");
                    Environment.Exit(0);
                }

                string number = m.Groups["l"].ToString().Trim();
                int seed = 31415927;

                if (number.IndexOf(',') > 0) {
                    string[] pieces = number.Split(',');
                    number = pieces[0].Trim();
                    seed = int.Parse(pieces[1].Trim());
                }

                int numToKeep = int.Parse(number);

                RecordSource source = stack.Pop();
                source.Random(numToKeep, seed);
                stack.Push(source);
            }
Example #7
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     // case: cs sharp filter file
     RecordSource source = stack.Pop();
     source = processor.GetStatistics(source);
     stack.Push(source);
 }
Example #8
0
        public DynamicRecordFilter(TStoreProcessor processor, string whereClause)
        {
            _whereClause = whereClause;
            _passThruInputSorting = true;  // since a where clause can't change key order
            _processor = processor;

            // for a whereClause we have to wait to on compiling the dynamic filter
            // until we have the first record (so we know how to cast the incoming
            // record type).  So _filter remains null

            ProcessTreeComment = "[OrderPreserved: True whereClause:" + _whereClause + "]";
        }
Example #9
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in Head()");
                    Environment.Exit(0);
                }

                long limit = long.Parse(m.Groups["l"].ToString().Trim());

                RecordSource source = stack.Pop();
                source.Limit(limit);
                stack.Push(source);
            }
Example #10
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     RecordSource right = stack.Pop();
     RecordSource left = stack.Pop();
     RecordSource source = processor.Pair(left, right, PairOperation.FilterLeftNotInRight);
     stack.Push(source);
 }
Example #11
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     // case: cs sharp filter file
     RecordSource source = stack.Pop();
     source = processor.FilterByCSharpSnippet(source, token);
     stack.Push(source);
 }
Example #12
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in ToLine()");
                    Environment.Exit(0);
                }

                string keyExpression = m.Groups["k"].ToString().Trim();

                RecordSource source = stack.Pop();
                string sourceName = Path.GetFileNameWithoutExtension(source.CurrentSourceName);
                ToDataFilter filter = new ToDataFilter(keyExpression, processor.TableColumnSeparator, sourceName);
                source = processor.Filter(source, filter);
                stack.Push(source);
            }
Example #13
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in Concat()");
                    Environment.Exit(0);
                }

                int arity = int.Parse(m.Groups["a"].ToString());
                if (arity > stack.Size) {
                    Console.WriteLine("Concat arity greater than stack size.");
                    Environment.Exit(0);
                }

                RecordSource right = stack.Pop();
                for (int i = 1; i < arity; i++) {
                    RecordSource left = stack.Pop();
                    right = processor.Pair(left, right, PairOperation.CatLeftThenRight);
                }

                stack.Push(right);
            }
Example #14
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in ToTable()");
                    Environment.Exit(0);
                }

                string keyExpression = m.Groups["k"].ToString().Trim();
                string[] headers = null;
                if (keyExpression.IndexOf(',') >= 0) {
                    string[] pieces = keyExpression.Split(',');
                    keyExpression = pieces[0].Trim();
                    headers = pieces[1].Trim().Split('+');
                }

                RecordSource source = stack.Pop();
                string sourceName = Path.GetFileNameWithoutExtension(source.CurrentSourceName);
                ToTableFilter filter = new ToTableFilter(keyExpression, processor.TableColumnSeparator, sourceName);
                filter.ColumnNames = headers;
                source = processor.Filter(source, filter);
                stack.Push(source);
            }
Example #15
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                // case: uri's (flatfile, directory, tstore, recordFile)

                RecordSource source = processor.Input(token);
                stack.Push(source);
            }
Example #16
0
            public void Execute(SourceStack stack, TStoreProcessor processor, string token)
            {
                Match m = regex.Match(token);
                if (!m.Success) {
                    Console.WriteLine("syntax error in Where()");
                    Environment.Exit(0);
                }

                string clause = m.Groups["c"].ToString().Trim();
                RecordSource source = stack.Pop();
                source = processor.SelectFilter(source, clause);
                stack.Push(source);
            }
Example #17
0
 public void Execute(SourceStack stack, TStoreProcessor processor, string token)
 {
     RecordSource right = stack.Pop();
     RecordSource left = stack.Pop();
     RecordSource source = processor.LeftOuterJoin(left, right);
     stack.Push(source);
 }
Example #18
0
        public DynamicRecordFilter(string cSharpSnippetFile, TStoreProcessor processor)
        {
            _cSharpSnippetFile = cSharpSnippetFile;
            // since the filter could change key order
            _processor = processor;

            // we can pass this early because the snippet's already written and it was
            // upto the writer to make sure the input/output types are corrrect.

            // if the file exists then we can compile it now because it's "code complete"
            // and we need to get the keyOrderIsPreserved;  Bummer, but we need to compile
            // it later when our internalSource is valid so that the filter has access to
            // it.  So we toss it after we get KeyOrderIsPreserved, and compile it
            // again at MoveNext time.

            if (File.Exists(_cSharpSnippetFile)) {
                IRecordFilter filter = _GetFilter(null, _assemblyLocations);
                _passThruInputSorting = filter.KeyOrderIsPreserved;
                _filterType = filter.GetType().ToString();
                if (_filterType.StartsWith("Microsoft.TMSN.Data.")) {
                    _filterType = _filterType.Remove(0, 20);
                }

                ProcessTreeComment = "[OrderPreserved:" + _passThruInputSorting + " filter: " + _filterType + "]";
            }

            else {
                _passThruInputSorting = true;
            }
        }
Example #19
0
 /// <summary>
 /// construction of Sources only available through TStoreProcessor factory methods
 /// </summary>
 /// <param name="processor"></param>
 internal RecordSource(TStoreProcessor processor)
 {
     Processor = processor;
 }