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

Class TextLoader

src/org/apache/pig/builtin/TextLoader.java:53–288  ·  view source on GitHub ↗

This load function simply creates a tuple for each line of text that has a single chararray field that contains the line of text.

Source from the content-addressed store, hash-verified

51 * contains the line of text.
52 */
53public class TextLoader extends LoadFunc implements LoadCaster {
54 protected RecordReader in = null;
55 private TupleFactory mTupleFactory = TupleFactory.getInstance();
56 private String loadLocation;
57 protected final Log mLog = LogFactory.getLog(getClass());
58
59 // it determines whether to depend on pig's own Bzip2TextInputFormat or
60 // to simply depend on hadoop for handling bzip2 inputs
61 private boolean bzipinput_usehadoops ;
62
63
64 @Override
65 public Tuple getNext() throws IOException {
66 try {
67 boolean notDone = in.nextKeyValue();
68 if (!notDone) {
69 return null;
70 }
71 Text value = (Text) in.getCurrentValue();
72 byte[] ba = value.getBytes();
73 // make a copy of the bytes representing the input since
74 // TextInputFormat will reuse the byte array
75 return mTupleFactory.newTuple(new DataByteArray(ba, 0, value.getLength()));
76 } catch (InterruptedException e) {
77 throw new IOException("Error getting input");
78 }
79 }
80
81 /**
82 * TextLoader does not support conversion to Boolean
83 * @throws IOException if the value cannot be cast.
84 */
85 @Override
86 public Boolean bytesToBoolean(byte[] b) throws IOException {
87 int errCode = 2109;
88 String msg = "TextLoader does not support conversion to Boolean.";
89 throw new ExecException(msg, errCode, PigException.BUG);
90 }
91
92 /**
93 * TextLoader does not support conversion to Integer
94 * @throws IOException if the value cannot be cast.
95 */
96 @Override
97 public Integer bytesToInteger(byte[] b) throws IOException {
98 int errCode = 2109;
99 String msg = "TextLoader does not support conversion to Integer.";
100 throw new ExecException(msg, errCode, PigException.BUG);
101 }
102
103 /**
104 * TextLoader does not support conversion to Long
105 * @throws IOException if the value cannot be cast.
106 */
107 @Override
108 public Long bytesToLong(byte[] b) throws IOException {
109 int errCode = 2109;
110 String msg = "TextLoader does not support conversion to Long.";

Callers

nothing calls this directly

Calls 2

getInstanceMethod · 0.95
getClassMethod · 0.80

Tested by

no test coverage detected