示例#1
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);
            }
示例#2
0
        /// <summary>
        /// This method creates an internal execution graph for the expression and evaluates it.
        /// </summary>
        /// <param name="txpExpression">The txp expression as described in the PrintSyntax method.</param>
        public void Evaluate(string txpExpression)
        {
            _mainThread = Thread.CurrentThread;
            Console.CancelKeyPress += new ConsoleCancelEventHandler(ControlCHandler);

            #region COMMANDFILE
            // if the expression is in a file: @<filename>
            if (txpExpression.StartsWith("@")) {
                StringBuilder sb = new StringBuilder();
                StreamReader sr = new StreamReader(txpExpression.Substring(1));
                while (true) {
                    string line = sr.ReadLine();
                    if (line == null) break;

                    sb.Append(line);
                }

                sr.Close();
                txpExpression = sb.ToString();
            }
            #endregion

            char[] delims = "^".ToCharArray();
            int outSymb = txpExpression.LastIndexOf('>');

            // if there's no output symbol assume stdout e.g. > $
            string outputUri = "$";
            string inputExpression = txpExpression;

            if (outSymb >= 0) {
                outputUri = txpExpression.Substring(outSymb + 1).Trim();
                inputExpression = txpExpression.Substring(0, outSymb).Trim();
            }

            string[] pieces = inputExpression.Split(delims);
            for (int i = 0; i < pieces.Length; i++) {
                pieces[i] = pieces[i].Trim();
            }

            SourceStack sourceStack = new SourceStack();

            for (int i = 0; i < pieces.Length; i++) {
                string token = pieces[i];

                bool recognized = false;
                foreach (ExecutionOperator op in _executionOperators) {
                    if (op.TestToken(token)) {
                        op.Execute(sourceStack, _processor, token);
                        recognized = true;
                        break;
                    }
                }

                // unknown token
                if (!recognized) {
                    Console.WriteLine("OPERATORS");
                    for (int j = 0; j < pieces.Length; j++) {
                        Console.Write("<" + pieces[j] + ">");
                        if (j == i) Console.WriteLine(" <-- illegal operator");
                        else Console.WriteLine();
                    }

                    Environment.Exit(-1);
                }
            }

            if (sourceStack.Size != 1) {
                Console.WriteLine("invalid txpExpression (stack not empty)");
                Environment.Exit(-1);
            }

            RecordSource outputSource = sourceStack.Pop();

            // evaluate it
            try {
                outputSource.Write(outputUri);
            }

            // caused by control-c
            catch (ThreadAbortException) {
                outputSource.InternalSource.Close();
                Environment.Exit(0);
            }
        }
示例#3
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);
            }
示例#4
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);
            }
示例#5
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);
            }
示例#6
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);
 }
示例#7
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);
 }
示例#8
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);
 }
示例#9
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);
            }
示例#10
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);
            }
示例#11
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);
            }
示例#12
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);
 }
示例#13
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);
 }
示例#14
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);
            }
示例#15
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);
            }
示例#16
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);
 }