Exemplo n.º 1
0
        public void Execute(TextWriter outputStream, TextWriter logStream, GqlEngineState gqlEngineState)
        {
            GqlQueryState gqlQueryState = new GqlQueryState (gqlEngineState);

            IntoProvider.DumpProviderToStream (gqlQuery, outputStream, gqlQueryState, gqlEngineState.ColumnDelimiter, gqlEngineState.Heading,
                gqlEngineState.AutoSize, FileOptionsIntoClause.FormatEnum.DontCare, cultureInfo);
        }
Exemplo n.º 2
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     endOfQuery = false;
     record = new ProviderRecord (this, true);
     record.Source = "(nullProvider)";
     record.LineNo = 0;
 }
Exemplo n.º 3
0
        public override void OnInitialize(GqlQueryState gqlQueryState, out string[] files, out long skip)
        {
            string fileName = fileOptions.FileName.EvaluateAsData (gqlQueryState).ToDataString (dataComparer.CultureInfo);

            string path = Path.GetDirectoryName (fileName);
            string searchPattern = Path.GetFileName (fileName);
            SearchOption searchOption;
            if (fileOptions.Recurse)
                searchOption = SearchOption.AllDirectories;
            else
                searchOption = SearchOption.TopDirectoryOnly;

            path = Path.Combine (gqlQueryState.CurrentDirectory, path);
            files = Directory.GetFiles (path + Path.DirectorySeparatorChar, searchPattern, searchOption);

            if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.Asc
                || fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.FileNameAsc)
                files = files.Select (p => new FileInfo (p)).OrderBy (p => p.Name, dataComparer.StringComparer).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.Desc
                     || fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.FileNameDesc)
                files = files.Select (p => new FileInfo (p)).OrderByDescending (p => p.Name, dataComparer.StringComparer).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.ModificationTimeAsc)
                files = files.Select (p => new FileInfo (p)).OrderBy (p => p.LastWriteTime).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.ModificationTimeDesc)
                files = files.Select (p => new FileInfo (p)).OrderByDescending (p => p.LastWriteTime).Select (p => p.FullName).ToArray ();

            skip = fileOptions.Skip;
        }
Exemplo n.º 4
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     this.gqlQueryState = gqlQueryState;
     currentProvider = 0;
     totalLineNo = 0;
     providers [0].Initialize (gqlQueryState);
 }
Exemplo n.º 5
0
        public IData EvaluateAsData(GqlQueryState gqlQueryState)
        {
            Variable variable;
            if (!gqlQueryState.Variables.TryGetValue (this.variable, out variable))
                throw new InvalidOperationException (string.Format ("Variable '{0}' not declared", this.variable));

            return variable.Value;
        }
Exemplo n.º 6
0
 public GqlQueryState(GqlQueryState other, bool newVariableScope)
     : this()
 {
     this.CurrentDirectory = other.CurrentDirectory;
     this.TempDirectory = other.TempDirectory;
     this.CurrentExecutionState = other.CurrentExecutionState;
     if (newVariableScope)
         this.Variables = new Dictionary<string, Variable> (other.Variables);
     else
         this.Variables = other.Variables;
     this.Warnings = other.Warnings;
 }
Exemplo n.º 7
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            provider.Initialize (gqlQueryState);

            if (heading == GqlEngineState.HeadingEnum.On || heading == GqlEngineState.HeadingEnum.OnWithRule) {
                if (!provider.GetNextRecord ())
                    return;

                columnNameList = provider.Record.Columns.Select (p => new ColumnName (p.ToString ())).ToArray ();

                if (heading == GqlEngineState.HeadingEnum.OnWithRule) {
                    provider.GetNextRecord ();
                }
            }
        }
Exemplo n.º 8
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            OnInitialize (gqlQueryState, out files, out skip);

            if (files.Length == 0) {
                gqlQueryState.Warnings.Add (
                    new Exception ("No input files are matching")
                );
            }

            this.gqlQueryState = gqlQueryState;
            currentFile = -1;
            totalLineNo = 0;
            provider = null;
        }
