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 <[email protected]> Authored: Wed Nov 22 20:48:35 2017 +0800 Committer: EEDY <[email protected]> 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()),
