You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by hz...@apache.org on 2016/07/19 01:17:53 UTC

[3/6] incubator-trafodion git commit: fix for comments

fix for comments


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/b9384304
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/b9384304
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/b9384304

Branch: refs/heads/master
Commit: b938430473526bbeab30cbaf7da132a9ec327459
Parents: 79b421f
Author: Liu Ming <ov...@sina.com>
Authored: Fri Jul 15 15:02:25 2016 +0000
Committer: Liu Ming <ov...@sina.com>
Committed: Fri Jul 15 15:02:25 2016 +0000

----------------------------------------------------------------------
 core/sql/bin/SqlciErrors.txt             |   2 +-
 core/sql/parser/ParKeyWords.cpp          |   2 +-
 core/sql/parser/sqlparser.y              | 182 +++++++++++++++++---------
 core/sql/regress/compGeneral/EXPECTED005 |  12 ++
 core/sql/regress/compGeneral/TEST005     |   2 +
 core/sql/sqlcomp/parser.h                |  23 +++-
 6 files changed, 156 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/bin/SqlciErrors.txt
----------------------------------------------------------------------
diff --git a/core/sql/bin/SqlciErrors.txt b/core/sql/bin/SqlciErrors.txt
index 86b753e..64f4613 100644
--- a/core/sql/bin/SqlciErrors.txt
+++ b/core/sql/bin/SqlciErrors.txt
@@ -410,7 +410,6 @@
 1430 3F000 99999 BEGINNER MAJOR DBADMIN A schema name that starts and ends with an "_"(underscore) is reserved for internal usage. It cannot be used to create a user schema.
 1431 ZZZZZ 99999 BEGINNER MINOR DBADMIN Object $0~String0 exists in HBase. This could be due to a concurrent transactional ddl operation in progress on this table.
 1432 ZZZZZ 99999 BEGINNER MINOR DBADMIN Input LOB type $0~Int0 does not match column's storage type: $1~Int1 Column name: $0~String0 .
-1433 ZZZZZ 99999 BEGINNER MINOR DBADMIN WITH clause redefined. WITH name $0~String0 .
 1500 ZZZZZ 99999 ADVANCED CRTCL DIALOUT The CATSYS - CAT_REFERENCES system schema relationship for catalog $0~CatalogName might be corrupt.
 1501 ZZZZZ 99999 UUUUUUUU UUUUU UUUUUUU --- unused as of 5/7/12 ---
 1502 ZZZZZ 99999 ADVANCED CRTCL DIALOUT The OBJECTS - REPLICAS definition schema relationship for $0~String0 $1~TableName might be corrupt.
@@ -1027,6 +1026,7 @@ $1~String1 --------------------------------
 3285 ZZZZZ 99999 BEGINNER MINOR DBADMIN The C interface for this type of routine is deprecated, please consider migrating to a TMUDF with a C++ or Java interface.
 3286 ZZZZZ 99999 BEGINNER MINOR DBADMIN The routine language that was either specified or implied from the library file name is not supported for this type of routine.
 3287 42000 99999 BEGINNER MINOR DBADMIN The $0~string0 option is not supported for this type of routine.
