()
| 2733 | * unit tests are done in TestStringUDFs |
| 2734 | */ |
| 2735 | @Test |
| 2736 | public void testStringUDFs() throws Exception { |
| 2737 | String inputStr = "amy smith "; |
| 2738 | File inputFile = Util.createInputFile("tmp", "testStrUDFsIn.txt", new String[] {inputStr}); |
| 2739 | |
| 2740 | // test typed data |
| 2741 | pigServer.registerQuery("=> load '" + Util.encodeEscape(inputFile.getAbsolutePath()) + "' as (name: chararray);"); |
| 2742 | pigServer.registerQuery("B = foreach @ generate SUBSTRING(name, 0, 3), " + |
| 2743 | "INDEXOF(name, 'a'), INDEXOF(name, 'a', 3), LAST_INDEX_OF(name, 'a'), REPLACE(name, 'a', 'b'), " + |
| 2744 | "STRSPLIT(name), STRSPLIT(name, ' '), STRSPLIT(name, ' ', 0), STRSPLITTOBAG(name), STRSPLITTOBAG(name,' ')" + |
| 2745 | ", STRSPLITTOBAG(name,' ',0), TRIM(name);"); |
| 2746 | |
| 2747 | Iterator<Tuple> it = pigServer.openIterator("B"); |
| 2748 | assertTrue(it.hasNext()); |
| 2749 | Tuple t = it.next(); |
| 2750 | Tuple expected = Util.buildTuple("amy", "smith"); |
| 2751 | DataBag expectedBag = Util.createBag(new Tuple[]{Util.buildTuple("amy"), Util.buildTuple("smith")}); |
| 2752 | assertTrue(!it.hasNext()); |
| 2753 | assertEquals(12, t.size()); |
| 2754 | assertEquals("amy", t.get(0)); |
| 2755 | assertEquals(0, t.get(1)); |
| 2756 | assertEquals(-1, t.get(2)); |
| 2757 | assertEquals(0, t.get(3)); |
| 2758 | assertEquals("bmy smith ", t.get(4)); |
| 2759 | assertEquals(expected, t.get(5)); |
| 2760 | assertEquals(expected, t.get(6)); |
| 2761 | assertEquals(expected, t.get(7)); |
| 2762 | assertEquals(expectedBag, t.get(8)); |
| 2763 | assertEquals(expectedBag, t.get(9)); |
| 2764 | assertEquals(expectedBag, t.get(10)); |
| 2765 | assertEquals("amy smith", t.get(11)); |
| 2766 | |
| 2767 | // test untyped data |
| 2768 | pigServer.registerQuery("=> load '" + Util.encodeEscape(inputFile.getAbsolutePath()) + "' as (name);"); |
| 2769 | pigServer.registerQuery("B = foreach @ generate SUBSTRING(name, 0, 3), " + |
| 2770 | "LAST_INDEX_OF(name, 'a'), REPLACE(name, 'a', 'b'), TRIM(name);"); |
| 2771 | |
| 2772 | it = pigServer.openIterator("B"); |
| 2773 | assertTrue(it.hasNext()); |
| 2774 | t = it.next(); |
| 2775 | assertTrue(!it.hasNext()); |
| 2776 | assertEquals(4, t.size()); |
| 2777 | assertEquals("amy", t.get(0)); |
| 2778 | assertEquals(0, t.get(1)); |
| 2779 | assertEquals("bmy smith ", t.get(2)); |
| 2780 | assertEquals("amy smith", t.get(3)); |
| 2781 | } |
| 2782 | |
| 2783 | @Test |
| 2784 | public void testTOKENIZE() throws Exception { |
nothing calls this directly
no test coverage detected