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

Method getSchema

src/org/apache/pig/impl/util/Utils.java:177–211  ·  view source on GitHub ↗
(LoadFunc wrappedLoadFunc, String location, boolean checkExistence, Job job)

Source from the content-addressed store, hash-verified

175 }
176
177 public static ResourceSchema getSchema(LoadFunc wrappedLoadFunc, String location, boolean checkExistence, Job job)
178 throws IOException {
179 Configuration conf = job.getConfiguration();
180 if (checkExistence) {
181 Path path = new Path(location);
182 if (!FileSystem.get(conf).exists(path)) {
183 // At compile time in batch mode, the file may not exist
184 // (such as intermediate file). Just return null - the
185 // same way as we would if we did not get a valid record
186 return null;
187 }
188 }
189 ReadToEndLoader loader = new ReadToEndLoader(wrappedLoadFunc, conf, location, 0);
190 // get the first record from the input file
191 // and figure out the schema from the data in
192 // the first record
193 Tuple t = loader.getNext();
194 if (t == null) {
195 // we couldn't get a valid record from the input
196 return null;
197 }
198 int numFields = t.size();
199 Schema s = new Schema();
200 for (int i = 0; i < numFields; i++) {
201 try {
202 s.add(DataType.determineFieldSchema(t.get(i)));
203 }
204 catch (Exception e) {
205 int errCode = 2104;
206 String msg = "Error while determining schema of SequenceFileStorage data.";
207 throw new ExecException(msg, errCode, PigException.BUG, e);
208 }
209 }
210 return new ResourceSchema(s);
211 }
212
213 /**
214 * @param schemaString a String representation of the Schema <b>without</b>

Callers 4

getSchemaMethod · 0.95
getSchemaMethod · 0.95
getSchemaMethod · 0.95
getSchemaMethod · 0.95

Calls 7

getMethod · 0.95
getNextMethod · 0.95
sizeMethod · 0.95
addMethod · 0.95
determineFieldSchemaMethod · 0.95
getConfigurationMethod · 0.65
existsMethod · 0.65

Tested by

no test coverage detected