trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [1/6] incubator-trafodion git commit: initial support of WITH
Date Tue, 19 Jul 2016 01:17:51 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 419d2cd5e -> bc325ffeb


initial support of WITH


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

Branch: refs/heads/master
Commit: 947797de2f0d7db1c346b19a7b50b4cb59c35bb0
Parents: 64ace98
Author: Liu Ming <ovis_poly@sina.com>
Authored: Wed Jul 6 14:36:10 2016 +0000
Committer: Liu Ming <ovis_poly@sina.com>
Committed: Wed Jul 6 14:36:10 2016 +0000

----------------------------------------------------------------------
 core/sql/parser/sqlparser.y | 94 +++++++++++++++++++++++++++++++++++++---
 core/sql/sqlci/sqlci_lex.ll |  1 +
 core/sql/sqlci/sqlci_yacc.y |  2 +
 core/sql/sqlcomp/parser.cpp |  9 ++++
 core/sql/sqlcomp/parser.h   |  2 +
 5 files changed, 101 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/947797de/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 3cd3663..60b4a09 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -1927,6 +1927,8 @@ static void enableMakeQuotedStringISO88591Mechanism()
 %type <relx>  		        table_name_as_clause_hint_and_col_list
 %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 <hint>      		optimizer_hint
 %type <hint>      		hints
 %type <hint>      		index_hints
@@ -6579,6 +6581,9 @@ table_reference : table_name_and_hint
               | rel_subquery_and_as_clause
                 { $$ = $1; }
 
+              | with_clause_list
+                {  $$ = $1;}
+
               | rel_subquery_as_clause_and_col_list
                 { $$ = $1; }
 
@@ -6647,6 +6652,26 @@ 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)
)
+                        {
+                          RelExpr *re = SqlParser_CurrentParser->with_clauses_->getFirstValue(&tmp);
+                          $$=re->copyTree(PARSERHEAP());
+                        }
+                        else
+                        {
+                          $$ = new (PARSERHEAP()) Scan(*$1);
+                          if ($2)
+                            $$->setHint($2);
+
+                          if ($3)
+                            ((Scan*)$$)->setHbaseAccessOptions($3);
+
+                          delete $1;
+                        }
+                      }
+/*
+                      {
                         $$ = new (PARSERHEAP()) Scan(*$1);
                         if ($2) 
                           $$->setHint($2);
@@ -6656,6 +6681,7 @@ table_name_and_hint : table_name optimizer_hint hbase_access_options
                         
                         delete $1;
                       }
+*/
                     | '(' table_name_and_hint ')'
                       {
                         CheckModeSpecial1();
@@ -6953,13 +6979,22 @@ 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
                                 {
-                                  $1->setCorrName(*$2);
-                                  $$ = new (PARSERHEAP()) Scan(*$1);
-                                  if ($3) 
-                                    $$->setHint($3);
-                                  if ($4)
-                                    ((Scan*)$$)->setHbaseAccessOptions($4);
-                                   
+                                   NAString tmp = ((*$1).getQualifiedNameAsString());
+                                   if(SqlParser_CurrentParser->with_clauses_->contains(&tmp)
)
+                                   {     
+                                     RelExpr *re = SqlParser_CurrentParser->with_clauses_->getFirstValue(&tmp);
+                                     RenameTable *rt = new (PARSERHEAP()) RenameTable(re,
*$2);
+                                     $$=rt->copyTree(PARSERHEAP());
+                                  }
+                                  else
+                                  {
+                                    $1->setCorrName(*$2);
+                                    $$ = new (PARSERHEAP()) Scan(*$1);
+                                    if ($3) 
+                                      $$->setHint($3);
+                                    if ($4)
+                                      ((Scan*)$$)->setHbaseAccessOptions($4);
+                                  }  
                                   delete $1;
                                   delete $2;
                                 }
@@ -7001,6 +7036,46 @@ rel_subquery_and_as_clause : rel_subquery as_clause
                                $$ = $2;
                              }
 
