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

Method determineFieldSchema

src/org/apache/pig/data/DataType.java:1668–1742  ·  view source on GitHub ↗

Utility method that determines the schema from the passed in dataType. If the dataType is Bag or Tuple, then we need to determine the schemas inside this dataType; for this we iterate through the fields inside this field. This method works both for raw objects and ResourceSchema.ResourceFieldSchema

(byte dataType, Iterator fieldIter,
            long fieldNum, Class klass )

Source from the content-addressed store, hash-verified

1666 * @throws SchemaMergeException
1667 */
1668 @SuppressWarnings("deprecation")
1669 private static Schema.FieldSchema determineFieldSchema(byte dataType, Iterator fieldIter,
1670 long fieldNum, Class klass ) throws ExecException, FrontendException, SchemaMergeException {
1671 switch (dataType) {
1672 case NULL:
1673 return new Schema.FieldSchema(null, BYTEARRAY);
1674
1675 case BOOLEAN:
1676 case INTEGER:
1677 case LONG:
1678 case FLOAT:
1679 case DOUBLE:
1680 case BIGINTEGER:
1681 case BIGDECIMAL:
1682 case DATETIME:
1683 case BYTEARRAY:
1684 case CHARARRAY:
1685 case MAP:
1686 return new Schema.FieldSchema(null, dataType);
1687 case TUPLE: {
1688 Schema schema = null;
1689 if(fieldNum != 0) {
1690 schema = new Schema();
1691 for(int i = 0; i < fieldNum; ++i) {
1692 schema.add(determineFieldSchema(klass.cast(fieldIter.next())));
1693 }
1694 }
1695 return new Schema.FieldSchema(null, schema, TUPLE);
1696 }
1697
1698 case BAG: {
1699 Schema schema = null;
1700 Schema bagSchema = null;
1701
1702 if(fieldNum != 0) {
1703 ArrayList<Schema> schemas = new ArrayList<Schema>();
1704 while (fieldIter.hasNext() ) {
1705 schemas.add(determineFieldSchema(klass.cast(fieldIter.next())).schema);
1706 }
1707 schema = schemas.get(0);
1708 if(null == schema) {
1709 Schema.FieldSchema tupleFs = new Schema.FieldSchema(null, null, TUPLE);
1710 bagSchema = new Schema(tupleFs);
1711 bagSchema.setTwoLevelAccessRequired(true);
1712 return new Schema.FieldSchema(null, bagSchema, BAG);
1713 }
1714 int schemaSize = schema.size();
1715
1716 for(int i = 1; i < schemas.size(); ++i) {
1717 Schema currSchema = schemas.get(i);
1718 if((null == currSchema) || (currSchema.size() != schemaSize)) {
1719 Schema.FieldSchema tupleFs = new Schema.FieldSchema(null, null, TUPLE);
1720 bagSchema = new Schema(tupleFs);
1721 bagSchema.setTwoLevelAccessRequired(true);
1722 return new Schema.FieldSchema(null, bagSchema, BAG);
1723 }
1724 schema = Schema.mergeSchema(schema, currSchema, false, false, false);
1725 }

Callers 3

getFieldSchemaMethod · 0.95
getSchemaMethod · 0.95

Calls 15

addMethod · 0.95
sizeMethod · 0.95
mergeSchemaMethod · 0.95
findTypeMethod · 0.95
castMethod · 0.80
addMethod · 0.65
getMethod · 0.65
sizeMethod · 0.65
getTypeMethod · 0.65
iteratorMethod · 0.65
getSchemaMethod · 0.65

Tested by 1