Exemplo n.º 9
0
        public override void OnInitialize(GqlQueryState gqlQueryState, out string[] files, out long skip)
        {
            fileSubqueryProvider.Initialize (gqlQueryState);
            try {
                List<string> fileList = new List<string> ();
                while (fileSubqueryProvider.GetNextRecord ()) {
                    fileList.Add (fileSubqueryProvider.Record.Columns [0].ToDataString (cultureInfo));
                }
                files = fileList.ToArray ();
            } finally {
                fileSubqueryProvider.Uninitialize ();
            }

            skip = 0;
        }
Exemplo n.º 10
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            this.gqlQueryState = new GqlQueryState (gqlQueryState, true);

            for (int i = 0; i < parameters.Length; i++) {
                IData result = parameters [i].EvaluateAsData (gqlQueryState);
                Variable variable = new Variable ();
                variable.Name = parameterNames [i];
                variable.Type = result.GetType ();
                variable.Value = result;

                this.gqlQueryState.Variables [variable.Name] = variable;
            }

            provider.Initialize (this.gqlQueryState);
        }
Exemplo n.º 11
0
 public IData EvaluateAsData(GqlQueryState gqlQueryState)
 {
     GqlQueryState gqlQueryState2 = new GqlQueryState (gqlQueryState);
     try {
         provider.Initialize (gqlQueryState2);
         if (!provider.GetNextRecord ()) {
             Type type = GetResultType ();
             return DataTypeUtil.GetDefaultFromDataType(GetResultType());
         }
         if (provider.Record.Columns.Length != 1)
             throw new InvalidOperationException ("Expression subquery didn't return exactly 1 column");
         return provider.Record.Columns [0];
     } finally {
         provider.Uninitialize ();
     }
 }
Exemplo n.º 12
0
        public static void DumpProviderToStream(IProvider provider, Stream outputStream, GqlQueryState gqlQueryState, 
            string columnDelimiter, string recordDelimiter, GqlEngineState.HeadingEnum heading,
            FileOptionsIntoClause.FormatEnum format,
            CultureInfo cultureInfo)
        {
            using (TextWriter writer = new StreamWriter (outputStream, System.Text.Encoding.GetEncoding (0))) {
                writer.NewLine = recordDelimiter;

                DumpProviderToStream (
                    provider,
                    writer,
                    gqlQueryState,
                    columnDelimiter,
                    heading,
                    0,
                    format,
                    cultureInfo
                );
            }
        }
Exemplo n.º 13
0
 public void Process(StateBin state, GqlQueryState gqlQueryState)
 {
     throw new Exception (string.Format ("Aggregation not supported on expression {0}", this.GetType ().ToString ()));
 }
Exemplo n.º 14
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     provider.Initialize (gqlQueryState);
 }
Exemplo n.º 15
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     provider.Initialize (gqlQueryState);
     ColumnsComparer<ColumnsComparerKey > columnsComparer = new ColumnsComparer<ColumnsComparerKey> (provider.GetColumnTypes (), dataComparer);
     recordList = new SortedSet<ColumnsComparerKey> (columnsComparer);
 }
