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 2017/12/12 18:16:28 UTC

[1/6] incubator-trafodion git commit: add limit clause support for LOAD-INTO statement.

Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 1ce089a0f -> 160785a30


add limit clause support for LOAD-INTO statement.

add limit clause support for LOAD-INTO statement.


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

Branch: refs/heads/master
Commit: 2299f3dfc156ca230c935c4ac150f7037d5d4dde
Parents: f574b54
Author: eedy <cq...@gmail.com>
Authored: Sun Dec 3 19:43:31 2017 +0800
Committer: EEDY <cq...@gmail.com>
Committed: Mon Dec 11 09:38:58 2017 +0800

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


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/2299f3df/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 2580127..4cd13ad 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -17934,12 +17934,34 @@ aqr_option : TOK_SQLCODE '=' NUMERIC_LITERAL_EXACT_NO_SCALE
 
 /* type relx */
 //HBASE LOAD 
-load_statement : TOK_LOAD TOK_TRANSFORM load_sample_option TOK_INTO table_name query_expression
+load_statement : TOK_LOAD TOK_TRANSFORM load_sample_option TOK_INTO table_name query_expression optional_limit_spec
                   {
                     //disabled by default in 0.8.0 release 
                     if (CmpCommon::getDefault(COMP_BOOL_226) != DF_ON)
                       YYERROR; 
 
+                    //limit clause
+                    if ($7)
+                    {
+                      RelExpr *query = $6;
+          
+                      if (query->getFirstNRows() >= 0)
+                        {
+                          // cannot specify LIMIT and FIRST N clauses together.
+                          YYERROR;
+                        }
+                      else
+                        {
+                          NABoolean negate;
+                          if ($7->castToConstValue(negate))
+                            {
+                              ConstValue * limit = (ConstValue*)$7;
+                              Lng32 scale = 0;
+                              query->setFirstNRows(limit->getExactNumericValue(scale));
+                            }
+                        }
+                    }
+
                     $$ = new (PARSERHEAP())
                           HBaseBulkLoadPrep(CorrName(*$5, PARSERHEAP()),
                                             NULL,
@@ -17949,7 +17971,7 @@ load_statement : TOK_LOAD TOK_TRANSFORM load_sample_option TOK_INTO table_name q
                                             //NULL
                                             );  
                     }