+with_clause_list : with_clause
+                     {  $$ = $1 ; }
+
+                   | with_clause_list ',' correlation_name TOK_AS rel_subquery 
+                      {
+                         RelRoot *root = new (PARSERHEAP())
+                                            RelRoot($5, REL_ROOT);
+                         $$= new (PARSERHEAP()) RenameTable(root, *$3); 
+
+                         //Duplicated definition of WITH
+                         if(SqlParser_CurrentParser->with_clauses_->contains($3) )
+                          {
+                            *SqlParser_Diags << DgSqlCode(-1433)
+                                             << DgString0((*$3).toCharStar());
+                             YYERROR;
+                          }
+
+                          SqlParser_CurrentParser->with_clauses_->insert($3 , $$);
+
+                      }
+
+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())
@@ -14684,6 +14759,11 @@ 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)

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/947797de/core/sql/sqlci/sqlci_lex.ll
----------------------------------------------------------------------
diff --git a/core/sql/sqlci/sqlci_lex.ll b/core/sql/sqlci/sqlci_lex.ll
index 4f8b4a7..2e518a6 100755
--- a/core/sql/sqlci/sqlci_lex.ll
+++ b/core/sql/sqlci/sqlci_lex.ll
@@ -425,6 +425,7 @@ B			[ \t\n]+
 [Ww][Hh][Ii][Ll][Ee]                   return_IDENT_or_TOKEN(WHILE, 0);
 [Ss][Ii][Gg][Nn][Aa][Ll]	       return_IDENT_or_TOKEN(SIGNAL, 0);
 [Ww][Ii][Tt][Hh][Oo][Uu][Tt]           return_IDENT_or_TOKEN(WITHOUT, 0);
+[Ww][Ii][Tt][Hh]                       return_IDENT_or_TOKEN(WITH, 0);
 [Hh][Oo][Ll][Dd]                       return_IDENT_or_TOKEN(HOLD, 0);
 [Pp][Aa][Rr][Ss][Ee][Rr][Ff][Ll][Aa][Gg][Ss] return_IDENT_or_TOKEN(PARSERFLAGS, 0);
 [Tt][Ee][Rr][Mm][Ii][Nn][Aa][Ll]_[Cc][Hh][Aa][Rr][Ss][Ee][Tt] return_IDENT_or_TOKEN(TERMINAL_CHARSET,
0);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/947797de/core/sql/sqlci/sqlci_yacc.y
----------------------------------------------------------------------
diff --git a/core/sql/sqlci/sqlci_yacc.y b/core/sql/sqlci/sqlci_yacc.y
index 6b92a95..ba6feac 100644
--- a/core/sql/sqlci/sqlci_yacc.y
+++ b/core/sql/sqlci/sqlci_yacc.y
@@ -510,6 +510,7 @@ static char * FCString (const char *idString, int isFC)
 %token TERMINAL_CHARSET
 %token TRANSFORM
 %token TRUNCATE
+%token WITH 
 %token UNLOCK
 %token UPD_STATS
 %token UPD_HIST_STATS
@@ -2231,6 +2232,7 @@ dml_type :
 	|	DUP			{$$ = DML_DDL_TYPE;}
 	|	PURGEDATA		{$$ = DML_DDL_TYPE;}
 	|	TRUNCATE		{$$ = DML_DDL_TYPE;}
+	|	WITH                    {$$ = DML_DDL_TYPE;}
 	|	POPULATE		{$$ = DML_DDL_TYPE;}
         |       VALIDATEtoken           {$$ = DML_DDL_TYPE;}
 	|	RECOVER 		{$$ = DML_DDL_TYPE;}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/947797de/core/sql/sqlcomp/parser.cpp
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/parser.cpp b/core/sql/sqlcomp/parser.cpp
index 2c427e5..58b44b2 100644
--- a/core/sql/sqlcomp/parser.cpp
+++ b/core/sql/sqlcomp/parser.cpp
@@ -101,6 +101,11 @@ void Parser::reset(NABoolean on_entry_reset_was_needed)
     Set_SqlParser_Flags(0);
 }
 
+ULng32 cmmHashFunc_NAString(const NAString& str)
+{
+  return (ULng32) NAString::hash(str);
+}
+
 
 Parser::Parser(const CmpContext* cmpContext) 
 {
@@ -151,6 +156,10 @@ Parser::Parser(const CmpContext* cmpContext)
   clearHasOlapFunctions();
 
   HQCKey_ = NULL;
+
+  Lng32 initsize = 10;
+  with_clauses_ =  new (wHeap_) NAHashDictionary<NAString,RelExpr>(&cmmHashFunc_NAString,
initsize , TRUE, wHeap_) ;
+
 }
 
 Parser::~Parser()

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/947797de/core/sql/sqlcomp/parser.h
----------------------------------------------------------------------
diff --git a/core/sql/sqlcomp/parser.h b/core/sql/sqlcomp/parser.h
index c9130b5..eebcadd 100644
--- a/core/sql/sqlcomp/parser.h
+++ b/core/sql/sqlcomp/parser.h
@@ -261,6 +261,8 @@ ItemExpr *get_w_ItemExprTree(const NAWchar * str,
   NABoolean isHQCCacheable()
     { return HQCKey_?HQCKey_->isCacheable():FALSE;  }
 
+  NAHashDictionary<NAString,RelExpr> *with_clauses_;
+
 private:
 
   HQCParseKey* HQCKey_;


Mime
View raw message