Exemplo n.º 16
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            string fileName = fileOptions.FileName.Evaluate (gqlQueryState);
            string path = Path.GetDirectoryName (fileName);
            string searchPattern = Path.GetFileName (fileName);
            SearchOption searchOption;
            if (fileOptions.Recurse)
                searchOption = SearchOption.AllDirectories;
            else
                searchOption = SearchOption.TopDirectoryOnly;

            path = Path.Combine (gqlQueryState.CurrentDirectory, path);
            files = Directory.GetFiles (path + Path.DirectorySeparatorChar, searchPattern, searchOption);

            if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.Asc
                || fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.FileNameAsc)
                files = files.Select (p => new FileInfo (p)).OrderBy (p => p.Name, stringComparer).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.Desc
                     || fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.FileNameDesc)
                files = files.Select (p => new FileInfo (p)).OrderByDescending (p => p.Name, stringComparer).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.ModificationTimeAsc)
                files = files.Select (p => new FileInfo (p)).OrderBy (p => p.LastWriteTime).Select (p => p.FullName).ToArray ();
            else if (fileOptions.FileOrder == FileOptionsFromClause.FileOrderEnum.ModificationTimeDesc)
                files = files.Select (p => new FileInfo (p)).OrderByDescending (p => p.LastWriteTime).Select (p => p.FullName).ToArray ();

            record = new ProviderRecord (this, true);
            record.LineNo = 0;
            record.TotalLineNo = 0;
            record.Source = "DirectoryProvider";
        }
Exemplo n.º 17
0
        public void Uninitialize()
        {
            if (provider != null) {
                provider.Uninitialize ();
                provider = null;
            }
            files = null;
            gqlQueryState = null;

            OnUninitialize ();
        }
Exemplo n.º 18
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     provider.Initialize (gqlQueryState);
     linesToGo = topValueExpression.Evaluate (gqlQueryState);
 }
Exemplo n.º 19
0
 public abstract void OnInitialize(GqlQueryState gqlQueryState, out string[] files, out long skip);
Exemplo n.º 20
0
        private IExpression GetResultExpression(GqlQueryState gqlQueryState)
        {
            foreach (WhenItem whenItem in whenItems) {
                if (whenItem.Check.Evaluate (gqlQueryState)) {
                    return whenItem.Result;
                }
            }

            return elseResult;
        }
Exemplo n.º 21
0
 public IData EvaluateAsData(GqlQueryState gqlQueryState)
 {
     return GetResultExpression (gqlQueryState).EvaluateAsData (gqlQueryState);
 }
Exemplo n.º 22
0
 public GqlQueryState(GqlQueryState other)
     : this(other, false)
 {
 }
Exemplo n.º 23
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     this.gqlQueryState = gqlQueryState;
     record = null;
 }
Exemplo n.º 24
0
        public static void DumpProviderToStream(IProvider provider, TextWriter outputWriter, GqlQueryState gqlQueryState, 
            string columnDelimiter, GqlEngineState.HeadingEnum heading, int autoSize,
            FileOptionsIntoClause.FormatEnum format,
            CultureInfo cultureInfo)
        {
            try {
                provider.Initialize (gqlQueryState);

                List<string[]> list = new List<string[]> ();
                if (heading != GqlEngineState.HeadingEnum.Off) {
                    ColumnName[] columnTitles = provider.GetColumnNames ();
                    if (columnTitles.Length > 0) {
                        string[] columnTitleStrings = columnTitles.Select (p => p.ToStringWithoutBrackets ()).ToArray ();
                        list.Add (columnTitleStrings);
                        if (heading == GqlEngineState.HeadingEnum.OnWithRule) {
                            string[] columnTitlesRule = new string[columnTitles.Length];
                            for (int i = 0; i < columnTitles.Length; i++)
                                columnTitlesRule [i] = new string ('=', columnTitleStrings [i].ToString ().Length);
                            list.Add (columnTitlesRule);
                        }
                    }
                }

                for (int record = 0; (autoSize == -1 || record < autoSize); record++) {
                    try {
                        if (!provider.GetNextRecord ())
                            break;
                    } catch (WarningException x) {
                        gqlQueryState.Warnings.Add (new LineIgnoredException (x));
                        record--;
                        continue;
                    }
                    list.Add (provider.Record.Columns.Select (p => p.ToString ()).ToArray ());
                }

                FormatColumnsFunction formatColumnListFunction;
                if (autoSize == 0) {
                    if (format == FileOptionsIntoClause.FormatEnum.Csv)
                        formatColumnListFunction = new FormatCsvFunction (columnDelimiter);
                    else
                        formatColumnListFunction = new FormatColumnListFunction (columnDelimiter);
                } else {
                    int[] max = new int[list [0].Length];
                    foreach (string[] item in list) {
                        for (int col = 0; col < max.Length; col++)
                            max [col] = Math.Max (item [col].Length, max [col]);
                    }
                    Type[] types = provider.GetColumnTypes ();
                    for (int col = 0; col < max.Length; col++)
                        if (types [col] != typeof(DataString))
                            max [col] = -max [col];
                    formatColumnListFunction = new FormatColumnListFunction (columnDelimiter, max);
                }

                foreach (var item in list) {
                    outputWriter.WriteLine (formatColumnListFunction.Evaluate (item));
                }

                do {
                    try {
                        if (!provider.GetNextRecord ())
                            break;
                        outputWriter.WriteLine (formatColumnListFunction.Evaluate (provider.Record.Columns.Select (p => p.ToDataString (cultureInfo).Value)));
                    } catch (WarningException x) {
                        gqlQueryState.Warnings.Add (new LineIgnoredException (x));
                    }
                } while (true);
            } finally {
                provider.Uninitialize ();
            }
        }
