当前位置: 首页>>代码示例>>Java>>正文


Java DataType.isNumberType方法代码示例

本文整理汇总了Java中org.apache.pig.data.DataType.isNumberType方法的典型用法代码示例。如果您正苦于以下问题:Java DataType.isNumberType方法的具体用法?Java DataType.isNumberType怎么用?Java DataType.isNumberType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pig.data.DataType的用法示例。


在下文中一共展示了DataType.isNumberType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public void visit(NegativeExpression negExp) throws FrontendException {
    byte type = negExp.getExpression().getType() ;
    if (DataType.isNumberType(type)) {
        //do nothing
    }
    else if (type == DataType.BYTEARRAY) {
        // cast bytearray to double
        insertCast(negExp, DataType.DOUBLE, negExp.getExpression());
    }
    else {
        int errCode = 1041;
        String msg = "NEG can be used with numbers or Bytearray only" ;
        msgCollector.collect(msg, MessageType.Error);
        throw new TypeCheckerException(negExp, msg, errCode, PigException.INPUT) ;
    }

}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:19,代码来源:TypeCheckingExpVisitor.java

示例2: 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 ;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:69,代码来源:LogicalSchema.java

示例3: addCastsToNumericBinExpression

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
 * Add casts to promote numeric type to larger of two input numeric types of
 * the {@link BinaryExpression}  binOp . If one of the inputs is numeric
 * and other bytearray, cast the bytearray type to other numeric type.
 * If both inputs are bytearray, cast them to double.
 * @param binOp
 * @throws FrontendException
 */
private void addCastsToNumericBinExpression(BinaryExpression binOp)
throws FrontendException {
    LogicalExpression lhs = binOp.getLhs() ;
    LogicalExpression rhs = binOp.getRhs() ;

    byte lhsType = lhs.getType() ;
    byte rhsType = rhs.getType() ;

    if ( DataType.isNumberType(lhsType) &&
            DataType.isNumberType(rhsType) ) {

        // return the bigger type
        byte biggerType = lhsType > rhsType ? lhsType:rhsType ;

        // Cast smaller type to the bigger type
        if (lhsType != biggerType) {
            insertCast(binOp, biggerType, binOp.getLhs());
        }
        else if (rhsType != biggerType) {
            insertCast(binOp, biggerType, binOp.getRhs());
        }
    }
    else if ( (lhsType == DataType.BYTEARRAY) &&
            (DataType.isNumberType(rhsType)) ) {
        insertCast(binOp, rhsType, binOp.getLhs());
    }
    else if ( (rhsType == DataType.BYTEARRAY) &&
            (DataType.isNumberType(lhsType)) ) {
        insertCast(binOp, lhsType, binOp.getRhs());
    }
    else if ( (lhsType == DataType.BYTEARRAY) &&
            (rhsType == DataType.BYTEARRAY) ) {
        // Cast both operands to double
        insertCast(binOp, DataType.DOUBLE, binOp.getLhs());
        insertCast(binOp, DataType.DOUBLE, binOp.getRhs());
    }
    else {
        int errCode = 1039;
        String msg = generateIncompatibleTypesMessage(binOp);
        msgCollector.collect(msg, MessageType.Error);
        throw new TypeCheckerException(binOp, msg, errCode, PigException.INPUT) ;
    }

}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:53,代码来源:TypeCheckingExpVisitor.java

