trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [2/6] incubator-trafodion git commit: limit clause support in create-as-select/load-into-select: syntax support
Date Tue, 12 Dec 2017 18:16:29 GMT
limit clause support in create-as-select/load-into-select: syntax support

1. add syntax support


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

Branch: refs/heads/master
Commit: 083f58d651f7e7ca631590fb7479df3b037d16fc
Parents: 0282c85
Author: eedy <cqlcqlc@gmail.com>
Authored: Tue Nov 14 17:44:58 2017 +0800
Committer: EEDY <cqlcqlc@gmail.com>
Committed: Mon Dec 11 09:38:58 2017 +0800

----------------------------------------------------------------------
 core/sql/parser/sqlparser.y | 58 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/083f58d6/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 9e16c20..5460024 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -24940,7 +24940,8 @@ table_definition : create_table_start_tokens ddl_qualified_name
 		   ctas_insert_columns
 		   create_table_as_token 
 		   optional_locking_stmt_list 
-                   query_expression
+                   query_expression 
+                   optional_limit_spec
 		   {
 		     QualifiedName * qn;
 
@@ -24959,6 +24960,32 @@ table_definition : create_table_start_tokens ddl_qualified_name
 			 YYABORT;
 
 		     RelRoot *top = finalize($10);
+                   //limit clause
+                   if ($11)
+                   {
+                     if (top->getFirstNRows() >= 0)
+                       {
+                         // cannot specify LIMIT and FIRST N clauses together.
+                         YYERROR;
+                       }
+                     else
+                       {
+                         NABoolean negate;
+                         if ($11->castToConstValue(negate))
+                           {
+                             ConstValue * limit = (ConstValue*)$11;
+                             Lng32 scale = 0;
+                             top->setFirstNRows(limit->getExactNumericValue(scale));
+                             top->setFirstNRowsParam(NULL);
+                           }
+                         else
+                           {
+                             top->setFirstNRowsParam($11);
+                             top->setFirstNRows(-1);
+                           }
+                       }
+                   }
+
 		     StmtDDLCreateTable *pNode =
 		       new (PARSERHEAP())
 		       StmtDDLCreateTable(
@@ -24997,7 +25024,8 @@ table_definition : create_table_start_tokens ddl_qualified_name
 		   ctas_insert_columns
 		   create_table_as_token 
 		   optional_locking_stmt_list 
-                   query_expression
+                   query_expression 
+                   optional_limit_spec
 		   {
 		     QualifiedName * qn;
 
@@ -25016,6 +25044,32 @@ table_definition : create_table_start_tokens ddl_qualified_name
                        YYABORT;
 
 		     RelRoot *top = finalize($9);
+                   //limit clause
+                   if ($10)
+                   {
+                     if (top->getFirstNRows() >= 0)
+                       {
+                         // cannot specify LIMIT and FIRST N clauses together.
+                         YYERROR;
+                       }
+                     else
+                       {
+                         NABoolean negate;
+                         if ($10->castToConstValue(negate))
+                           {
+                             ConstValue * limit = (ConstValue*)$10;
+                             Lng32 scale = 0;
+                             top->setFirstNRows(limit->getExactNumericValue(scale));
+                             top->setFirstNRowsParam(NULL);
+                           }
+                         else
+                           {
+                             top->setFirstNRowsParam($10);
+                             top->setFirstNRows(-1);
+                           }
+                       }
+                   }
+		     
 		     StmtDDLCreateTable *pNode =
 		       new (PARSERHEAP())
 		       StmtDDLCreateTable(


Mime
View raw message