Class SqlAdvisorTest

    • Field Detail

      • ADVISOR_TEST_FACTORY

        public static final SqlTestFactory ADVISOR_TEST_FACTORY
      • configureTester

        public org.junit.rules.MethodRule configureTester
      • STAR_KEYWORD

        private static final java.util.List<java.lang.String> STAR_KEYWORD
      • FROM_KEYWORDS

        protected static final java.util.List<java.lang.String> FROM_KEYWORDS
      • SALES_TABLES

        protected static final java.util.List<java.lang.String> SALES_TABLES
      • SCHEMAS

        private static final java.util.List<java.lang.String> SCHEMAS
      • AB_TABLES

        private static final java.util.List<java.lang.String> AB_TABLES
      • EMP_TABLE

        private static final java.util.List<java.lang.String> EMP_TABLE
      • FETCH_OFFSET

        protected static final java.util.List<java.lang.String> FETCH_OFFSET
      • EXPR_KEYWORDS

        protected static final java.util.List<java.lang.String> EXPR_KEYWORDS
      • QUANTIFIERS

        protected static final java.util.List<java.lang.String> QUANTIFIERS
      • SELECT_KEYWORDS

        protected static final java.util.List<java.lang.String> SELECT_KEYWORDS
      • ORDER_KEYWORDS

        private static final java.util.List<java.lang.String> ORDER_KEYWORDS
      • EMP_COLUMNS

        private static final java.util.List<java.lang.String> EMP_COLUMNS
      • EMP_COLUMNS_E

        private static final java.util.List<java.lang.String> EMP_COLUMNS_E
      • DEPT_COLUMNS

        private static final java.util.List<java.lang.String> DEPT_COLUMNS
      • PREDICATE_KEYWORDS

        protected static final java.util.List<java.lang.String> PREDICATE_KEYWORDS
      • WHERE_KEYWORDS

        private static final java.util.List<java.lang.String> WHERE_KEYWORDS
      • A_TABLE

        private static final java.util.List<java.lang.String> A_TABLE
      • JOIN_KEYWORDS

        protected static final java.util.List<java.lang.String> JOIN_KEYWORDS
      • SETOPS

        private static final java.util.List<java.lang.String> SETOPS
    • Constructor Detail

      • SqlAdvisorTest

        public SqlAdvisorTest()
    • Method Detail

      • getFromKeywords

        protected java.util.List<java.lang.String> getFromKeywords()
      • getSelectKeywords

        protected java.util.List<java.lang.String> getSelectKeywords()
      • getSalesTables

        protected java.util.List<java.lang.String> getSalesTables()
        Returns a list of the tables in the SALES schema. Derived classes with extended SALES schemas may override.
        Returns:
        list of tables in the SALES schema
      • getJoinKeywords

        protected java.util.List<java.lang.String> getJoinKeywords()
      • assertTokenizesTo

        private void assertTokenizesTo​(java.lang.String sql,
                                       java.lang.String expected)
      • assertHint

        protected void assertHint​(java.lang.String sql,
                                  java.util.List<java.lang.String>... expectedLists)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • assertHint

        protected void assertHint​(java.lang.String sql,
                                  java.lang.String expectedResults)
                           throws java.lang.Exception
        Checks that a given SQL statement yields the expected set of completion hints.
        Parameters:
        sql - SQL statement
        expectedResults - Expected list of hints
        Throws:
        java.lang.Exception - on error
      • assertSimplify

        protected void assertSimplify​(java.lang.String sql,
                                      java.lang.String expected)
        Tests that a given SQL statement simplifies to the salesTables result.
        Parameters:
        sql - SQL statement to simplify. The SQL statement must contain precisely one caret '^', which marks the location where completion is to occur.
        expected - Expected result after simplification.
      • assertComplete

        protected void assertComplete​(java.lang.String sql,
                                      java.util.List<java.lang.String>... expectedResults)
      • assertComplete

        protected void assertComplete​(java.lang.String sql,
                                      java.util.Map<java.lang.String,​java.lang.String> replacements,
                                      java.util.List<java.lang.String>... expectedResults)
      • assertComplete

        protected void assertComplete​(java.lang.String sql,
                                      java.lang.String expectedResults,
                                      java.lang.String expectedWord)
      • assertComplete

        protected void assertComplete​(java.lang.String sql,
                                      java.lang.String expectedResults,
                                      java.lang.String expectedWord,
                                      java.util.Map<java.lang.String,​java.lang.String> replacements)
        Tests that a given SQL which may be invalid or incomplete simplifies itself and yields the salesTables set of completion hints. This is an integration test of assertHint(java.lang.String, java.util.List<java.lang.String>...) and assertSimplify(java.lang.String, java.lang.String).
        Parameters:
        sql - SQL statement
        expectedResults - Expected list of hints
        expectedWord - Word that we expect to be replaced, or null if we don't care
      • assertReplacements

        private void assertReplacements​(java.lang.String sql,
                                        java.util.Map<java.lang.String,​java.lang.String> replacements,
                                        org.apache.calcite.sql.advise.SqlAdvisor advisor,
                                        java.lang.String word,
                                        java.util.List<org.apache.calcite.sql.validate.SqlMoniker> results)
      • assertEquals

        protected void assertEquals​(java.lang.String[] actualResults,
                                    java.util.List<java.lang.String>... expectedResults)
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • convertCompletionHints

        private java.lang.String convertCompletionHints​(java.util.List<org.apache.calcite.sql.validate.SqlMoniker> hints)
      • toString

        private static <T> java.lang.String toString​(java.util.Collection<T> list)
        Converts a list to a string, one item per line.
        Parameters:
        list - List
        Returns:
        String with one item of the list per line
      • plus

        protected static <T> java.util.List<T> plus​(java.util.List<T>... lists)
        Concatenates several lists of the same type into a single list.
        Parameters:
        lists - Lists to concatenate
        Returns:
        Sum list
      • testFrom

        public void testFrom()
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testFromComplete

        public void testFromComplete()
      • testGroup

        public void testGroup()
      • testJoin

        public void testJoin()
                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testJoinKeywords

        public void testJoinKeywords()
      • testSimplifyStarAlias

        public void testSimplifyStarAlias()
      • testSimlifySubQueryStar

        public void testSimlifySubQueryStar()
      • testSimlifySubQueryMultipleFrom

        public void testSimlifySubQueryMultipleFrom()
      • testSimlifyMinus

        public void testSimlifyMinus()
      • testOnCondition

        public void testOnCondition()
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testFromWhere

        public void testFromWhere()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testWhereList

        public void testWhereList()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testSelectList

        public void testSelectList()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testOrderByList

        public void testOrderByList()
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testSubQuery

        public void testSubQuery()
                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testSubQueryInWhere

        public void testSubQueryInWhere()
      • testSimpleParserTokenizer

        public void testSimpleParserTokenizer()
      • testSimpleParser

        public void testSimpleParser()
      • testSimpleParserQuotedIdSqlServer

        public void testSimpleParserQuotedIdSqlServer()
      • testSimpleParserQuotedIdMySql

        public void testSimpleParserQuotedIdMySql()
      • testSimpleParserQuotedIdJava

        public void testSimpleParserQuotedIdJava()
      • testSimpleParserQuotedIdDefault

        public void testSimpleParserQuotedIdDefault()
      • replaceQuotes

        private java.lang.String replaceQuotes​(org.apache.calcite.sql.parser.SqlParser.Config parserConfig,
                                               java.lang.String sql)
      • testSimpleParserQuotedIdImpl

        private void testSimpleParserQuotedIdImpl()
      • testPartialIdentifier

        public void testPartialIdentifier()
      • testAdviceKeywordsJava

        public void testAdviceKeywordsJava()
      • testAdviceMixedCase

        public void testAdviceMixedCase()
      • testAdviceExpression

        public void testAdviceExpression()
      • testAdviceEmptyFrom

        public void testAdviceEmptyFrom()
      • testInsert

        public void testInsert()
                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestSchema

        public void testNestSchema()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestTable1

        public void testNestTable1()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestTable2

        public void testNestTable2()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestTable3

        public void testNestTable3()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestTable4

        public void testNestTable4()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestTableSchemaMustMatch

        public void testNestTableSchemaMustMatch()
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testNestSchemaSqlServer

        public void testNestSchemaSqlServer()
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testUnion

        public void testUnion()
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testMssql

        public void testMssql()