| 554 | } |
| 555 | |
| 556 | public static String hadoopify(String filename, PigContext pigContext) throws IOException { |
| 557 | if (Shell.WINDOWS){ |
| 558 | filename = filename.replace('\\','/'); |
| 559 | } |
| 560 | if (filename.startsWith(LOCAL_PREFIX)) { |
| 561 | filename = filename.substring(LOCAL_PREFIX.length()); |
| 562 | } |
| 563 | |
| 564 | ElementDescriptor localElem = |
| 565 | pigContext.getLfs().asElement(filename); |
| 566 | |
| 567 | if (!localElem.exists()) { |
| 568 | throw new FileNotFoundException(filename); |
| 569 | } |
| 570 | |
| 571 | ElementDescriptor distribElem = pigContext.getDfs().asElement( |
| 572 | getTemporaryPath(pigContext).toString()); |
| 573 | |
| 574 | int suffixStart = filename.lastIndexOf('.'); |
| 575 | if (suffixStart != -1) { |
| 576 | distribElem = pigContext.getDfs().asElement(distribElem.toString() + |
| 577 | filename.substring(suffixStart)); |
| 578 | } |
| 579 | |
| 580 | // TODO: currently the copy method in Data Storage does not allow to specify overwrite |
| 581 | // so the work around is to delete the dst file first, if it exists |
| 582 | if (distribElem.exists()) { |
| 583 | distribElem.delete(); |
| 584 | } |
| 585 | localElem.copy(distribElem, null, false); |
| 586 | |
| 587 | return distribElem.toString(); |
| 588 | } |
| 589 | |
| 590 | public static String fullPath(String filename, PigContext pigContext) throws IOException { |
| 591 | try { |