Review Board 1.7.22


Introduce a syntax to be able to easily refer to the previously defined relation

Review Request #9019 - Created Jan. 18, 2013 and updated

Jonathan Coveney
refer_previous_relation
PIG-3090
Reviewers
pig
pig-git
See JIRA

 
src/org/apache/pig/parser/AstValidator.g
Revision 8646078 New Change
[20] 12 lines
[+20]
13
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
 
18

   
19
/**
19
/**
20
 * Grammar file for Pig tree parser (visitor for default data type insertion).
20
 * Grammar file for Pig tree parser (visitor for default data type insertion).
21
 *
21
 *
22
 * NOTE: THIS FILE IS BASED ON QueryParser.g, SO IF YOU CHANGE THAT FILE, YOU WILL 
22
 * NOTE: THIS FILE IS BASED ON QueryParser.g, SO IF YOU CHANGE THAT FILE, YOU WILL
23
 *       PROBABLY NEED TO MAKE CORRESPONDING CHANGES TO THIS FILE AS WELL.
23
 *       PROBABLY NEED TO MAKE CORRESPONDING CHANGES TO THIS FILE AS WELL.
24
 */
24
 */
25

    
   
25

   
26
tree grammar AstValidator;
26
tree grammar AstValidator;
27

    
   
27

   
[+20] [20] 20 lines
[+20]
48
@members {
48
@members {
49

    
   
49

   
50
private static Log log = LogFactory.getLog( AstValidator.class );
50
private static Log log = LogFactory.getLog( AstValidator.class );
51

    
   
51

   
52
@Override
52
@Override
53
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) 
53
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow)
54
throws RecognitionException {
54
throws RecognitionException {
55
    throw new MismatchedTokenException( ttype, input );
55
    throw new MismatchedTokenException( ttype, input );
56
}
56
}
57

    
   
57

   
58
@Override
58
@Override
59
public Object recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow)
59
public Object recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow)
60
throws RecognitionException {
60
throws RecognitionException {
61
    throw e;
61
    throw e;
62
}
62
}
63

    
   
63

   
64
private void validateSchemaAliasName(Set<String> fieldNames, CommonTree node, String name)
64
private void validateSchemaAliasName(Set<String> fieldNames, CommonTree node, String name)
65
throws DuplicatedSchemaAliasException {
65
throws DuplicatedSchemaAliasException {
66
    if( fieldNames.contains( name ) ) {
66
    if( fieldNames.contains( name ) ) {
67
        throw new DuplicatedSchemaAliasException( input, 
67
        throw new DuplicatedSchemaAliasException( input,
68
            new SourceLocation( (PigParserNode)node ), name );
68
            new SourceLocation( (PigParserNode)node ), name );
69
    } else {
69
    } else {
70
        fieldNames.add( name );
70
        fieldNames.add( name );
71
    }
71
    }
72
}
72
}
[+20] [20] 10 lines
[+20]
83
        throw new ParserValidationException( input, new SourceLocation( (PigParserNode)node ),
83
        throw new ParserValidationException( input, new SourceLocation( (PigParserNode)node ),
84
            "Duplicated command option" );
84
            "Duplicated command option" );
85
    }
85
    }
86
}
86
}
87

    
   
87

   
88
private Set<String> aliases = new HashSet<String>();
88
private String lastRel = null;

    
   
89

   

    
   
90
private String getLastRel(CommonTree node) throws UndefinedAliasException {

    
   
91
    if (lastRel != null) {

    
   
92
        return lastRel;

    
   
93
    }

    
   
94
    throw new UndefinedAliasException( input, new SourceLocation((PigParserNode)node), "@");

    
   
95
}

    
   
96

   

    
   
97
private Set<String> aliases = new HashSet<String>() {

    
   
98
    @Override

    
   
99
    public boolean add(String e) {

    
   
100
        lastRel = e;

    
   
101
        return super.add(e);

    
   
102
    }

    
   
103
};
89

    
   
104

   
90
} // End of @members
105
} // End of @members
91

    
   