+3288 42000 99999 BEGINNER MINOR DBADMIN A syntax error occurred. WITH clause redefined. WITH name $0~String0 .
 3300 42000 99999 BEGINNER MAJOR DBADMIN --- available ---
 3301 42000 99999 BEGINNER MAJOR DBADMIN $0~string0 is too long (longer than $1~int0 $2~string1).
 

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/parser/ParKeyWords.cpp
----------------------------------------------------------------------
diff --git a/core/sql/parser/ParKeyWords.cpp b/core/sql/parser/ParKeyWords.cpp
index fee890f..6f1c06f 100644
--- a/core/sql/parser/ParKeyWords.cpp
+++ b/core/sql/parser/ParKeyWords.cpp
@@ -848,7 +848,7 @@ ParKeyWord ParKeyWords::keyWords_[] = {
   ParKeyWord("RECORD_SEPARATOR",   TOK_RECORD_SEPARATOR, NONRESTOKEN_),
   ParKeyWord("RECOVER",            TOK_RECOVER,     NONRESTOKEN_),
   ParKeyWord("RECOVERY",           TOK_RECOVERY,    NONRESTOKEN_),
-  ParKeyWord("RECURSIVE",          IDENTIFIER,      POTANS_|RESWORD_),
+  ParKeyWord("RECURSIVE",          TOK_RECURSIVE,      POTANS_|RESWORD_),
   ParKeyWord("REDEFTIME",          TOK_REDEFTIME,   FLAGSNONE_),
   ParKeyWord("REF",                IDENTIFIER,      POTANS_|RESWORD_),
   ParKeyWord("REFERENCES",         TOK_REFERENCES,  ANS_|RESWORD_),

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 60b4a09..74c2718 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -966,6 +966,7 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %token <tokval> TOK_RECORD_SEPARATOR
 %token <tokval> TOK_RECOVER
 %token <tokval> TOK_RECOVERY
+%token <tokval> TOK_RECURSIVE 
 %token <tokval> TOK_REFERENCING        
 %token <tokval> TOK_REFRESH               
 %token <tokval> TOK_RELATED
@@ -1928,7 +1929,8 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %type <relx>  		        rel_subquery_and_as_clause
 %type <relx>  		        rel_subquery_as_clause_and_col_list
 %type <relx>                    with_clause
-%type <relx>                    with_clause_list
+%type <relx>                    with_clause_elements
+%type <relx>                    with_clause_element
 %type <hint>      		optimizer_hint
 %type <hint>      		hints
 %type <hint>      		index_hints
@@ -6581,9 +6583,6 @@ table_reference : table_name_and_hint
               | rel_subquery_and_as_clause
                 { $$ = $1; }
 
-              | with_clause_list
-                {  $$ = $1;}
-
               | rel_subquery_as_clause_and_col_list
                 { $$ = $1; }
 
@@ -6653,10 +6652,11 @@ table_as_tmudf_function : TOK_UDF '(' table_mapping_function_invocation ')'
 table_name_and_hint : table_name optimizer_hint hbase_access_options
                       {
                         NAString tmp = ((*$1).getQualifiedNameAsString());
-                        if(SqlParser_CurrentParser->with_clauses_->contains(&tmp) )
+                        if(SqlParser_CurrentParser->hasWithDefinition(&tmp) )
                         {
-                          RelExpr *re = SqlParser_CurrentParser->with_clauses_->getFirstValue(&tmp);
+                          RelExpr *re = SqlParser_CurrentParser->getWithDefinition(&tmp);
                           $$=re->copyTree(PARSERHEAP());
+                          delete $1;
                         }
                         else
                         {
@@ -6670,18 +6670,7 @@ table_name_and_hint : table_name optimizer_hint hbase_access_options
                           delete $1;
                         }
                       }
-/*
-                      {
-                        $$ = new (PARSERHEAP()) Scan(*$1);
-                        if ($2) 
-                          $$->setHint($2);
 
-                        if ($3)
-                          ((Scan*)$$)->setHbaseAccessOptions($3);
-                        
-                        delete $1;
-                      }
-*/
                     | '(' table_name_and_hint ')'
                       {
                         CheckModeSpecial1();
@@ -6980,9 +6969,9 @@ del_stmt_w_acc_type_rtn_list_and_as_clause_col_list : '('  delete_statement acce
 table_name_as_clause_and_hint : table_name as_clause optimizer_hint hbase_access_options
                                 {
                                    NAString tmp = ((*$1).getQualifiedNameAsString());
-                                   if(SqlParser_CurrentParser->with_clauses_->contains(&tmp) )
+                                   if(SqlParser_CurrentParser->hasWithDefinition(&tmp) )
                                    {     
-                                     RelExpr *re = SqlParser_CurrentParser->with_clauses_->getFirstValue(&tmp);
+                                     RelExpr *re = SqlParser_CurrentParser->getWithDefinition(&tmp);
                                      RenameTable *rt = new (PARSERHEAP()) RenameTable(re, *$2);
                                      $$=rt->copyTree(PARSERHEAP());
                                   }
@@ -7035,47 +7024,47 @@ rel_subquery_and_as_clause : rel_subquery as_clause
                                CheckModeSpecial1();
                                $$ = $2;
                              }
+with_clause : 
+              TOK_WITH with_clause_elements
+              {
+                 $$ = NULL;
+              }
+              | TOK_WITH TOK_RECURSIVE with_clause_elements
+              {
+                        *SqlParser_Diags << DgSqlCode(-3022) << DgString0("WITH RECURSIVE");
+                        YYERROR;
+              }
 
-with_clause_list : with_clause
-                     {  $$ = $1 ; }
+with_clause_elements : with_clause_element
+              {
+                 $$ = NULL;
+              }
+              | with_clause_elements ',' with_clause_element
+              {
+                 $$ = NULL;
+              }
 
-                   | with_clause_list ',' correlation_name TOK_AS rel_subquery 
+with_clause_element : correlation_name TOK_AS '(' query_expression ')'
                       {
                          RelRoot *root = new (PARSERHEAP())
-                                            RelRoot($5, REL_ROOT);
-                         $$= new (PARSERHEAP()) RenameTable(root, *$3); 
+                                            RelRoot($4, REL_ROOT);
+                         $$= new (PARSERHEAP()) RenameTable(root, *$1); 
 
                          //Duplicated definition of WITH
-                         if(SqlParser_CurrentParser->with_clauses_->contains($3) )
+                         if(SqlParser_CurrentParser->hasWithDefinition($1) )
                           {
-                            *SqlParser_Diags << DgSqlCode(-1433)
-                                             << DgString0((*$3).toCharStar());
+                            *SqlParser_Diags << DgSqlCode(-3288)
+                                             << DgString0((*$1).toCharStar());
+                             delete $1;
+                             delete $4;
                              YYERROR;
                           }
 
-                          SqlParser_CurrentParser->with_clauses_->insert($3 , $$);
-
+                          SqlParser_CurrentParser->insertWithDefinition($1 , $$);
+                          delete $1;
+                          delete $4;
                       }
 
-with_clause : TOK_WITH correlation_name TOK_AS rel_subquery
-                        {
-                          //protected by CQD before this feature is fully QA
-                          if (CmpCommon::getDefault(MODE_SPECIAL_4) == DF_OFF)
-                          {
-                            *SqlParser_Diags << DgSqlCode(-3022)
-                              << DgString0("WITH statement");
-                            YYERROR;
-                          }
-                          $$= new (PARSERHEAP()) RenameTable($4, *$2);
-                          if(SqlParser_CurrentParser->with_clauses_->contains($2) )
-                          {
-                            *SqlParser_Diags << DgSqlCode(-1433)
-                               << DgString0((*$2).toCharStar());
-                             YYERROR;
-                          }
-                          SqlParser_CurrentParser->with_clauses_->insert($2 , $$);
-                        }
-
 rel_subquery_as_clause_and_col_list : rel_subquery as_clause '(' derived_column_list ')'
                                       {
                                         $$ = new (PARSERHEAP())
@@ -13396,9 +13385,8 @@ ignore_ms4_hints : identifier '(' NUMERIC_LITERAL_EXACT_NO_SCALE  ')'
                           | identifier 
                                { $$ = NULL; }
 
-/* type relx */
-query_specification : select_token set_quantifier query_spec_body 
-     {
+query_specification :select_token set_quantifier query_spec_body 
+    { 
        if ($2) {
          $$ = new (PARSERHEAP())
            RelRoot(new (PARSERHEAP())
@@ -13408,14 +13396,41 @@ query_specification : select_token set_quantifier query_spec_body
                               ColReference(new (PARSERHEAP()) ColRefName(TRUE, PARSERHEAP()))
                                         )
                          );
-	   assert($3->getOperatorType() == REL_ROOT);
+           assert($3->getOperatorType() == REL_ROOT);
+           RelRoot *root1 = (RelRoot *) $$;
+           RelRoot *root2 = (RelRoot *) $3;
+           root1->assignmentStTree() = root2->assignmentStTree();
+           root2->assignmentStTree() = NULL;
+           }
+       else
+         $$ = $3;
+
+       if (CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP ||
+           CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP_MV)
+         ((RelRoot*)$$)->setAnalyzeOnly();
+
+    }
+
+/* type relx */
+query_specification :with_clause select_token set_quantifier query_spec_body 
+     {
+       if ($3) {
+         $$ = new (PARSERHEAP())
+           RelRoot(new (PARSERHEAP())
+                   GroupByAgg($4
+                              ,REL_GROUPBY
+                              ,new (PARSERHEAP())
+                              ColReference(new (PARSERHEAP()) ColRefName(TRUE, PARSERHEAP()))
+                                        )
+                         );
+	   assert($4->getOperatorType() == REL_ROOT);
 	   RelRoot *root1 = (RelRoot *) $$;
-	   RelRoot *root2 = (RelRoot *) $3;
+	   RelRoot *root2 = (RelRoot *) $4;
 	   root1->assignmentStTree() = root2->assignmentStTree();
 	   root2->assignmentStTree() = NULL;
 	   }
        else
-         $$ = $3;
+         $$ = $4;
          
        if (CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP ||
            CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP_MV)
@@ -13445,7 +13460,6 @@ query_specification : exe_util_get_lob_info
 				  RelRoot *root = new (PARSERHEAP())
 				    RelRoot($1, REL_ROOT);
                                 }
-/* type relx */
 query_specification : select_token '[' firstn_sorted NUMERIC_LITERAL_EXACT_NO_SCALE ']' set_quantifier query_spec_body
 	{
 	  if ($6) {
@@ -13493,6 +13507,55 @@ query_specification : select_token '[' firstn_sorted NUMERIC_LITERAL_EXACT_NO_SC
           if (CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP ||
               CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP_MV)
             ((RelRoot*)$$)->setAnalyzeOnly();
+           } 
+/* type relx */
+query_specification : with_clause select_token '[' firstn_sorted NUMERIC_LITERAL_EXACT_NO_SCALE ']' set_quantifier query_spec_body
+	{
+	  if ($7) {
+	    $$ = new (PARSERHEAP())
+	      RelRoot(new (PARSERHEAP())
+		      GroupByAgg($8
+				 ,REL_GROUPBY
+				 ,new (PARSERHEAP())
+				 ColReference(new (PARSERHEAP()) 
+					      ColRefName(TRUE, PARSERHEAP())))
+		      );
+	   assert($8->getOperatorType() == REL_ROOT);
+	   RelRoot *root1 = (RelRoot *) $$;
+	   RelRoot *root2 = (RelRoot *) $8;
+	   root1->assignmentStTree() = root2->assignmentStTree();
+	   root2->assignmentStTree() = NULL;
+	   }
+	  else
+	    $$ = $8;
+
+	  assert($$->getOperatorType() == REL_ROOT);
+	  
+	  RelRoot * rootNode = (RelRoot *)$$;
+	  Int64 numRows = atoInt64($5->data());
+	  if (($4 == TOK_LAST) && 
+	      ((numRows < 0) || (numRows > 1)))
+	    {
+	      yyerror("Number of rows must be 0 or 1 with LAST option. \n");
+	      YYERROR;
+	    }
+
+	  if ($4 == TOK_LAST)
+	    {
+	      // last 0 is -2.  last 1 is -3.
+	      rootNode->setFirstNRows((numRows == 0) ? -2 : -3);
+	    }
+	  else
+	    {
+	      rootNode->setFirstNRows(numRows);
+	    }
+
+	  rootNode->needFirstSortedRows() = (($4 == TOK_FIRST) ? TRUE : FALSE);
+	  delete $5;
+         
+          if (CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP ||
+              CmpCommon::getDefault(MVQR_LOG_QUERY_DESCRIPTORS) == DF_DUMP_MV)
+            ((RelRoot*)$$)->setAnalyzeOnly();
 	}
 
 /* type tokval */
@@ -14759,11 +14822,6 @@ optional_limit_spec : TOK_LIMIT NUMERIC_LITERAL_EXACT_NO_SCALE
 
 dml_statement : dml_query { $$ = $1; }
 
-               | with_clause_list dml_query
-                    {
-                        $$ = $2;
-                    }
-
 	       | front_of_insert_with_rwrs   rowwise_rowset_info Rest_Of_insert_statement 
 		    {
                       if ($1 != Insert::UPSERT_INSERT)
@@ -18270,7 +18328,7 @@ non_join_query_expression : non_join_query_term
             }
           }
         }
-		| query_expression TOK_UNION TOK_ALL query_term
+	| query_expression TOK_UNION TOK_ALL query_term
         {
 	  Union *unionNode = new (PARSERHEAP()) Union($1, $4);
           $$ = new (PARSERHEAP()) RelRoot(unionNode);
@@ -18309,7 +18367,6 @@ non_join_query_expression : non_join_query_term
 
 /* type relx */
 non_join_query_term : non_join_query_primary
-
   		    | query_term TOK_INTERSECT query_primary
   		      {
   			$$ = new (PARSERHEAP())
@@ -18385,7 +18442,6 @@ rel_subquery : '(' query_expression order_by_clause ')'
 
                                   $$ = temp;
 				}
-
 /* type item */
 predicate : directed_comparison_predicate
         | key_comparison_predicate

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/regress/compGeneral/EXPECTED005
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/EXPECTED005 b/core/sql/regress/compGeneral/EXPECTED005
index e9e8d0a..4717d8e 100755
--- a/core/sql/regress/compGeneral/EXPECTED005
+++ b/core/sql/regress/compGeneral/EXPECTED005
@@ -1105,6 +1105,18 @@ C1 C2
 
 --- SQL operation complete.
 >>
+>>with recursive w1 as (select c1, c2 from witht1 union all select origin.c1 , origin.c2 from w1 join t1 origin on origin.c1 = w1.c1 );
+
+*** ERROR[3022] The WITH RECURSIVE operator is not yet supported.
+
+*** ERROR[8822] The statement was not prepared.
+
+>>with w1 as (select * from witht1), w1 as (select * from witht2) select * from w1;
+
+*** ERROR[3288] A syntax error occurred. WITH clause redefined. WITH name W1 .
+
+*** ERROR[8822] The statement was not prepared.
+
 >>cqd mode_special_4 reset;
 
 --- SQL operation complete.

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/regress/compGeneral/TEST005
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/TEST005 b/core/sql/regress/compGeneral/TEST005
index b98297e..41b62cd 100755
--- a/core/sql/regress/compGeneral/TEST005
+++ b/core/sql/regress/compGeneral/TEST005
@@ -503,6 +503,8 @@ select * from w1
 union all
 select * from w1;
 
+with recursive w1 as (select c1, c2 from witht1 union all select origin.c1 , origin.c2 from w1 join t1 origin on origin.c1 = w1.c1 );
+with w1 as (select * from witht1), w1 as (select * from witht2) select * from w1;
 cqd mode_special_4 reset;
 
 ?section cleanup

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/b9384304/core/sql/sqlcomp/parser.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/parser.h b/core/sql/sqlcomp/parser.h
index eebcadd..cd57ed5 100644
--- a/core/sql/sqlcomp/parser.h
+++ b/core/sql/sqlcomp/parser.h
@@ -261,8 +261,20 @@ ItemExpr *get_w_ItemExprTree(const NAWchar * str,
   NABoolean isHQCCacheable()
     { return HQCKey_?HQCKey_->isCacheable():FALSE;  }
 
-  NAHashDictionary<NAString,RelExpr> *with_clauses_;
-
+  NABoolean hasWithDefinition(NAString* key)
+    { if(with_clauses_->contains(key) ) return TRUE;
+      else return FALSE;
+    }
+
+  void insertWithDefinition(NAString* key,  RelExpr* val)
+    {
+       with_clauses_->insert(key,val);
+    }
+
+  RelExpr * getWithDefinition(NAString *key)
+    {
+       return with_clauses_->getFirstValue(key);
+    }
 private:
 
   HQCParseKey* HQCKey_;
@@ -313,6 +325,13 @@ private:
 
   LIST(NABoolean )  hasOlapFunctions_;
   LIST(NABoolean )  hasTDFunctions_;
+  /* 
+   * hashmap to save WITH clause definition 
+   * key is the name of the with clause
+   * value is the RelExpr structure
+   */
+  NAHashDictionary<NAString,RelExpr> *with_clauses_;
+
 };
 
 #define PARSERASSERT(b) \