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

Class SchemaTupleFactory

src/org/apache/pig/data/SchemaTupleFactory.java:32–129  ·  view source on GitHub ↗

This is an implementation of TupleFactory that will instantiate SchemaTuple's. This class has nothing to do with the actual generation of code, and instead simply encapsulates the classes which allow for efficiently creating SchemaTuples.

Source from the content-addressed store, hash-verified

30 * for efficiently creating SchemaTuples.
31 */
32public class SchemaTupleFactory implements TupleMaker<SchemaTuple<?>> {
33 static final Log LOG = LogFactory.getLog(SchemaTupleFactory.class);
34
35 private SchemaTupleQuickGenerator<? extends SchemaTuple<?>> generator;
36 private Class<SchemaTuple<?>> clazz;
37 private int tupleSize;
38
39 protected SchemaTupleFactory(Class<SchemaTuple<?>> clazz,
40 SchemaTupleQuickGenerator<? extends SchemaTuple<?>> generator) {
41 this.clazz = clazz;
42 this.generator = generator;
43 tupleSize = generator.make().size();
44 }
45
46 /**
47 * This method inspects a Schema to see whether or
48 * not a SchemaTuple implementation can be generated
49 * for the types present. Currently, bags and maps
50 * are not supported.
51 * @param s as Schema
52 * @return boolean type value, true if it is generatable
53 */
54 public static boolean isGeneratable(Schema s) {
55 if (s == null || s.size() == 0) {
56 return false;
57 }
58
59 for (Schema.FieldSchema fs : s.getFields()) {
60 if (fs.type == DataType.TUPLE && !isGeneratable(fs.schema)) {
61 return false;
62 }
63 }
64
65 return true;
66 }
67
68 @Override
69 public SchemaTuple<?> newTuple() {
70 return generator.make();
71 }
72
73 @Override
74 public SchemaTuple<?> newTuple(int size) {
75 if (size != tupleSize) {
76 throw new RuntimeException("Request a SchemaTuple of the wrong size! Requested ["
77 + size + "], can only be [" + tupleSize + "]" );
78 }
79 return generator.make();
80 }
81
82 public Class<SchemaTuple<?>> tupleClass() {
83 return clazz;
84 }
85
86 // We could make this faster by caching the result, but I doubt it will be called
87 // in any great volume.
88 public boolean isFixedSize() {
89 return clazz.isAssignableFrom(AppendableSchemaTuple.class);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected