MCPcopy Create free account
hub / github.com/apache/pig / macroImport

Method macroImport

src/org/apache/pig/parser/QueryParserDriver.java:517–580  ·  view source on GitHub ↗
(CommonTree t)

Source from the content-addressed store, hash-verified

515 }
516
517 private void macroImport(CommonTree t) throws ParserException {
518 // remove quote
519 String fname = t.getChild(0).getText();
520 fname = QueryParserUtils.removeQuotes(fname);
521 if (!importSeen.add(fname)) {
522 // we've already imported this file, so just skip this import statement
523 LOG.debug("Ignoring duplicated import " + fname);
524 t.getParent().deleteChild(t.getChildIndex());
525 return;
526 }
527
528 Tree macroAST = null;
529 if (pigContext.macros.containsKey(fname)) {
530 macroAST = pigContext.macros.get(fname);
531 } else {
532 FetchFileRet localFileRet = getMacroFile(fname);
533
534 BufferedReader in = null;
535 try {
536 in = new BufferedReader(new FileReader(localFileRet.file));
537 } catch (FileNotFoundException e) {
538 String msg = getErrorMessage(fname, t,
539 "Failed to import file '" + fname + "'", e.getMessage());
540 throw new ParserException(msg);
541 }
542
543 StringBuilder sb = new StringBuilder();
544 String line = null;
545 try {
546 line = in.readLine();
547 while (line != null) {
548 sb.append(line).append("\n");
549 line = in.readLine();
550 }
551 } catch (IOException e) {
552 String msg = getErrorMessage(fname, t,
553 "Failed to read file '" + fname + "'", e.getMessage());
554 throw new ParserException(msg);
555 }
556
557 String macroText = null;
558 try {
559 in.close();
560 in = new BufferedReader(new StringReader(sb.toString()));
561 macroText = pigContext.doParamSubstitution(in);
562 } catch (IOException e) {
563 String msg = getErrorMessage(fname, t,
564 "Parameter sustitution failed for macro.", e.getMessage());
565 throw new ParserException(msg);
566 }
567
568 // parse
569 CommonTokenStream tokenStream = tokenize(macroText, fname);
570
571 try {
572 macroAST = parse( tokenStream );
573 pigContext.macros.put(fname, macroAST);
574 } catch(RuntimeException ex) {

Callers 1

expandImportMethod · 0.95

Calls 15

removeQuotesMethod · 0.95
getMacroFileMethod · 0.95
getErrorMessageMethod · 0.95
tokenizeMethod · 0.95
parseMethod · 0.95
debugMethod · 0.80
doParamSubstitutionMethod · 0.80
addMethod · 0.65
getMethod · 0.65
appendMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected