本文整理汇总了Java中org.apache.pig.data.DataType.isSchemaType方法的典型用法代码示例。如果您正苦于以下问题:Java DataType.isSchemaType方法的具体用法?Java DataType.isSchemaType怎么用?Java DataType.isSchemaType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pig.data.DataType
的用法示例。
在下文中一共展示了DataType.isSchemaType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromPigSchema
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public static org.apache.hadoop.zebra.schema.Schema fromPigSchema(
Schema pschema) throws FrontendException, ParseException {
org.apache.hadoop.zebra.schema.Schema tschema = new org.apache.hadoop.zebra.schema.Schema();
Schema.FieldSchema columnSchema;
for (int i = 0; i < pschema.size(); i++) {
columnSchema = pschema.getField(i);
if (columnSchema != null) {
if (DataType.isSchemaType(columnSchema.type))
tschema.add(new org.apache.hadoop.zebra.schema.Schema.ColumnSchema(columnSchema.alias,
fromPigSchema(columnSchema.schema), toTableType(columnSchema.type)));
else if (columnSchema.type == DataType.MAP)
tschema.add(new org.apache.hadoop.zebra.schema.Schema.ColumnSchema(columnSchema.alias,
new org.apache.hadoop.zebra.schema.Schema(new org.apache.hadoop.zebra.schema.Schema.ColumnSchema(null,
org.apache.hadoop.zebra.schema.ColumnType.BYTES)), toTableType(columnSchema.type)));
else
tschema.add(new org.apache.hadoop.zebra.schema.Schema.ColumnSchema(columnSchema.alias, toTableType(columnSchema.type)));
} else {
tschema.add(new org.apache.hadoop.zebra.schema.Schema.ColumnSchema(null, ColumnType.ANY));
}
}
return tschema;
}
示例2: equals
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/***
* Compare two field schema for equality
* @param relaxInner If true, we don't check inner tuple schemas
* @param relaxAlias If true, we don't check aliases
* @return true if FieldSchemas are equal, false otherwise
*/
public static boolean equals(LogicalFieldSchema fschema,
LogicalFieldSchema fother,
boolean relaxInner,
boolean relaxAlias) {
if( fschema == null || fother == null ) {
return false ;
}
if( fschema.type != fother.type ) {
return false ;
}
if (!relaxAlias) {
if ( fschema.alias == null && fother.alias == null ) {
// good
} else if ( fschema.alias == null ) {
return false ;
} else if( !fschema.alias.equals( fother.alias ) ) {
return false ;
}
}
if ( (!relaxInner) && (DataType.isSchemaType(fschema.type))) {
// Don't do the comparison if both embedded schemas are
// null. That will cause Schema.equals to return false,
// even though we want to view that as true.
if (!(fschema.schema == null && fother.schema == null)) {
// compare recursively using schema
if (!LogicalSchema.equals(fschema.schema, fother.schema, false, relaxAlias)) {
return false ;
}
}
}
return true ;
}
示例3: fitPossible
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* Computes a modified version of manhattan distance between
* the two schemas: s1 & s2. Here the value on the same axis
* are preferred over values that change axis as this means
* that the number of casts required will be lesser on the same
* axis.
*
* However, this function ceases to be a metric as the triangle
* inequality does not hold.
*
* Each schema is an s1.size() dimensional vector.
* The ordering for each axis is as defined by castLookup.
* Unallowed casts are returned a dist of INFINITY.
* @param s1
* @param s2
* @return
*/
private long fitPossible(Schema s1, Schema s2) {
if(s1==null || s2==null) return INF;
List<FieldSchema> sFields = s1.getFields();
List<FieldSchema> fsFields = s2.getFields();
if(sFields.size()!=fsFields.size())
return INF;
long score = 0;
int castCnt=0;
for(int i=0;i<sFields.size();i++){
FieldSchema sFS = sFields.get(i);
if(sFS == null){
return INF;
}
// if we have a byte array do not include it
// in the computation of the score - bytearray
// fields will be looked at separately outside
// of this function
if (sFS.type == DataType.BYTEARRAY)
continue;
FieldSchema fsFS = fsFields.get(i);
if(DataType.isSchemaType(sFS.type)){
if(!FieldSchema.equals(sFS, fsFS, false, true))
return INF;
}
if(FieldSchema.equals(sFS, fsFS, true, true)) continue;
if(!castLookup.containsKey(sFS.type))
return INF;
if(!(castLookup.get(sFS.type).contains(fsFS.type)))
return INF;
score += (castLookup.get(sFS.type)).indexOf(fsFS.type) + 1;
++castCnt;
}
return score * castCnt;
}
示例4: ResourceFieldSchema
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* 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;
}
}
示例5: FieldSchema
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* 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();
}
示例6: setFieldSchemaDefaultType
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* 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);
}
}
示例7: name
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@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();
}
示例8: getOutputSchema
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public Schema getOutputSchema(Schema input)
{
if (input.getFields().size() == 0)
{
throw new RuntimeException("Expected at least one parameter");
}
Byte outputType = null;
int pos = 0;
for (FieldSchema field : input.getFields())
{
if (DataType.isSchemaType(field.type))
{
throw new RuntimeException(String.format("Not supported on schema types. Found %s in position %d.",DataType.findTypeName(field.type),pos));
}
if (DataType.isComplex(field.type))
{
throw new RuntimeException(String.format("Not supported on complex types. Found %s in position %d.",DataType.findTypeName(field.type),pos));
}
if (!DataType.isUsableType(field.type))
{
throw new RuntimeException(String.format("Not a usable type. Found %s in position %d.",DataType.findTypeName(field.type),pos));
}
if (outputType == null)
{
outputType = field.type;
}
else if (!outputType.equals(field.type))
{
if (strict)
{
throw new RuntimeException(String.format("Expected all types to be equal, but found '%s' in position %d. First element has type '%s'. "
+ "If you'd like to attempt merging types, use the '%s' option, as '%s' is the default.",
DataType.findTypeName(field.type),pos,DataType.findTypeName((byte)outputType),LAZY_OPTION,STRICT_OPTION));
}
else
{
byte merged = DataType.mergeType(outputType, field.type);
if (merged == DataType.ERROR)
{
throw new RuntimeException(String.format("Expected all types to be equal, but found '%s' in position %d, where output type is '%s', and types could not be merged.",
DataType.findTypeName(field.type),pos,DataType.findTypeName((byte)outputType)));
}
outputType = merged;
}
}
pos++;
}
getInstanceProperties().put("type", outputType);
return new Schema(new Schema.FieldSchema("item",outputType));
}
示例9: castable
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* Check if FieldSchema inFs is castable to outFs
* @param inFs
* @param outFs
* @return true if it is castable
*/
public static boolean castable(LogicalFieldSchema inFs,
LogicalFieldSchema outFs) {
if(outFs == null && inFs == null) {
return false;
}
if (outFs == null) {
return false ;
}
if (inFs == null) {
return false ;
}
byte inType = inFs.type;
byte outType = outFs.type;
if (DataType.isSchemaType(outFs.type)) {
if(inType == DataType.BYTEARRAY) {
// good
} else if (inType == outType) {
// Don't do the comparison if either input inner schema
// is null/empty or both inner schemas are
// null. That will cause Schema.equals to return false,
// even though we want to view that as true.
if (!(inFs.schema == null || inFs.schema.size() == 0 ||
(outFs.schema == null && inFs.schema == null))) {
// compare recursively using schema
if (!LogicalSchema.castable(inFs.schema, outFs.schema)) {
return false ;
}
}
} else {
return false;
}
} else {
if (inType == outType) {
// good
}
else if (inType == DataType.BOOLEAN && (outType == DataType.CHARARRAY
|| outType == DataType.BYTEARRAY || DataType.isNumberType(outType))) {
// good
}
else if (DataType.isNumberType(inType) && (outType == DataType.CHARARRAY
|| outType == DataType.BYTEARRAY || DataType.isNumberType(outType))
|| outType == DataType.BOOLEAN) {
// good
}
else if (inType == DataType.CHARARRAY && (outType == DataType.BYTEARRAY
|| DataType.isNumberType(outType)) || outType == DataType.BOOLEAN) {
// good
}
else if (inType == DataType.BYTEARRAY) {
// good
}
else {
return false;
}
}
return true ;
}
示例10: castable
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* Recursively compare two schemas to check if the input schema
* can be cast to the cast schema
* @param castFs schema of the cast operator
* @param inputFs schema of the cast input
* @return true or falsew!
*/
public static boolean castable(
Schema.FieldSchema castFs,
Schema.FieldSchema inputFs) {
if(castFs == null && inputFs == null) {
return false;
}
if (castFs == null) {
return false ;
}
if (inputFs == null) {
return false ;
}
byte inputType = inputFs.type;
byte castType = castFs.type;
if (DataType.isSchemaType(castFs.type)) {
if(inputType == DataType.BYTEARRAY) {
// good
} else if (inputType == castType) {
// Don't do the comparison if both embedded schemas are
// null. That will cause Schema.equals to return false,
// even though we want to view that as true.
if (!(castFs.schema == null && inputFs.schema == null)) {
// compare recursively using schema
if (!Schema.castable(castFs.schema, inputFs.schema)) {
return false ;
}
}
} else {
return false;
}
} else {
if (inputType == castType) {
// good
}
else if (inputType == DataType.BOOLEAN && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType))) {
// good
}
else if (DataType.isNumberType(inputType) && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType)
|| castType == DataType.BOOLEAN || castType == DataType.DATETIME)) {
// good
}
else if (inputType == DataType.DATETIME && (castType == DataType.CHARARRAY
|| castType == DataType.BYTEARRAY || DataType.isNumberType(castType))) {
// good
}
else if (inputType == DataType.CHARARRAY && (castType == DataType.BYTEARRAY
|| DataType.isNumberType(castType) || castType == DataType.BOOLEAN
|| castType == DataType.DATETIME)) {
// good
}
else if (inputType == DataType.BYTEARRAY) {
// good
}
else {
return false;
}
}
return true ;
}
示例11: equals
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/***
* Compare two field schema for equality
* @param fschema
* @param fother
* @param relaxInner If true, we don't check inner tuple schemas
* @param relaxAlias If true, we don't check aliases
* @return true if FieldSchemas are equal, false otherwise
*/
public static boolean equals(FieldSchema fschema,
FieldSchema fother,
boolean relaxInner,
boolean relaxAlias) {
if (fschema == null) {
return false ;
}
if (fother == null) {
return false ;
}
if (fschema.type != fother.type) {
return false ;
}
if (!relaxAlias) {
if ( (fschema.alias == null) &&
(fother.alias == null) ) {
// good
}
else if ( (fschema.alias != null) &&
(fother.alias == null) ) {
return false ;
}
else if ( (fschema.alias == null) &&
(fother.alias != null) ) {
return false ;
}
else if (!fschema.alias.equals(fother.alias)) {
return false ;
}
}
if ( (!relaxInner) && (DataType.isSchemaType(fschema.type))) {
// Don't do the comparison if both embedded schemas are
// null. That will cause Schema.equals to return false,
// even though we want to view that as true.
if (!(fschema.schema == null && fother.schema == null)) {
// compare recursively using schema
if (!Schema.equals(fschema.schema, fother.schema, false, relaxAlias)) {
return false ;
}
}
}
return true ;
}
示例12: fitPossible
import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
* Computes a modified version of manhattan distance between
* the two schemas: s1 & s2. Here the value on the same axis
* are preferred over values that change axis as this means
* that the number of casts required will be lesser on the same
* axis.
*
* However, this function ceases to be a metric as the triangle
* inequality does not hold.
*
* Each schema is an s1.size() dimensional vector.
* The ordering for each axis is as defined by castLookup.
* Unallowed casts are returned a dist of INFINITY.
* @param s1
* @param s2
* @param s2Type
* @return
*/
private long fitPossible(Schema s1, Schema s2, SchemaType s2Type) {
if(s1==null || s2==null) return INF;
List<FieldSchema> sFields = s1.getFields();
List<FieldSchema> fsFields = s2.getFields();
if((s2Type == SchemaType.NORMAL) && (sFields.size()!=fsFields.size()))
return INF;
if((s2Type == SchemaType.VARARG) && (sFields.size() < fsFields.size()))
return INF;
long score = 0;
int castCnt=0;
for(int i=0;i<sFields.size();i++){
FieldSchema sFS = sFields.get(i);
if(sFS == null){
return INF;
}
// if we have a byte array do not include it
// in the computation of the score - bytearray
// fields will be looked at separately outside
// of this function
if (sFS.type == DataType.BYTEARRAY)
continue;
//if we get to the vararg field (if defined) : take it repeatedly
FieldSchema fsFS = ((s2Type == SchemaType.VARARG) && i >= s2.size()) ?
fsFields.get(s2.size() - 1) : fsFields.get(i);
if(DataType.isSchemaType(sFS.type)){
if(!FieldSchema.equals(sFS, fsFS, false, true))
return INF;
}
if(FieldSchema.equals(sFS, fsFS, true, true)) continue;
if(!castLookup.containsKey(sFS.type))
return INF;
if(!(castLookup.get(sFS.type).contains(fsFS.type)))
return INF;
score += (castLookup.get(sFS.type)).indexOf(fsFS.type) + 1;
++castCnt;
}
return score * castCnt;
}