Exemplo n.º 25
0
 public void Uninitialize()
 {
     provider.Uninitialize ();
     data = null;
     record = null;
     gqlQueryState = null;
 }
Exemplo n.º 26
0
 public void Initialize(GqlQueryState gqlQueryState)
 {
     record = new ProviderRecord (this, true);
     record.LineNo = 1;
     this.gqlQueryState = gqlQueryState;
 }
Exemplo n.º 27
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            regex = new Regex (regexDefinition, caseInsensitive ? RegexOptions.IgnoreCase : RegexOptions.None);
            string[] groups = regex.GetGroupNames ();
            columnNameList = groups.Skip (1).Select (p => new ColumnName (p)).ToArray ();
            for (int i = 0; i < columnNameList.Length; i++)
                if (groups [i + 1] == (i + 1).ToString ())
                    columnNameList [i] = new ColumnName (i);
                else
                    columnNameList [i] = new ColumnName (groups [i + 1]);
            provider.Initialize (gqlQueryState);

            record = new ProviderRecord (this, true);
            dataStrings = new DataString[columnNameList.Length];
            for (int i = 0; i < dataStrings.Length; i++) {
                dataStrings [i] = new DataString ();
                record.Columns [i] = dataStrings [i];
            }
        }
Exemplo n.º 28
0
        public void Process(StateBin state, GqlQueryState gqlQueryState)
        {
            throw new NotSupportedException ("Aggregation with case expression not supported");

            //GetResultExpression(gqlQueryState).Aggregate(state, gqlQueryState);
        }
Exemplo n.º 29
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            provider.Initialize(gqlQueryState);
            this.gqlQueryState = gqlQueryState;

            data = new StateBin[outputColumns.Length];
            record = new ProviderRecord(this, true);
        }
Exemplo n.º 30
0
        public void Initialize(GqlQueryState gqlQueryState)
        {
            this.gqlQueryState = gqlQueryState;
            gqlEngineExecutionState = gqlQueryState.CurrentExecutionState;

            string fileName;
            if (this.fileName.StartsWith ("#")) {
                fileName = Path.Combine (gqlQueryState.TempDirectory, this.fileName);
            } else {
                fileName = Path.Combine (gqlQueryState.CurrentDirectory, this.fileName);
            }
            streamReader = new StreamReader (new AsyncStreamReader (new FileStream (fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 32 * 1024), 32 * 1024));
            record = new ProviderRecord (this, true);
            record.Source = fileName;
            dataString = new DataString ();
            record.Columns [0] = dataString;

            for (long i = 0; i < skip; i++) {
                if (streamReader.ReadLine () == null) {
                    streamReader.Close ();
                    streamReader = null;
                    return;
                }
            }
        }