DefaultDataTypeInserter.g

tree grammar DefaultDataTypeInserter;

options {
    tokenVocab=PigParser;
    ASTLabelType=CommonTree;
    output=AST;
    backtrack=true;
}

@header {
package pig;
}

query :^( QUERY statement* )
;

statement : ^( STATEMENT alias? op_clause )
;

alias : IDENTIFIER
;

op_clause : load_clause | store_clause | filter_clause | distinct_clause
;

load_clause : ^( LOAD QUOTEDSTRING func_clause? as_clause? )
;

as_clause: tuple_def
;

tuple_def : ^( TUPLE_DEF field+ )
;

// Add default types for schema field.
field : ^( FIELD IDENTIFIER )
     -> ^( FIELD IDENTIFIER BYTEARRAY )
      | ^( FIELD IDENTIFIER type )
;

type : simple_type | tuple_type | bag_type | map_type
;

simple_type : INT | LONG | FLOAT | DOUBLE | CHARARRAY | BYTEARRAY
;

tuple_type : tuple_def
;

bag_type : tuple_def
;

map_type : 
;

func_clause : ^( FUNC func_name func_args? )
;

func_name : IDENTIFIER+
;

func_args : QUOTEDSTRING+
;

store_clause : ^( STORE alias QUOTEDSTRING func_clause? )
;

filter_clause : ^( FILTER alias cond )
;

cond : ^( OR cond cond )
     | ^( AND cond cond )
     | ^( NOT cond )
     | ^( NULL expr NOT )
     | ^( FILTEROP expr expr )
     | func_clause
;

expr : ^( PLUS expr expr )
     | ^( MINUS expr expr )
     | ^( STAR expr expr )
     | ^( DIV expr expr )
     | ^( PERCENT expr expr )
     | ^( CAST_EXPR type expr )
     | const_expr
     | var_expr
     | neg_expr
;

var_expr : projectable_expr^ ( dot_proj | pound_proj )*
;

projectable_expr: func_clause | col_ref | bin_expr
;

dot_proj : ^( PERIOD col_ref+ )
;

pound_proj : POUND^ ( QUOTEDSTRING | NULL )
;

bin_expr : ^( BIN_EXPR cond expr expr )
;

neg_expr : MINUS^ expr
;

distinct_clause : ^( DISTINCT alias )
;

col_ref : alias_col_ref | dollar_col_ref
;

alias_col_ref : GROUP | IDENTIFIER
;

dollar_col_ref : DOLLAR! INTEGER
;

const_expr : scalar | map | bag | tuple
;

scalar : INTEGER | LONGINEGER | FLOATNUMBER | DOUBLENUMBER | QUOTEDSTRING | NULL
;

map : ^( MAP_VAL keyvalue+ )
;

keyvalue : ^( KEY_VAL_PAIR string_val const_expr )
;

string_val : QUOTEDSTRING | NULL
;

bag :^( BAG_VAL tuple+ )
;

tuple : ^( TUPLE_VAL const_expr+ )
;

DefaultDataTypeInserter (last edited 2010-10-08 22:21:04 by XuefuZhang)