/** * Determine whether the this object can have a schema. * @param o Object to determine if it has a schema * @return true if the type can have a valid schema (i.e., bag or tuple) */ public static boolean isSchemaType(Object o) { return isSchemaType(findType(o)); }
/** * Recursively set NULL type to the specifid type * @param fs the field schema whose NULL type has to be set * @param t the specified type */ public static void setFieldSchemaDefaultType(Schema.FieldSchema fs, byte t) { if(null == fs) return; if(DataType.NULL == fs.type) { fs.type = t; } if(DataType.isSchemaType(fs.type)) { setSchemaDefaultType(fs.schema, t); } }
/** * Construct using a {@link org.apache.pig.newplan.logical.relational.LogicalSchema.LogicalFieldSchema} as the template. * @param fieldSchema fieldSchema to copy from */ public ResourceFieldSchema(LogicalFieldSchema fieldSchema) { type = fieldSchema.type; name = fieldSchema.alias; description = "autogenerated from Pig Field Schema"; LogicalSchema inner = fieldSchema.schema; // allow partial schema if (DataType.isSchemaType(type) && inner != null) { schema = new ResourceSchema(inner); } else { schema = null; } }
private void resetTypeToNull (LogicalSchema s1) { if( s1 != null ) { for (LogicalFieldSchema fs : s1.getFields()) { if( DataType.isSchemaType(fs.type) ) { resetTypeToNull(fs.schema); } else { fs.type = DataType.NULL; } } } }
if ( (!relaxInner) && (DataType.isSchemaType(fschema.type))) {
private void setNullTypeToByteArrayType (LogicalSchema s1) { if( s1 != null ) { for (LogicalFieldSchema fs : s1.getFields()) { if( DataType.isSchemaType(fs.type) ) { setNullTypeToByteArrayType(fs.schema); } else if(fs.type == DataType.NULL) { fs.type = DataType.BYTEARRAY; } } } } }
if ( (!relaxInner) && (DataType.isSchemaType(fschema.type))) {
private static boolean hasOnlyNullOrByteArraySchema (LogicalFieldSchema fs) { if( DataType.isSchemaType(fs.type) ) { if( fs.schema != null ) { for (LogicalFieldSchema sub_fs : fs.schema.getFields() ) { if( !hasOnlyNullOrByteArraySchema(sub_fs) ) { return false; } } } } else if( fs.type != DataType.NULL && fs.type != DataType.BYTEARRAY ) { return false; } return true; }
/** * Constructor for tuple fields. * * @param a * Alias, if known. If unknown leave null. * @param s * Schema of this tuple. * @param t * Type, using codes from * {@link org.apache.pig.data.DataType}. * */ public FieldSchema(String a, Schema s, byte t) throws FrontendException { alias = a; schema = s; log.debug("t: " + t + " Bag: " + DataType.BAG + " tuple: " + DataType.TUPLE); if ((null != s) && !(DataType.isSchemaType(t))) { int errCode = 1020; throw new FrontendException("Only a BAG, TUPLE or MAP can have schemas. Got " + DataType.findTypeName(t), errCode, PigException.INPUT); } type = t; canonicalName = CanonicalNamer.getNewName(); }
fsFields.get(s2.size() - 1) : fsFields.get(i); if(DataType.isSchemaType(sFS.type)){ if(!FieldSchema.equals(sFS, fsFS, false, true)) return INF;
@Override public String name() { if (DataType.isSchemaType(resultType)) return "Cast" + "[" + DataType.findTypeName(resultType)+":" + fieldSchema.calcCastString() + "]" + " - " + mKey.toString(); else return "Cast" + "[" + DataType.findTypeName(resultType) + "]" + " - " + mKey.toString(); }
if (!DataType.isSchemaType(fs.type)) { outputList.add(new FieldSchema(fs.alias, fs.type)) ;
for (FieldSchema field : input.getFields()) if (DataType.isSchemaType(field.type))
if (DataType.isSchemaType(udfFieldSchema.type) && udfFieldSchema.schema != null && isNotBagWithEmptyTuple(udfFieldSchema)
private static LogicalFieldSchema replaceNullByteArrayFieldSchema( LogicalFieldSchema originalFS, LogicalFieldSchema userFS) throws FrontendException { if( originalFS == null && userFS == null ) { return null; } else if ( originalFS == null ) { return userFS.deepCopy(); } else if ( userFS == null ) { return originalFS.deepCopy(); } if ( originalFS.type==DataType.NULL || originalFS.type==DataType.BYTEARRAY ) { return userFS.deepCopy(); } else if ( userFS.type==DataType.NULL || userFS.type==DataType.BYTEARRAY ) { // Use originalFS schema but keep the alias from userFS return new LogicalFieldSchema(userFS.alias, originalFS.schema, originalFS.type); } if ( !DataType.isSchemaType(originalFS.type) ) { return userFS.deepCopy(); } else { LogicalSchema replacedSchema = replaceNullByteArraySchema(originalFS.schema, userFS.schema); return new LogicalFieldSchema(userFS.alias, replacedSchema, userFS.type); } }
byte outType = outFs.type; if (DataType.isSchemaType(outFs.type)) { if(inType == DataType.BYTEARRAY) {
byte castType = castFs.type; if (DataType.isSchemaType(castFs.type)) { if(inputType == DataType.BYTEARRAY) {
throw new SchemaMergeException(msg, errCode, PigException.INPUT) ; if(DataType.isSchemaType(mergedType)) {
String msg = "Cannot cast " + DataType.findTypeName(inType) + ((DataType.isSchemaType(inType))? " with schema " + inFs.toString(false) : "") + " to " + DataType.findTypeName(outType) + ((DataType.isSchemaType(outType))? " with schema " + outFs.toString(false) : ""); msgCollector.collect(msg, MessageType.Error) ; throw new TypeCheckerException(cast, msg, errCode, PigException.INPUT) ;
otherTakesAliasPrecedence) ; if (!DataType.isSchemaType(mergedType)) {