-                   | TOK_LOAD optional_hbbload_options TOK_INTO table_name query_expression
+                   | TOK_LOAD optional_hbbload_options TOK_INTO table_name query_expression optional_limit_spec
                     {
                       CharInfo::CharSet stmtCharSet = CharInfo::UnknownCharSet;
                       NAString * stmt = getSqlStmtStr ( stmtCharSet  // out - CharInfo::CharSet &
@@ -17966,6 +17988,26 @@ load_statement : TOK_LOAD TOK_TRANSFORM load_sample_option TOK_INTO table_name q
                           stmt->index(" into ", 0, NAString::ignoreCase);
                        
                       RelRoot *top = finalize($5);
+                      //limit clause
+                      if ($6)
+                      {
+                        if (top->getFirstNRows() >= 0)
+                          {
+                            // cannot specify LIMIT and FIRST N clauses together.
+                            YYERROR;
+                          }
+                        else
+                          {
+                            NABoolean negate;
+                            if ($6->castToConstValue(negate))
+                              {
+                                ConstValue * limit = (ConstValue*)$6;
+                                Lng32 scale = 0;
+                                top->setFirstNRows(limit->getExactNumericValue(scale));
+                                top->setFirstNRowsParam(NULL);
+                              }
+                          }
+                      }
 
                       ExeUtilHBaseBulkLoad * eubl = new (PARSERHEAP()) 
                                         ExeUtilHBaseBulkLoad(CorrName(*$4, PARSERHEAP()),


[4/6] incubator-trafodion git commit: add regression test for new sub limit clauses

Posted by hz...@apache.org.
add regression test for new sub limit clauses


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

Branch: refs/heads/master
Commit: 23f578dc803e1a44820e117294947987a137aba2
Parents: 2299f3d
Author: EEDY <cq...@gmail.com>
Authored: Mon Dec 11 18:01:36 2017 +0800
Committer: EEDY <cq...@gmail.com>
Committed: Mon Dec 11 18:01:36 2017 +0800

----------------------------------------------------------------------
 core/sql/regress/compGeneral/EXPECTED045       | 121 +++++++++++++++++++-
 core/sql/regress/compGeneral/FILTER045         |  17 +++
 core/sql/regress/compGeneral/TEST045           |  46 +++++++-
 core/sql/regress/tools/runregr_compGeneral.ksh |   3 +
 4 files changed, 184 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/23f578dc/core/sql/regress/compGeneral/EXPECTED045
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/EXPECTED045 b/core/sql/regress/compGeneral/EXPECTED045
index 87ead12..ab607a0 100644
--- a/core/sql/regress/compGeneral/EXPECTED045
+++ b/core/sql/regress/compGeneral/EXPECTED045
@@ -34,6 +34,23 @@
 >>obey TEST045(ddl);
 >>--------------------------------------------------------------------
 >>
+>>create table sub_limit_01 ( a int, b char(30), c decimal(8,2) ) ;
+
+--- SQL operation complete.
+>>
+>>insert into sub_limit_01 values
++>(1, 'Limit_str_01', 11.23),(2, 'Limit_str_02', 12.23),(3, 'Limit_str_03', 13.23),
++>(4, 'Limit_str_04', 14.23),(5, 'Limit_str_05', 15.23),(6, 'Limit_str_06', 16.23),
++>(7, 'Limit_str_07', 17.23),(8, 'Limit_str_08', 18.23),(9, 'Limit_str_09', 19.23),
++>(10, 'Limit_str_10', 20.23),(11, 'Limit_str_11', 21.23),(12, 'Limit_str_12', 22.23),
++>(13, 'Limit_str_13', 23.23),(14, 'Limit_str_14', 24.23),(15, 'Limit_str_15', 25.23),
++>(16, 'Limit_str_16', 26.23),(17, 'Limit_str_17', 27.23),(18, 'Limit_str_18', 28.23),
++>(19, 'Limit_str_19', 29.23),(20, 'Limit_str_20', 30.23),(21, 'Limit_str_21', 31.23);
+
+--- 21 row(s) inserted.
+>>
+>>
+>>
 >>create table store_sales
 +>(
 +>    ss_sold_date_sk           int,
@@ -490,8 +507,110 @@
 
 --- SQL operation complete.
 >>
+>>
+>>
+>>--------------------------------------------------------------------
+>>obey TEST045(common_subexpr);
+>>--------------------------------------------------------------------
+>>
+>>--------------------------------------------------------------------
+>>-- test sub-expressions with limit clause
+>>--------------------------------------------------------------------
+>>
+>>create table sub_limit_02 as select * from sub_limit_01 limit 1;
+
+--- 1 row(s) inserted.
+>>create table sub_limit_03 (a int , b char(30), c decimal(8,2)) as select * from sub_limit_01 limit 2;
+
+--- 2 row(s) inserted.
+>>
+>>insert into sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+
+--- 2 row(s) inserted.
+>>insert no check into sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+
+--- 2 row(s) inserted.
+>>insert with no rollback into table sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+
+--- 2 row(s) inserted.
+>>insert overwrite table sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+
+--- 2 row(s) inserted.
+>>insert with no rollback into sub_limit_02 (*) select * from sub_limit_01 order by a,c limit 2;
+
+--- 2 row(s) inserted.
+>>insert NOMVLOG into sub_limit_02 (a, b) select a, b from sub_limit_01 order by a,b limit 2;
+
+--- 2 row(s) inserted.
+>>
+>>load into sub_limit_03 select * from sub_limit_01 limit 16;
+Task:  LOAD            Status: Started    Object: TRAFODION.T045_CSES.SUB_LIMIT_03
+Task:  CLEANUP         Status: Started    Time:
+Task:  CLEANUP         Status: Ended      Time:
+Task:  CLEANUP         Status: Ended      Elapsed Time:
+Task:  LOADING DATA    Status: Started    Time:
+       Rows Processed: 16 
+       Error Rows:     0 
+Task:  LOADING DATA    Status: Ended      Time:
+Task:  LOADING DATA    Status: Ended      Elapsed Time:
+Task:  COMPLETION      Status: Started    Time:
+       Rows Loaded:    16 
+Task:  COMPLETION      Status: Ended      Time:
+Task:  COMPLETION      Status: Ended      Elapsed Time:
+
+--- 16 row(s) loaded.
+>>
+>>select * from sub_limit_02 order by a,b,c ;
+
+A            B                               C         
+-----------  ------------------------------  ----------
+
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                             ?
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                             ?
+
+--- 13 row(s) selected.
+>>
+>>select * from sub_limit_03 order by a,b,c ;
+
+A            B                               C         
+-----------  ------------------------------  ----------
+
+          1  Limit_str_01                         11.23
+          1  Limit_str_01                         11.23
+          2  Limit_str_02                         12.23
+          2  Limit_str_02                         12.23
+          3  Limit_str_03                         13.23
+          4  Limit_str_04                         14.23
+          5  Limit_str_05                         15.23
+          6  Limit_str_06                         16.23
+          7  Limit_str_07                         17.23
+          8  Limit_str_08                         18.23
+          9  Limit_str_09                         19.23
+         10  Limit_str_10                         20.23
+         11  Limit_str_11                         21.23
+         12  Limit_str_12                         22.23
+         13  Limit_str_13                         23.23
+         14  Limit_str_14                         24.23
+         15  Limit_str_15                         25.23
+         16  Limit_str_16                         26.23
+
+--- 18 row(s) selected.
+>>
+>>
+>>
 >>--------------------------------------------------------------------
->>obey TEST045(queries);
+>>obey TEST045(with_queries);
 >>--------------------------------------------------------------------
 >>
 >>obey TEST045(enable_cses);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/23f578dc/core/sql/regress/compGeneral/FILTER045
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/FILTER045 b/core/sql/regress/compGeneral/FILTER045
new file mode 100755
index 0000000..b75741f
--- /dev/null
+++ b/core/sql/regress/compGeneral/FILTER045
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+# Specialized filter for  project to filter out
+# 1. Syskey values
+# 2. "Funny names" for index columns appearing multiple times
+#    (done twice, since it may appear multiple times)
+# 3. refreshed elapsed time
+
+fil=$1
+if [ "$fil" = "" ]; then
+  echo "Usage: $0 filename"
+  exit 1
+fi
+
+sed "
+s/\(Time:\) .*$/\1/g
+" $fil

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/23f578dc/core/sql/regress/compGeneral/TEST045
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/TEST045 b/core/sql/regress/compGeneral/TEST045
index 533f747..605051c 100644
--- a/core/sql/regress/compGeneral/TEST045
+++ b/core/sql/regress/compGeneral/TEST045
@@ -28,7 +28,8 @@ obey TEST045(clnup);
 log LOG045 clear;
 obey TEST045(setup);
 obey TEST045(ddl);
-obey TEST045(queries);
+obey TEST045(common_subexpr);
+obey TEST045(with_queries);
 obey TEST045(clnup);
 log;
 exit;
@@ -76,6 +77,19 @@ cqd cse_debug_warnings 'off';
 ?section ddl
 --------------------------------------------------------------------
 
+create table sub_limit_01 ( a int, b char(30), c decimal(8,2) ) ;
+
+insert into sub_limit_01 values
+(1, 'Limit_str_01', 11.23),(2, 'Limit_str_02', 12.23),(3, 'Limit_str_03', 13.23),
+(4, 'Limit_str_04', 14.23),(5, 'Limit_str_05', 15.23),(6, 'Limit_str_06', 16.23),
+(7, 'Limit_str_07', 17.23),(8, 'Limit_str_08', 18.23),(9, 'Limit_str_09', 19.23),
+(10, 'Limit_str_10', 20.23),(11, 'Limit_str_11', 21.23),(12, 'Limit_str_12', 22.23),
+(13, 'Limit_str_13', 23.23),(14, 'Limit_str_14', 24.23),(15, 'Limit_str_15', 25.23),
+(16, 'Limit_str_16', 26.23),(17, 'Limit_str_17', 27.23),(18, 'Limit_str_18', 28.23),
+(19, 'Limit_str_19', 29.23),(20, 'Limit_str_20', 30.23),(21, 'Limit_str_21', 31.23);
+
+
+
 create table store_sales
 (
     ss_sold_date_sk           int,
@@ -498,8 +512,36 @@ update statistics for table date_dim on every column;
 update statistics for table date_dim on (d_qoy, d_year);
 update statistics for table store_sales on every column;
 
+
+
+--------------------------------------------------------------------
+?section common_subexpr
+--------------------------------------------------------------------
+
+--------------------------------------------------------------------
+-- test sub-expressions with limit clause
+--------------------------------------------------------------------
+
+create table sub_limit_02 as select * from sub_limit_01 limit 1;
+create table sub_limit_03 (a int , b char(30), c decimal(8,2)) as select * from sub_limit_01 limit 2;
+
+insert into sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+insert no check into sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+insert with no rollback into table sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+insert overwrite table sub_limit_02 select * from sub_limit_01 order by a,c limit 2;
+insert with no rollback into sub_limit_02 (*) select * from sub_limit_01 order by a,c limit 2;
+insert NOMVLOG into sub_limit_02 (a, b) select a, b from sub_limit_01 order by a,b limit 2;
+
+load into sub_limit_03 select * from sub_limit_01 limit 16;
+
+select * from sub_limit_02 order by a,b,c ;
+
+select * from sub_limit_03 order by a,b,c ;
+
+
+
 --------------------------------------------------------------------
-?section queries
+?section with_queries
 --------------------------------------------------------------------
 
 obey TEST045(enable_cses);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/23f578dc/core/sql/regress/tools/runregr_compGeneral.ksh
----------------------------------------------------------------------
diff --git a/core/sql/regress/tools/runregr_compGeneral.ksh b/core/sql/regress/tools/runregr_compGeneral.ksh
index c854766..d151f51 100755
--- a/core/sql/regress/tools/runregr_compGeneral.ksh
+++ b/core/sql/regress/tools/runregr_compGeneral.ksh
@@ -379,6 +379,9 @@ cp $scriptsdir/tools/runmxci.ksh $REGRRUNDIR 2>$NULL
 echo "copying FILTER042 to $REGRRUNDIR"
 cp $REGRTSTDIR/FILTER042 $REGRRUNDIR 2>$NULL
 
+echo "copying FILTER045 to $REGRRUNDIR"
+cp $REGRTSTDIR/FILTER045 $REGRRUNDIR 2>$NULL
+
 if [ $diffOnly -eq 0 ]; then
    if [ "$REGRTSTDIR" != "$REGRRUNDIR" ]; then
       echo "copying FILTER_TIME.AWK to $REGRRUNDIR"


[5/6] incubator-trafodion git commit: fix potential result mismatch caused by result order

Posted by hz...@apache.org.
fix potential result mismatch caused by result order


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

Branch: refs/heads/master
Commit: 6cf245b873e784fe84edc2ce18bff2ca3246efb3
Parents: 23f578d
Author: EEDY <cq...@gmail.com>
Authored: Mon Dec 11 18:54:19 2017 +0800
Committer: EEDY <cq...@gmail.com>
Committed: Mon Dec 11 18:54:19 2017 +0800

----------------------------------------------------------------------
 core/sql/regress/compGeneral/EXPECTED045 | 63 ++++++++-------------------
 core/sql/regress/compGeneral/TEST045     |  4 +-
 2 files changed, 19 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6cf245b8/core/sql/regress/compGeneral/EXPECTED045
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/EXPECTED045 b/core/sql/regress/compGeneral/EXPECTED045
index ab607a0..201b2a3 100644
--- a/core/sql/regress/compGeneral/EXPECTED045
+++ b/core/sql/regress/compGeneral/EXPECTED045
@@ -560,52 +560,23 @@ Task:  COMPLETION      Status: Ended      Elapsed Time:
 
 --- 16 row(s) loaded.
 >>
->>select * from sub_limit_02 order by a,b,c ;
-
-A            B                               C         
------------  ------------------------------  ----------
-
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                             ?
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                             ?
-
---- 13 row(s) selected.
->>
->>select * from sub_limit_03 order by a,b,c ;
-
-A            B                               C         
------------  ------------------------------  ----------
-
-          1  Limit_str_01                         11.23
-          1  Limit_str_01                         11.23
-          2  Limit_str_02                         12.23
-          2  Limit_str_02                         12.23
-          3  Limit_str_03                         13.23
-          4  Limit_str_04                         14.23
-          5  Limit_str_05                         15.23
-          6  Limit_str_06                         16.23
-          7  Limit_str_07                         17.23
-          8  Limit_str_08                         18.23
-          9  Limit_str_09                         19.23
-         10  Limit_str_10                         20.23
-         11  Limit_str_11                         21.23
-         12  Limit_str_12                         22.23
-         13  Limit_str_13                         23.23
-         14  Limit_str_14                         24.23
-         15  Limit_str_15                         25.23
-         16  Limit_str_16                         26.23
-
---- 18 row(s) selected.
+>>select count(*) from sub_limit_02;
+
+(EXPR)              
+--------------------
+
+                  13
+
+--- 1 row(s) selected.
+>>
+>>select count(*) from sub_limit_03;
+
+(EXPR)              
+--------------------
+
+                  18
+
+--- 1 row(s) selected.
 >>
 >>
 >>

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/6cf245b8/core/sql/regress/compGeneral/TEST045
----------------------------------------------------------------------
diff --git a/core/sql/regress/compGeneral/TEST045 b/core/sql/regress/compGeneral/TEST045
index 605051c..f2d7c72 100644
--- a/core/sql/regress/compGeneral/TEST045
+++ b/core/sql/regress/compGeneral/TEST045
@@ -534,9 +534,9 @@ insert NOMVLOG into sub_limit_02 (a, b) select a, b from sub_limit_01 order by a
 
 load into sub_limit_03 select * from sub_limit_01 limit 16;
 
-select * from sub_limit_02 order by a,b,c ;
+select count(*) from sub_limit_02;
 
-select * from sub_limit_03 order by a,b,c ;
+select count(*) from sub_limit_03;
 
 
 


[6/6] incubator-trafodion git commit: Merge [TRAFODION-2804] Limit clause support in statements LOAD/INSERT/CREATE-TABLE + query PR-1334

Posted by hz...@apache.org.
Merge [TRAFODION-2804] Limit clause support in statements LOAD/INSERT/CREATE-TABLE + query PR-1334


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

Branch: refs/heads/master
Commit: 160785a301da04ebc0fa19293c05f04062a217da
Parents: 1ce089a 6cf245b
Author: Hans Zeller <hz...@apache.org>
Authored: Tue Dec 12 18:15:29 2017 +0000
Committer: Hans Zeller <hz...@apache.org>
Committed: Tue Dec 12 18:15:29 2017 +0000

----------------------------------------------------------------------
 core/sql/parser/sqlparser.y                    | 227 +++++++++++++++++++-
 core/sql/regress/compGeneral/EXPECTED045       |  92 +++++++-
 core/sql/regress/compGeneral/FILTER045         |  17 ++
 core/sql/regress/compGeneral/TEST045           |  46 +++-
 core/sql/regress/tools/runregr_compGeneral.ksh |   3 +
 5 files changed, 371 insertions(+), 14 deletions(-)
----------------------------------------------------------------------



[2/6] incubator-trafodion git commit: limit clause support in create-as-select/load-into-select: syntax support

Posted by hz...@apache.org.
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 <cq...@gmail.com>
Authored: Tue Nov 14 17:44:58 2017 +0800
Committer: EEDY <cq...@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(


[3/6] incubator-trafodion git commit: add limit clause for insert-as-select statement

Posted by hz...@apache.org.
add limit clause for insert-as-select statement

add limit clause for insert-as-select statement


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

Branch: refs/heads/master
Commit: f574b540d6ba7de35493a672da544887b7d146e6
Parents: 083f58d
Author: eedy <cq...@gmail.com>
Authored: Wed Nov 22 20:48:35 2017 +0800
Committer: EEDY <cq...@gmail.com>
Committed: Mon Dec 11 09:38:58 2017 +0800

----------------------------------------------------------------------
 core/sql/parser/sqlparser.y | 123 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 116 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/f574b540/core/sql/parser/sqlparser.y
----------------------------------------------------------------------
diff --git a/core/sql/parser/sqlparser.y b/core/sql/parser/sqlparser.y
index 5460024..2580127 100755
--- a/core/sql/parser/sqlparser.y
+++ b/core/sql/parser/sqlparser.y
@@ -19239,9 +19239,31 @@ boolean_primary : predicate
               } 
 
 /* type relx */
-Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_expression order_by_clause access_type
+Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_expression order_by_clause access_type optional_limit_spec
         {
           if (!finalizeAccessOptions($5, $7)) YYERROR;
+
+          //limit clause
+          if ($8)
+          {
+	     RelExpr *query = $5;
+
+            if (query->getFirstNRows() >= 0)
+              {
+                // cannot specify LIMIT and FIRST N clauses together.
+                YYERROR;
+              }
+            else
+              {
+                NABoolean negate;
+                if ($8->castToConstValue(negate))
+                  {
+                    ConstValue * limit = (ConstValue*)$8;
+                    Lng32 scale = 0;
+                    query->setFirstNRows(limit->getExactNumericValue(scale));
+                  }
+              }
+          }
 		  
           // insert into all columns
           $$ = new (PARSERHEAP())
@@ -19272,10 +19294,32 @@ Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_ex
 	   
         }
         |
-     no_check_log no_rollback TOK_INTO TOK_TABLE table_name query_expression order_by_clause access_type
+     no_check_log no_rollback TOK_INTO TOK_TABLE table_name query_expression order_by_clause access_type optional_limit_spec
         {
           if (!finalizeAccessOptions($6, $8)) YYERROR;
-		  
+
+          //limit clause
+          if ($9)
+          {
+	     RelExpr *query = $6;
+
+            if (query->getFirstNRows() >= 0)
+              {
+                // cannot specify LIMIT and FIRST N clauses together.
+                YYERROR;
+              }
+            else
+              {
+                NABoolean negate;
+                if ($9->castToConstValue(negate))
+                  {
+                    ConstValue * limit = (ConstValue*)$9;
+                    Lng32 scale = 0;
+                    query->setFirstNRows(limit->getExactNumericValue(scale));
+                  }
+              }
+          }
+  
           // insert into all columns
           $$ = new (PARSERHEAP())
             Insert(CorrName(*$5, PARSERHEAP()),
@@ -19302,10 +19346,32 @@ Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_ex
 	   delete $5;
         }
         |
-        TOK_OVERWRITE TOK_TABLE table_name query_expression order_by_clause access_type
+        TOK_OVERWRITE TOK_TABLE table_name query_expression order_by_clause access_type optional_limit_spec
         {
           if (!finalizeAccessOptions($4, $6)) YYERROR;
-		  
+
+          //limit clause
+          if ($7)
+          {
+	     RelExpr *query = $4;
+
+            if (query->getFirstNRows() >= 0)
+              {
+                // cannot specify LIMIT and FIRST N clauses together.
+                YYERROR;
+              }
+            else
+              {
+                NABoolean negate;
+                if ($7->castToConstValue(negate))
+                  {
+                    ConstValue * limit = (ConstValue*)$7;
+                    Lng32 scale = 0;
+                    query->setFirstNRows(limit->getExactNumericValue(scale));
+                  }
+              }
+          }
+
           // insert into all columns
           $$ = new (PARSERHEAP())
             Insert(CorrName(*$3, PARSERHEAP()),
@@ -19320,10 +19386,32 @@ Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_ex
           delete $3;
         }  
             
-          | no_check_log no_rollback TOK_INTO  table_name '(' '*' ')' query_expression order_by_clause access_type
+          | no_check_log no_rollback TOK_INTO  table_name '(' '*' ')' query_expression order_by_clause access_type optional_limit_spec
         {
           if (!finalizeAccessOptions($8, $10)) YYERROR;
 
+          //limit clause
+          if ($11)
+          {
+	     RelExpr *query = $8;
+
+            if (query->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;
+                    query->setFirstNRows(limit->getExactNumericValue(scale));
+                  }
+              }
+          }
+
           // insert into all columns --
           // Tandem extension to INSERT statement;
           // just ignore the redundant "(*)" columnlist.
@@ -19406,8 +19494,29 @@ Rest_Of_insert_statement : no_check_log no_rollback TOK_INTO table_name query_ex
 		  
                   delete $4;
                 }
-          | no_check_log no_rollback TOK_INTO table_name '(' column_list ')' query_expression order_by_clause
+          | no_check_log no_rollback TOK_INTO table_name '(' column_list ')' query_expression order_by_clause optional_limit_spec
                 {
+                  //limit clause
+                  if ($10)
+                    {
+          	        RelExpr *query = $8;
+                      if (query->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;
+                              query->setFirstNRows(limit->getExactNumericValue(scale));
+                            }
+                        }
+                    }
+                
                   // insert into specified columns
                   $$ = new (PARSERHEAP())
                     Insert(CorrName(*$4, PARSERHEAP()),