You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tajo.apache.org by hy...@apache.org on 2013/06/26 09:11:57 UTC
git commit: TAJO-74: Refactor parser rules of SQL.g. (hyunsik)
Updated Branches:
refs/heads/master d3e3fa5e7 -> 73d5b1ee4
TAJO-74: Refactor parser rules of SQL.g. (hyunsik)
Project: http://git-wip-us.apache.org/repos/asf/incubator-tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tajo/commit/73d5b1ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tajo/tree/73d5b1ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tajo/diff/73d5b1ee
Branch: refs/heads/master
Commit: 73d5b1ee447688f1c1d24956d8f3b11635a95a44
Parents: d3e3fa5
Author: Hyunsik Choi <hy...@apache.org>
Authored: Wed Jun 26 16:11:24 2013 +0900
Committer: Hyunsik Choi <hy...@apache.org>
Committed: Wed Jun 26 16:11:24 2013 +0900
----------------------------------------------------------------------
CHANGES.txt | 5 +-
.../src/main/antlr3/tajo/engine/parser/SQL.g | 444 ++++++++++++-------
.../java/tajo/engine/parser/QueryAnalyzer.java | 2 -
.../tajo/engine/parser/TestQueryAnalyzer.java | 26 --
.../java/tajo/engine/parser/TestSQLParser.java | 63 +--
5 files changed, 301 insertions(+), 239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/73d5b1ee/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b012699..0bd1cad 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,8 @@ Release 0.2.0 - unreleased
IMPROVEMENTS
+ TAJO-74: Refactor parser rules of SQL.g. (hyunsik)
+
TAJO-7: Enabling TajoCli to take multiple lines as one statement. (jinho)
TAJO-72: Rename NQL.g to SQL.g. (hyunsik)
@@ -21,7 +23,8 @@ Release 0.2.0 - unreleased
TAJO-69: Add .reviewboardrc file to the ignore lists of Rat and .gitignore.
(hyunsik)
- TAJO-66: Support compiling and running Tajo with Java7 (Tejas Patil via hsaputra)
+ TAJO-66: Support compiling and running Tajo with Java7 (Tejas Patil via
+ hsaputra)
TAJO-51: Parallel Container Launch of TaskRunnerLauncherImpl. (hyunsik)
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/73d5b1ee/tajo-core/tajo-core-backend/src/main/antlr3/tajo/engine/parser/SQL.g
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/antlr3/tajo/engine/parser/SQL.g b/tajo-core/tajo-core-backend/src/main/antlr3/tajo/engine/parser/SQL.g
index c88d767..0ae3fcf 100644
--- a/tajo-core/tajo-core-backend/src/main/antlr3/tajo/engine/parser/SQL.g
+++ b/tajo-core/tajo-core-backend/src/main/antlr3/tajo/engine/parser/SQL.g
@@ -47,7 +47,6 @@ tokens {
PARAM;
PARAMS;
SEL_LIST;
- SESSION_CLEAR;
SET_QUALIFIER;
SHOW_TABLE;
SHOW_FUNCTION;
@@ -193,8 +192,8 @@ BY : B Y;
CASE : C A S E;
CHARACTER : C H A R A C T E R;
+COALESCE : C O A L E S C E;
COUNT : C O U N T;
-COPY : C O P Y;
CREATE : C R E A T E;
CROSS : C R O S S;
CUBE : C U B E;
@@ -237,6 +236,7 @@ NATIONAL : N A T I O N A L;
NATURAL : N A T U R A L;
NOT : N O T;
NULL : N U L L;
+NULLIF : N U L L I F;
ON : O N;
OUTER : O U T E R;
@@ -320,74 +320,51 @@ BYTEA : B Y T E A; // alias for BLOB
INET4 : I N E T '4';
+
/*
===============================================================================
- SQL Main
+ <data types>
===============================================================================
*/
-sql
- : statement EOF
- ;
-
-statement
- : sessionStatement
- | controlStatement
- | dataStatement
- | dataChangeStatement
- | schemaStatement
- | indexStatement
- ;
-sessionStatement
- : 'session' 'clear' -> ^(SESSION_CLEAR)
- ;
-
-controlStatement
- : '\\' 't' (table)? -> ^(SHOW_TABLE table?)
- | '\\' 'd' table -> ^(DESC_TABLE table)
- | '\\' 'f' -> ^(SHOW_FUNCTION)
- ;
-
-dataStatement
- : query_expression
- | set_stmt
- | copyStatement
- ;
-
-dataChangeStatement
- : insertStmt
- ;
-
-schemaStatement
- : createTableStatement
- | DROP TABLE table -> ^(DROP_TABLE table)
- ;
-
-indexStatement
- : CREATE (u=UNIQUE)? INDEX n=Identifier ON t=table (m=method_specifier)? LEFT_PAREN s=sort_specifier_list RIGHT_PAREN p=param_clause?-> ^(CREATE_INDEX $u? $m? $p? $n $t $s)
- ;
-
-createTableStatement
- : CREATE EXTERNAL TABLE t=table def=tableElements USING f=Identifier p=param_clause? (LOCATION path=Character_String_Literal)
- -> ^(CREATE_TABLE $t EXTERNAL ^(TABLE_DEF $def) ^(USING $f) $p? ^(LOCATION $path))
- | CREATE TABLE t=table (def=tableElements)? (USING s=Identifier)? (p=param_clause)? (AS q=query_expression)?
- -> ^(CREATE_TABLE $t ^(TABLE_DEF $def)? ^(USING $s)? $p? ^(AS $q)?)
- ;
-
-copyStatement
- : COPY t=table FROM path=string_value_expr FORMAT s=Identifier (p=param_clause)? -> ^(COPY $t $path $s $p?)
+data_type
+ : boolean_type
+ | bit_type
+ | varbit_type
+ | binary_type
+ | varbinary_type
+ | blob_type
+ | INET4
+ | character_string_type
+ | datetime_type
+ | numeric_type
;
-tableElements
- : LEFT_PAREN fieldElement (COMMA fieldElement)* RIGHT_PAREN -> fieldElement+
+character_string_type
+ : char_type
+ | varchar_type
+ | nchar_type
+ | nvarchar_type
+ | TEXT
;
-fieldElement
- : Identifier fieldType -> ^(FIELD_DEF Identifier fieldType)
+numeric_type
+ : int1_type
+ | int2_type
+ | int4_type
+ | int8_type
+ | float4_type
+ | float_type
+ | float8_type
+ | number_type
;
-fieldType
- : dataType
+datetime_type
+ : DATE
+ | TIME
+ | timetz_type
+ | TIMESTAMP
+ | timestamptz_type
;
precision_param
@@ -476,34 +453,81 @@ blob_type
| BYTEA -> BLOB
;
-dataType
- : boolean_type
- | bit_type
- | varbit_type
- | int1_type
- | int2_type
- | int4_type
- | int8_type
- | float4_type
- | float_type
- | float8_type
- | number_type
- | char_type
- | varchar_type
- | nchar_type
- | nvarchar_type
- | DATE
- | TIME
- | timetz_type
- | TIMESTAMP
- | timestamptz_type
- | TEXT
- | binary_type
- | varbinary_type
- | blob_type
- | INET4
+/*
+===============================================================================
+ SQL statement (Start Symbol)
+===============================================================================
+*/
+sql
+ : statement EOF
+ ;
+
+statement
+ : data_statement
+ | data_change_statement
+ | schema_statement
+ | index_statement
;
+data_statement
+ : query_expression
+ | set_stmt
+ ;
+
+data_change_statement
+ : insert_statement
+ ;
+
+schema_statement
+ : create_table_statement
+ | DROP TABLE table -> ^(DROP_TABLE table)
+ ;
+
+index_statement
+ : CREATE (u=UNIQUE)? INDEX n=Identifier ON t=table (m=method_specifier)?
+ LEFT_PAREN s=sort_specifier_list RIGHT_PAREN p=param_clause?
+ -> ^(CREATE_INDEX $u? $m? $p? $n $t $s)
+ ;
+
+create_table_statement
+ : CREATE EXTERNAL TABLE t=table def=table_elements USING f=Identifier
+ p=param_clause? (LOCATION path=Character_String_Literal)
+ -> ^(CREATE_TABLE $t EXTERNAL ^(TABLE_DEF $def) ^(USING $f) $p?
+ ^(LOCATION $path))
+ | CREATE TABLE t=table (def=table_elements)? (USING s=Identifier)?
+ (p=param_clause)? (AS q=query_expression)?
+ -> ^(CREATE_TABLE $t ^(TABLE_DEF $def)? ^(USING $s)? $p? ^(AS $q)?)
+ ;
+
+table_elements
+ : LEFT_PAREN field_element (COMMA field_element)* RIGHT_PAREN
+ -> field_element+
+ ;
+
+field_element
+ : Identifier field_type -> ^(FIELD_DEF Identifier field_type)
+ ;
+
+field_type
+ : data_type
+ ;
+
+/*
+===============================================================================
+ <insert stmt>
+===============================================================================
+*/
+
+insert_statement
+ : INSERT 'into' table (LEFT_PAREN column_reference_list RIGHT_PAREN)? 'values' array
+ -> ^(INSERT ^(TABLE table) ^(VALUES array) ^(TARGET_FIELDS column_reference_list)?)
+ ;
+
+/*
+===============================================================================
+ <query_expression>
+===============================================================================
+*/
query_expression
: query_expression_body
;
@@ -514,7 +538,8 @@ query_expression_body
;
non_join_query_expression
- : (non_join_query_term | joined_table (UNION | EXCEPT)^ (ALL|DISTINCT)? query_term) ((UNION | EXCEPT)^ (ALL|DISTINCT)? query_term)*
+ : (non_join_query_term | joined_table (UNION | EXCEPT)^ (ALL|DISTINCT)? query_term)
+ ((UNION | EXCEPT)^ (ALL|DISTINCT)? query_term)*
;
query_term
@@ -523,7 +548,8 @@ query_term
;
non_join_query_term
- : ( non_join_query_primary | joined_table INTERSECT^ (ALL|DISTINCT)? query_primary) (INTERSECT^ (ALL|DISTINCT)? query_primary)*
+ : ( non_join_query_primary | joined_table INTERSECT^ (ALL|DISTINCT)? query_primary)
+ (INTERSECT^ (ALL|DISTINCT)? query_primary)*
;
query_primary
@@ -537,61 +563,47 @@ non_join_query_primary
;
simple_table
-options {k=1;}
+ options {k=1;}
: query_specification
;
query_specification
- : SELECT setQualifier? selectList from_clause? where_clause? groupby_clause? having_clause? orderby_clause? limit_clause?
- -> ^(SELECT from_clause? setQualifier? selectList where_clause? groupby_clause? having_clause? orderby_clause? limit_clause?)
+ : SELECT set_qualifier? select_list from_clause? where_clause? groupby_clause? having_clause?
+ orderby_clause? limit_clause?
+ -> ^(SELECT from_clause? set_qualifier? select_list where_clause? groupby_clause?
+ having_clause? orderby_clause? limit_clause?)
;
-insertStmt
- : INSERT 'into' table (LEFT_PAREN column_reference RIGHT_PAREN)? 'values' array
- -> ^(INSERT ^(TABLE table) ^(VALUES array) ^(TARGET_FIELDS column_reference)?)
- ;
-
-selectList
+select_list
: MULTIPLY -> ^(SEL_LIST ALL)
- | derivedColumn (COMMA derivedColumn)* -> ^(SEL_LIST derivedColumn+)
+ | derived_column (COMMA derived_column)* -> ^(SEL_LIST derived_column+)
;
-setQualifier
+set_qualifier
: DISTINCT -> ^(SET_QUALIFIER DISTINCT)
| ALL -> ^(SET_QUALIFIER ALL)
;
-derivedColumn
- : bool_expr asClause? -> ^(COLUMN bool_expr asClause?)
+derived_column
+ : boolean_value_expression as_clause? -> ^(COLUMN boolean_value_expression as_clause?)
;
-fieldName
+column_reference
: (t=Identifier DOT)? b=Identifier -> ^(FIELD_NAME $b $t?)
;
-asClause
- : (AS)? fieldName
+as_clause
+ : (AS)? column_reference
;
-column_reference
- : fieldName (COMMA fieldName)* -> fieldName+
+column_reference_list
+ : column_reference (COMMA column_reference)* -> column_reference+
;
table
: Identifier
;
-// TODO - to be improved
-funcCall
- : Identifier LEFT_PAREN funcArgs? RIGHT_PAREN -> ^(FUNCTION[$Identifier.text] funcArgs?)
- | COUNT LEFT_PAREN funcArgs RIGHT_PAREN -> ^(COUNT_VAL funcArgs)
- | COUNT LEFT_PAREN MULTIPLY RIGHT_PAREN -> ^(COUNT_ROWS)
- ;
-
-funcArgs
- : bool_expr (COMMA bool_expr)* -> bool_expr+
- ;
-
from_clause
: FROM^ table_reference_list
;
@@ -654,7 +666,7 @@ join_condition
;
named_columns_join
- : USING LEFT_PAREN f=column_reference RIGHT_PAREN -> ^(USING $f)
+ : USING LEFT_PAREN f=column_reference_list RIGHT_PAREN -> ^(USING $f)
;
table_primary
@@ -665,6 +677,29 @@ where_clause
: WHERE^ search_condition
;
+/*
+===============================================================================
+ <routine invocation>
+
+ Invoke an SQL-invoked routine.
+===============================================================================
+*/
+
+routine_invocation
+ : Identifier LEFT_PAREN funcArgs? RIGHT_PAREN -> ^(FUNCTION[$Identifier.text] funcArgs?)
+ | COUNT LEFT_PAREN funcArgs RIGHT_PAREN -> ^(COUNT_VAL funcArgs)
+ | COUNT LEFT_PAREN MULTIPLY RIGHT_PAREN -> ^(COUNT_ROWS)
+ ;
+
+funcArgs
+ : boolean_value_expression (COMMA boolean_value_expression)* -> boolean_value_expression+
+ ;
+
+/*
+===============================================================================
+ <groupby clause>
+===============================================================================
+*/
groupby_clause
: GROUP BY g=grouping_element_list -> ^(GROUP_BY $g)
;
@@ -681,8 +716,8 @@ grouping_element
;
ordinary_grouping_set
- : column_reference
- | LEFT_PAREN! column_reference RIGHT_PAREN!
+ : column_reference_list
+ | LEFT_PAREN! column_reference_list RIGHT_PAREN!
;
rollup_list
@@ -698,9 +733,17 @@ empty_grouping_set
;
having_clause
- : HAVING^ bool_expr
+ : HAVING^ boolean_value_expression
;
+/*
+===============================================================================
+ <orderby clause>
+
+ Specify a comparison of two row values.
+===============================================================================
+*/
+
orderby_clause
: ORDER BY sort_specifier_list -> ^(ORDER_BY sort_specifier_list)
;
@@ -710,7 +753,7 @@ sort_specifier_list
;
sort_specifier
- : fn=fieldName a=order_specification? o=null_ordering? -> ^(SORT_KEY $fn $a? $o?)
+ : fn=column_reference a=order_specification? o=null_ordering? -> ^(SORT_KEY $fn $a? $o?)
;
order_specification
@@ -719,7 +762,7 @@ order_specification
;
limit_clause
- : LIMIT e=expr -> ^(LIMIT $e)
+ : LIMIT e=numeric_value_expression -> ^(LIMIT $e)
;
null_ordering
@@ -727,12 +770,20 @@ null_ordering
| NULL LAST -> ^(NULL_ORDER LAST)
;
+/*
+===============================================================================
+ <set stmt>
+
+ Specify a comparison of two row values.
+===============================================================================
+*/
+
set_stmt
: SET (UNION|INTERSECT|EXCEPT) table
;
search_condition
- : bool_expr
+ : boolean_value_expression
;
param_clause
@@ -740,14 +791,20 @@ param_clause
;
param
- : k=Character_String_Literal EQUAL v=bool_expr -> ^(PARAM $k $v)
+ : k=Character_String_Literal EQUAL v=numeric_value_expression -> ^(PARAM $k $v)
;
method_specifier
: USING m=Identifier -> ^(USING[$m.text])
;
-bool_expr
+/*
+===============================================================================
+ <boolean value expression>
+===============================================================================
+*/
+
+boolean_value_expression
: and_predicate (OR^ and_predicate)*
;
@@ -768,18 +825,23 @@ is_clause
: IS NOT? t=truth_value -> ^(IS NOT? $t)
;
-
truth_value
: TRUE | FALSE | UNKNOWN
;
boolean_primary
: predicate
- | expr
- | LEFT_PAREN! bool_expr RIGHT_PAREN!
+ | numeric_value_expression
+ | LEFT_PAREN! boolean_value_expression RIGHT_PAREN!
| case_expression
;
+/*
+===============================================================================
+ <predicate>
+===============================================================================
+*/
+
predicate
: comparison_predicate
| in_predicate
@@ -787,44 +849,93 @@ predicate
| null_predicate
;
-in_predicate
- : expr NOT? IN array -> ^(IN expr array NOT?)
+/*
+===============================================================================
+ <comparison_predicate>
+
+ Specify a comparison of two row values.
+===============================================================================
+*/
+comparison_predicate
+ options{k=1;}
+ : l=numeric_value_expression c=comp_op r=numeric_value_expression -> ^($c $l $r)
+ ;
+
+comp_op
+ : EQUAL
+ | NOT_EQUAL
+ | LTH
+ | LEQ
+ | GTH
+ | GEQ
+ ;
+
+/*
+===============================================================================
+ <in_predicate>
+
+ Specify a quantified comparison.
+===============================================================================
+*/
+
+in_predicate : v=numeric_value_expression NOT? IN a=in_predicate_value -> ^(IN $v $a NOT?);
+
+in_predicate_value
+ : LEFT_PAREN! in_value_list RIGHT_PAREN!
;
+in_value_list
+ : numeric_value_expression ( COMMA numeric_value_expression )* -> numeric_value_expression+;
+
+/*
+===============================================================================
+ <like_predicate>
+
+ Specify a pattern-match comparison.
+===============================================================================
+*/
+
like_predicate
- : f=fieldName NOT? LIKE s=string_value_expr -> ^(LIKE NOT? $f $s)
+ : f=column_reference NOT? LIKE s=Character_String_Literal -> ^(LIKE NOT? $f $s)
;
+/*
+===============================================================================
+ <null_predicate>
+
+ Specify a test for a null value.
+===============================================================================
+*/
+
null_predicate
- : f=expr IS (n=NOT)? NULL -> ^(IS $f NULL $n?)
+ : f=numeric_value_expression IS (n=NOT)? NULL -> ^(IS $f NULL $n?)
;
-comparison_predicate
- : expr EQUAL^ expr
- | expr NOT_EQUAL^ expr
- | expr LTH^ expr
- | expr LEQ^ expr
- | expr GTH^ expr
- | expr GEQ^ expr
- ;
+/*
+===============================================================================
+ <numeric_value_expression>
+
+ Specify a comparison of two row values.
+===============================================================================
+*/
-expr
- : multExpr ((PLUS|MINUS)^ multExpr)*
+numeric_value_expression
+ : term ((PLUS|MINUS)^ term)*
;
-multExpr
- : atom ((MULTIPLY|DIVIDE|MODULAR)^ atom)*
+term
+ : numeric_primary ((MULTIPLY|DIVIDE|MODULAR)^ numeric_primary)*
;
array
: LEFT_PAREN literal (COMMA literal )* RIGHT_PAREN -> literal+
;
-atom
+numeric_primary
: literal
- | fieldName
- | LEFT_PAREN! expr RIGHT_PAREN!
- | funcCall
+ | column_reference
+ | LEFT_PAREN! numeric_value_expression RIGHT_PAREN!
+ | routine_invocation
;
literal
@@ -850,21 +961,36 @@ sign
: PLUS | MINUS
;
-////////////////////////////////
-// Case Statement
-////////////////////////////////
+/*
+===============================================================================
+ case_expression
+===============================================================================
+*/
+
case_expression
: case_specification
;
+case_abbreviation
+ : NULLIF LEFT_PAREN numeric_value_expression COMMA boolean_value_expression RIGHT_PAREN
+ | COALESCE LEFT_PAREN numeric_value_expression ( COMMA boolean_value_expression )+ RIGHT_PAREN
+ ;
+
case_specification
- : searched_case
+ : simple_case
+ | searched_case
+ ;
+
+simple_case
+ : CASE numeric_value_expression ( simple_when_clause )+ ( else_clause )? END
;
searched_case
: CASE^ (searched_when_clause)+ (else_clause)? END!
;
+simple_when_clause : WHEN numeric_value_expression THEN result ;
+
searched_when_clause
: WHEN c=search_condition THEN r=result -> ^(WHEN $c $r)
;
@@ -874,7 +1000,7 @@ else_clause
;
result
- : bool_expr
+ : numeric_value_expression | NULL
;
// Operators
@@ -918,9 +1044,9 @@ COMMENT
===============================================================================
*/
-// Regular Expressions for Tokens
-Identifier : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|Digit|'_'|':')*
- ;
+Identifier
+ : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|Digit|'_'|':')*
+ ;
/*
===============================================================================
@@ -935,8 +1061,10 @@ fragment
Extended_Control_Characters : '\u0080' .. '\u009F';
Character_String_Literal
- : Quote ( ESC_SEQ | ~('\\'|Quote) )* Quote {setText(getText().substring(1, getText().length()-1));}
- | Double_Quote ( ESC_SEQ | ~('\\'|Double_Quote) )* Double_Quote {setText(getText().substring(1, getText().length()-1));}
+ : Quote ( ESC_SEQ | ~('\\'|Quote) )* Quote
+ { setText(getText().substring(1, getText().length()-1)); }
+ | Double_Quote ( ESC_SEQ | ~('\\'|Double_Quote) )* Double_Quote
+ { setText(getText().substring(1, getText().length()-1)); }
;
Quote
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/73d5b1ee/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
index f50beda..b203658 100644
--- a/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/main/java/tajo/engine/parser/QueryAnalyzer.java
@@ -971,8 +971,6 @@ public final class QueryAnalyzer {
return StatementType.INTERSECT;
case SQLParser.INSERT:
return StatementType.INSERT;
- case SQLParser.COPY:
- return StatementType.COPY;
case SQLParser.CREATE_INDEX:
return StatementType.CREATE_INDEX;
case SQLParser.CREATE_TABLE:
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/73d5b1ee/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestQueryAnalyzer.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestQueryAnalyzer.java b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestQueryAnalyzer.java
index 99865dc..1c5905d 100644
--- a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestQueryAnalyzer.java
+++ b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestQueryAnalyzer.java
@@ -650,30 +650,4 @@ public class TestQueryAnalyzer {
QueryBlock.Target t2 = (QueryBlock.Target) t1.clone();
assertEquals(t1,t2);
}
-
- final static String [] CopyStmt = {
- "copy lineitem from '/tmp/tpch/lineitem' format rcfile",
- "copy lineitem from '/tmp/tpch/lineitem' format csv with ('csv.delimiter' = '|')"
- };
-
- @Test
- public void testCopy1() {
- CopyStmt copyStmt =
- (CopyStmt) analyzer.parse(CopyStmt[0]).getParseTree();
- assertEquals("lineitem", copyStmt.getTableName());
- assertEquals(new Path("/tmp/tpch/lineitem"), copyStmt.getPath());
- assertEquals(StoreType.RCFILE, copyStmt.getStoreType());
- assertFalse(copyStmt.hasParams());
- }
-
- @Test
- public void testCopy2() {
- CopyStmt copyStmt =
- (CopyStmt) analyzer.parse(CopyStmt[1]).getParseTree();
- assertEquals("lineitem", copyStmt.getTableName());
- assertEquals(new Path("/tmp/tpch/lineitem"), copyStmt.getPath());
- assertEquals(StoreType.CSV, copyStmt.getStoreType());
- assertTrue(copyStmt.hasParams());
- assertEquals("|", copyStmt.getParams().get("csv.delimiter"));
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tajo/blob/73d5b1ee/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestSQLParser.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestSQLParser.java b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestSQLParser.java
index 8858d7f..d0a6f80 100644
--- a/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestSQLParser.java
+++ b/tajo-core/tajo-core-backend/src/test/java/tajo/engine/parser/TestSQLParser.java
@@ -34,7 +34,6 @@ public class TestSQLParser {
"select id, name, age, gender from people", // 0
"select title, ISBN from Books", // 1
"select studentId from students", // 2
- "session clear", // 3
"select id, name, age, gender from people as p, students as s", // 4
"select name, addr, sum(score) from students group by name, addr", // 5
"select name, addr, age from people where age > 30", // 6
@@ -107,7 +106,7 @@ public class TestSQLParser {
@Test
public void testColumnFamily() throws TQLSyntaxError {
- Tree ast = parseQuery(selQueries[9]);
+ Tree ast = parseQuery(selQueries[8]);
assertEquals(SQLParser.SELECT, ast.getType());
assertEquals(SQLParser.SEL_LIST, ast.getChild(1).getType());
assertEquals(SQLParser.COLUMN, ast.getChild(1).getChild(0).getType());
@@ -121,13 +120,13 @@ public class TestSQLParser {
@Test
public void testSetQualifier() throws TQLSyntaxError {
- Tree ast = parseQuery(selQueries[10]);
+ Tree ast = parseQuery(selQueries[9]);
assertEquals(SQLParser.SELECT, ast.getType());
assertEquals(SQLParser.SET_QUALIFIER, ast.getChild(1).getType());
assertEquals(SQLParser.DISTINCT, ast.getChild(1).getChild(0).getType());
assertSetListofSetQualifierTest(ast);
- ast = parseQuery(selQueries[11]);
+ ast = parseQuery(selQueries[10]);
assertEquals(SQLParser.SELECT, ast.getType());
assertEquals(SQLParser.SET_QUALIFIER, ast.getChild(1).getType());
assertEquals(SQLParser.ALL, ast.getChild(1).getChild(0).getType());
@@ -142,15 +141,8 @@ public class TestSQLParser {
}
@Test
- public void testSessionClear() throws RecognitionException,
- TQLSyntaxError {
- Tree tree = parseQuery(selQueries[3]);
- assertEquals(tree.getType(), SQLParser.SESSION_CLEAR);
- }
-
- @Test
public void testWhereClause() throws RecognitionException, TQLSyntaxError {
- Tree tree = parseQuery(selQueries[6]);
+ Tree tree = parseQuery(selQueries[5]);
assertEquals(tree.getType(), SQLParser.SELECT);
tree = tree.getChild(2).getChild(0);
@@ -614,39 +606,6 @@ public class TestSQLParser {
assertEquals(ast.getChild(0).getText(), "abc");
}
- static String[] copyStmts = {
- "copy employee from '/tmp/table1' format csv with ('csv.delimiter' = '|')"
- };
-
- @Test
- public void testCopyTable() throws RecognitionException, TQLSyntaxError {
- Tree ast = parseQuery(copyStmts[0]);
- assertEquals(ast.getType(), SQLParser.COPY);
- int idx = 0;
- assertEquals("employee", ast.getChild(idx++).getText());
- assertEquals("/tmp/table1", ast.getChild(idx++).getText());
- assertEquals("csv", ast.getChild(idx++).getText());
- assertEquals(SQLParser.PARAMS, ast.getChild(idx).getType());
- Tree params = ast.getChild(idx);
- assertEquals(SQLParser.PARAM, params.getChild(0).getType());
- assertEquals("csv.delimiter", params.getChild(0).getChild(0).getText());
- assertEquals("|", params.getChild(0).getChild(1).getText());
- }
-
-
- static String[] controlStmts = { "\\t", "\\t abc" };
-
- @Test
- public void testShowTable() throws RecognitionException, TQLSyntaxError {
- Tree ast = parseQuery(controlStmts[0]);
- assertEquals(ast.getType(), SQLParser.SHOW_TABLE);
- assertEquals(ast.getChildCount(), 0);
-
- ast = parseQuery(controlStmts[1]);
- assertEquals(ast.getType(), SQLParser.SHOW_TABLE);
- assertEquals(ast.getChild(0).getText(), "abc");
- }
-
static String[] exprs = {
"1 + 2", // 0
"3 - 4", // 1
@@ -692,32 +651,32 @@ public class TestSQLParser {
@Test
public void testArithEvalTree() throws RecognitionException {
SQLParser p = parseExpr(exprs[0]);
- CommonTree node = (CommonTree) p.expr().getTree();
+ CommonTree node = (CommonTree) p.numeric_value_expression().getTree();
assertEquals(node.getText(), "+");
assertEquals(node.getChild(0).getText(), "1");
assertEquals(node.getChild(1).getText(), "2");
p = parseExpr(exprs[1]);
- node = (CommonTree) p.expr().getTree();
+ node = (CommonTree) p.numeric_value_expression().getTree();
assertEquals(node.getText(), "-");
assertEquals(node.getChild(0).getText(), "3");
assertEquals(node.getChild(1).getText(), "4");
p = parseExpr(exprs[2]);
- node = (CommonTree) p.expr().getTree();
+ node = (CommonTree) p.numeric_value_expression().getTree();
assertEquals(node.getText(), "*");
assertEquals(node.getChild(0).getText(), "5");
assertEquals(node.getChild(1).getText(), "6");
p = parseExpr(exprs[3]);
- node = (CommonTree) p.expr().getTree();
+ node = (CommonTree) p.numeric_value_expression().getTree();
assertEquals(node.getText(), "/");
assertEquals(node.getChild(0).getText(), "7");
assertEquals(node.getChild(1).getText(), "8");
p = parseExpr(exprs[4]);
- node = (CommonTree) p.expr().getTree();
+ node = (CommonTree) p.numeric_value_expression().getTree();
assertEquals(node.getText(), "%");
assertEquals(node.getChild(0).getText(), "10");
assertEquals(node.getChild(1).getText(), "2");
@@ -806,13 +765,13 @@ public class TestSQLParser {
@Test
public void testOrEvalTree() throws RecognitionException {
SQLParser p = parseExpr(exprs[16]);
- CommonTree node = (CommonTree) p.bool_expr().getTree();
+ CommonTree node = (CommonTree) p.boolean_value_expression().getTree();
assertEquals(node.getText(), "or");
assertEquals(node.getChild(0).getText(), ">");
assertEquals(node.getChild(1).getText(), "<");
p = parseExpr(exprs[17]);
- node = (CommonTree) p.bool_expr().getTree();
+ node = (CommonTree) p.boolean_value_expression().getTree();
assertEquals(node.getText(), "or");
assertEquals(node.getChild(0).getText(), ">");
assertEquals(node.getChild(1).getText(), "and");