Ejemplo n.º 1
0
        private void InitializeSourceForStreaming(HqlDataSource src)
        {
            if (src.OnJoin == null)
            {
                src.InitJoining();
            }
            src.LoadFieldReferences(_select.FieldGroup);
            src.LoadFieldReferences(_where.EvaluationCriteria);
            src.LoadFieldReferences(_groupby.FieldGroup);
            src.LoadFieldReferences(_orderby.FieldGroup);
            if (_settings.PrintCategorizeFilename)
            {
                src.LoadFieldReferences(_settings.Output.FieldGroup);
            }

            for (int j = 0; j < _from.Count; ++j)
            {
                if (_from[j].OnJoin != null)
                {
                    src.LoadFieldReferences(_from[j].OnJoin.EvaluationCriteria);
                }
            }

            src.BuildBlankValues();
        }
Ejemplo n.º 2
0
        public void Parse(HqlTokenProcessor processor)
        {
            HqlToken   token;
            bool       FileExpected = true;
            HqlKeyword joinType;

            // first thing should be from
            token = processor.GetToken();
            if (token.WordType != HqlWordType.KEYWORD || token.Keyword != HqlKeyword.FROM)
            {
                throw new Exception("Expected FROM");
            }

            bool ReadNextToken = true;

            // now pull back things until you get to EOF or WHERE
            for (; ;)
            {
                joinType = HqlKeyword.UNKNOWN;

                if (ReadNextToken)
                {
                    processor.MoveNextToken();
                }
                ReadNextToken = true;

                token = processor.GetToken();
                if (processor.MatchesEndOfProcessing())
                {
                    break;
                }

                if (token.WordType == HqlWordType.KEYWORD &&
                    (
                        token.Keyword == HqlKeyword.WHERE ||
                        token.Keyword == HqlKeyword.GROUPBY ||
                        token.Keyword == HqlKeyword.HAVING ||
                        token.Keyword == HqlKeyword.ORDERBY
                    )
                    )
                {
                    break;
                }

                if (token.WordType == HqlWordType.KEYWORD &&
                    (
                        token.Keyword == HqlKeyword.FULL_OUTER ||
                        token.Keyword == HqlKeyword.LEFT_OUTER ||
                        token.Keyword == HqlKeyword.RIGHT_OUTER ||
                        token.Keyword == HqlKeyword.INNER
                    )
                    )
                {
                    joinType = token.Keyword;

                    processor.MoveNextToken();
                    token = processor.GetToken();
                    if (token.WordType != HqlWordType.KEYWORD || token.Keyword != HqlKeyword.JOIN)
                    {
                        throw new Exception("Expected JOIN keyword");
                    }
                    FileExpected = true;

                    processor.MoveNextToken();
                    token = processor.GetToken();
                }

                // else time to process it!
                if (!FileExpected)
                {
                    break;
                }

                FileExpected = false;

                if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.STDIN)
                {
                    AddStdin();
                }
                else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.DUAL)
                {
                    AddDual();
                }
                else if (token.WordType == HqlWordType.TEXT || token.WordType == HqlWordType.LITERAL_STRING)
                {
                    AddFile(token.Data);
                }
                else if (token.WordType == HqlWordType.STREAM)
                {
                    HqlDataSource source = new HqlDataSource(HqlDataSourceType.STREAM, (System.IO.StreamReader)token.Parsed);
                    AddSource(source);
                }
                else if (token.WordType == HqlWordType.KEYWORD && token.Keyword == HqlKeyword.OPENPAREN)
                {
                    // NESTED QUERY!
                    HqlStream cs           = new HqlStream(processor.GetRemainingSql(false), ")");
                    string    remainingSql = cs.RemainingSql;
                    processor.SetRemainingSql(remainingSql);
                    processor.MoveNextToken();
                    token = processor.GetToken();
                    if (token.WordType != HqlWordType.KEYWORD || token.Keyword != HqlKeyword.CLOSEDPAREN)
                    {
                        throw new Exception("Nested query SQL did not return correctly");
                    }

                    AddTextReader(cs);
                }
                else
                {
                    throw new Exception("Unknown type of FROM clause");
                }

                // look to process SKIP
                for (;;)
                {
                    bool breakOut = false;

                    if (ReadNextToken)
                    {
                        processor.MoveNextToken();
                        token = processor.GetToken();
                    }

                    if (_sources != null && _sources.Length > 0 && (token.WordType == HqlWordType.UNKNOWN || token.WordType == HqlWordType.KEYWORD))
                    {
                        HqlToken option;
                        switch (token.Data.ToUpper())
                        {
                        case "SKIP":
                        {
                            option = processor.GetOptionData(token.Data);
                            if (option.WordType != HqlWordType.INT || option.ParsedAsInt <= 0)
                            {
                                throw new Exception("Skip count must be greater than zero");
                            }
                            CurrentSource.SkipRecords = option.ParsedAsInt;
                            ReadNextToken             = true;
                            break;
                        }

                        case "DELIMITER":
                        case "DELIM":
                        {
                            option = processor.GetOptionData(token.Data);
                            if (option.WordType != HqlWordType.TEXT && option.WordType != HqlWordType.LITERAL_STRING)
                            {
                                throw new Exception(String.Format("Expected a valid delimiter after {0}", token.Data));
                            }
                            CurrentSource.Delimiter = HqlTokenProcessor.CleanupDelimiter(option.Data);
                            ReadNextToken           = true;
                            break;
                        }

                        case "AS":
                        {
                            option = processor.GetOptionData(token.Data);
                            if (option.WordType != HqlWordType.UNKNOWN)
                            {
                                throw new Exception("Expected a table reference name following AS");
                            }
                            CurrentSource.TableReference = option.Data;
                            break;
                        }

                        default:
                            breakOut = true;
                            break;
                        }
                    }
                    else
                    {
                        breakOut = true;
                    }

                    if (breakOut)
                    {
                        ReadNextToken = false;
                        break;
                    }
                }


                if (joinType != HqlKeyword.UNKNOWN)
                {
                    HqlDataSource src = LeftSideOfJoin;
                    src.JoinType = joinType;

                    if (ReadNextToken)
                    {
                        processor.MoveNextToken();
                        token = processor.GetToken();
                    }

                    if (token.WordType != HqlWordType.KEYWORD || token.Keyword != HqlKeyword.ON)
                    {
                        throw new Exception("Expected ON following a table");
                    }

                    src.InitJoining();
                    src.OnJoin.Parse(processor, HqlKeyword.ON, HqlKeyword.ON, null);
                    ReadNextToken = false;
                }
            }

            if (FileExpected)
            {
                throw new Exception("Expected additional FROM fields");
            }
        }