106

   
92
@rulecatch {
107
@rulecatch {
93
catch(RecognitionException re) {
108
catch(RecognitionException re) {
[+20] [20] 27 lines
[+20]
121
parallel_clause : ^( PARALLEL INTEGER )
136
parallel_clause : ^( PARALLEL INTEGER )
122
;
137
;
123

    
   
138

   
124
alias returns[String name, CommonTree node]
139
alias returns[String name, CommonTree node]
125
 : IDENTIFIER
140
 : IDENTIFIER
126
   { 
141
   {
127
       $name = $IDENTIFIER.text;
142
       $name = $IDENTIFIER.text;
128
       $node = $IDENTIFIER;
143
       $node = $IDENTIFIER;
129
   }
144
   }
130
;
145
;
131

    
   
146

   
132
op_clause : define_clause 
147
previous_rel returns[String name, CommonTree node]

    
   
148
 : ARROBA

    
   
149
   {

    
   
150
       $name = getLastRel($ARROBA);

    
   
151
       $node = $ARROBA;

    
   
152
   }

    
   
153
;

    
   
154

   

    
   
155
op_clause : define_clause
133
          | load_clause
156
          | load_clause
134
          | group_clause
157
          | group_clause
135
          | store_clause
158
          | store_clause
136
          | filter_clause
159
          | filter_clause
137
          | distinct_clause
160
          | distinct_clause
[+20] [20] 22 lines
[+20]
160
    int out = 0;
183
    int out = 0;
161
    int error = 0;
184
    int error = 0;
162
}
185
}
163
 : ^( EXECCOMMAND ( ship_clause { checkDuplication( ++ship, $ship_clause.start ); }
186
 : ^( EXECCOMMAND ( ship_clause { checkDuplication( ++ship, $ship_clause.start ); }
164
                  | cache_clause { checkDuplication( ++cache, $cache_clause.start ); }
187
                  | cache_clause { checkDuplication( ++cache, $cache_clause.start ); }
165
                  | input_clause { checkDuplication( ++in, $input_clause.start ); } 
188
                  | input_clause { checkDuplication( ++in, $input_clause.start ); }
166
                  | output_clause { checkDuplication( ++out, $output_clause.start ); } 
189
                  | output_clause { checkDuplication( ++out, $output_clause.start ); }
167
                  | error_clause { checkDuplication( ++error, $error_clause.start ); }
190
                  | error_clause { checkDuplication( ++error, $error_clause.start ); }
168
                  )*
191
                  )*
169
   )
192
   )
170
;
193
;
171

    
   
194

   
[+20] [20] 108 lines
[+20]
280

    
   
303

   
281
cube_by_expr_list
304
cube_by_expr_list
282
 : cube_by_expr+
305
 : cube_by_expr+
283
;
306
;
284

    
   
307

   
285
cube_by_expr 
308
cube_by_expr
286
 : col_range | expr | STAR 
309
 : col_range | expr | STAR
287
;
310
;
288

    
   
311

   
289
group_clause
312
group_clause
290
scope {
313
scope {
291
    int arity;
314
    int arity;
292
}
315
}
293
@init {
316
@init {
294
    $group_clause::arity = 0;
317
    $group_clause::arity = 0;
295
}
318
}
296
 : ^( ( GROUP | COGROUP ) group_item+ group_type? partition_clause? )
319
 : ^( ( GROUP | COGROUP ) group_item+ group_type? partition_clause? )
297
;
320
;
298

    
   
321

   
299
group_type : QUOTEDSTRING 
322
group_type : QUOTEDSTRING
300
;
323
;
301

    
   
324

   
302
group_item
325
group_item
303
 : rel ( join_group_by_clause | ALL | ANY ) ( INNER | OUTER )?
326
 : rel ( join_group_by_clause | ALL | ANY ) ( INNER | OUTER )?
304
   {
327
   {
[+20] [20] 6 lines
[+20]
311
       }
334
       }
312
   }
335
   }
313
;
336
;
314

    
   
337

   
315
rel : alias {  validateAliasRef( aliases, $alias.node, $alias.name ); }
338
rel : alias {  validateAliasRef( aliases, $alias.node, $alias.name ); }

    
   
339
    | previous_rel { validateAliasRef( aliases, $previous_rel.node, $previous_rel.name ); }
316
    | op_clause parallel_clause?
340
    | op_clause parallel_clause?
317
;
341
;
318

    
   
342

   
319
flatten_generated_item : ( flatten_clause | col_range | expr | STAR ) field_def_list?
343
flatten_generated_item : ( flatten_clause | col_range | expr | STAR ) field_def_list?
320
;
344
;
[+20] [20] 11 lines
[+20]
332
     | ^( AND cond cond )
356
     | ^( AND cond cond )
333
     | ^( NOT cond )
357
     | ^( NOT cond )
334
     | ^( NULL expr NOT? )
358
     | ^( NULL expr NOT? )
335
     | ^( rel_op expr expr )
359
     | ^( rel_op expr expr )
336
     | func_eval
360
     | func_eval
337
     | ^( BOOL_COND expr )     
361
     | ^( BOOL_COND expr )
338
;
362
;
339

    
   
363

   
340
func_eval: ^( FUNC_EVAL func_name real_arg* )
364
func_eval: ^( FUNC_EVAL func_name real_arg* )
341
;
365
;
342

    
   
366

   
[+20] [20] 373 lines
src/org/apache/pig/parser/LogicalPlanBuilder.java
Revision 699f7a6 New Change
 
src/org/apache/pig/parser/LogicalPlanGenerator.g
Revision 9b9c099 New Change
 
src/org/apache/pig/parser/QueryLexer.g
Revision f201916 New Change
 
src/org/apache/pig/parser/QueryParser.g
Revision 642884e New Change
 
test/org/apache/pig/test/TestCommit.java
Revision 7df409e New Change
 
test/org/apache/pig/test/TestPreviousRelation.java
New File
 
  1. src/org/apache/pig/parser/AstValidator.g: Loading...
  2. src/org/apache/pig/parser/LogicalPlanBuilder.java: Loading...
  3. src/org/apache/pig/parser/LogicalPlanGenerator.g: Loading...
  4. src/org/apache/pig/parser/QueryLexer.g: Loading...
  5. src/org/apache/pig/parser/QueryParser.g: Loading...
  6. test/org/apache/pig/test/TestCommit.java: Loading...
  7. test/org/apache/pig/test/TestPreviousRelation.java: Loading...