示例4: addCastsToCompareBinaryExp

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private void addCastsToCompareBinaryExp(BinaryExpression binOp, boolean isEquality)
throws FrontendException {
    LogicalExpression lhs = binOp.getLhs() ;
    LogicalExpression rhs = binOp.getRhs() ;

    byte lhsType = lhs.getType() ;
    byte rhsType = rhs.getType() ;
    if ( DataType.isNumberType(lhsType) &&
            DataType.isNumberType(rhsType) ) {
        // If not the same type, we cast them to the same
        byte biggerType = lhsType > rhsType ? lhsType:rhsType ;

        // Cast smaller type to the bigger type
        if (lhsType != biggerType) {
            insertCast(binOp, biggerType, binOp.getLhs());
        }
        else if (rhsType != biggerType) {
            insertCast(binOp, biggerType, binOp.getRhs());
        }
    }
    else if ( (lhsType == DataType.DATETIME) &&
            (rhsType == DataType.DATETIME) ) {
        // good
    }
    else if ( (lhsType == DataType.CHARARRAY) &&
            (rhsType == DataType.CHARARRAY) ) {
        // good
    }
    else if ( (lhsType == DataType.BYTEARRAY) &&
            (rhsType == DataType.BYTEARRAY) ) {
        // good
    }
    else if ( (lhsType == DataType.BYTEARRAY) &&
            ( (rhsType == DataType.CHARARRAY) || (DataType.isNumberType(rhsType)) || (rhsType == DataType.BOOLEAN) || (rhsType == DataType.DATETIME))
    ) {
        // Cast byte array to the type on rhs
        insertCast(binOp, rhsType, binOp.getLhs());
    }
    else if ( (rhsType == DataType.BYTEARRAY) &&
            ( (lhsType == DataType.CHARARRAY) || (DataType.isNumberType(lhsType)) || (lhsType == DataType.BOOLEAN) || (lhsType == DataType.DATETIME))
    ) {
        // Cast byte array to the type on lhs
        insertCast(binOp, lhsType, binOp.getRhs());
    }else if (isEquality){

        //in case of equality condition, allow boolean, tuples and maps as args
        if((lhsType == DataType.BOOLEAN) &&
                (rhsType == DataType.BOOLEAN) ) {
            // good
        }
        else if((lhsType == DataType.TUPLE) &&
                (rhsType == DataType.TUPLE) ) {
            // good
        }
        else if ( (lhsType == DataType.MAP) &&
                (rhsType == DataType.MAP) ) {
            // good
        }
        else if (lhsType == DataType.BYTEARRAY &&
                (rhsType == DataType.MAP || rhsType == DataType.TUPLE)){
            // Cast byte array to the type on lhs
            insertCast(binOp, rhsType, binOp.getLhs());
        }
        else if(rhsType == DataType.BYTEARRAY &&
                (lhsType == DataType.MAP || lhsType == DataType.TUPLE)){
            // Cast byte array to the type on lhs
            insertCast(binOp, lhsType, binOp.getRhs());
        }
        else {
            throwIncompatibleTypeError(binOp);
        }
    }
    else {
        throwIncompatibleTypeError(binOp);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:77,代码来源:TypeCheckingExpVisitor.java

示例5: 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 ;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:73,代码来源:Schema.java

示例6: exec

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
public Double exec(Tuple input) throws IOException 
{
	if (input == null || input.size() == 0) {
           pigLogger.warn(this, "Input is empty.", PigWarning.UDF_WARNING_1); 
		return null;
       }

       Double output = null;
       boolean accumulated = false;

	try {
           for(int i = 0; i < input.size(); ++i) {
               Object o = input.get(i);
               byte inputType = DataType.findType(o);
               if(DataType.isNumberType(inputType)) {
                   if(!accumulated) {
                       output = 0.0;
                       accumulated = true;
                   }
                   switch(inputType) {
                   case DataType.INTEGER:
                       output += (Integer)o;
                       break;

                   case DataType.LONG:
                       output += (Long)o;
                       break;

                   case DataType.FLOAT:
                       output += (Float)o;
                       break;

                   case DataType.DOUBLE:
                       output += (Double)o;
                       break;
                   }

               } else {
                   pigLogger.warn(this, "Found a non-numeric type.", PigWarning.UDF_WARNING_3);
               }
           }
	} catch(Exception e){
           pigLogger.warn(this, "Problem while computing output.", PigWarning.UDF_WARNING_2); 
		return null;
	}

       if(!accumulated) {
           pigLogger.warn(this, "Did not find any numeric type in the input.", PigWarning.UDF_WARNING_4);
       }

	return output;
   }
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:53,代码来源:TestWarningFunc.java


注:本文中的org.apache.pig.data.DataType.isNumberType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。