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


Java DataType.findType方法代码示例

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


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

示例1: compare

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
    if (o1 == null)
        return -1;
    if (o2 == null)
        return 1;
    try {
        Object field1 = o1.get(fieldNum);
        Object field2 = o2.get(fieldNum);
        if (!typeFound) {
            datatype = DataType.findType(field1);
            typeFound = true;
        }
        return DataType.compare(field1, field2, datatype, datatype);
    } catch (ExecException e) {
        throw new RuntimeException("Error while comparing o1:" + o1
                + " and o2:" + o2, e);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:20,代码来源:Top.java

示例2: compare

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
    if (o1 == null)
        return -1;
    if (o2 == null)
        return 1;
    try {
        Object field1 = o1.get(fieldNum);
        Object field2 = o2.get(fieldNum);
        if (!typeFound) {
            datatype = DataType.findType(field1);
            if(datatype != DataType.NULL) {
                typeFound = true;
            }
        }
        return DataType.compare(field1, field2, datatype, datatype);
    } catch (ExecException e) {
        throw new RuntimeException("Error while comparing o1:" + o1
                + " and o2:" + o2, e);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:22,代码来源:TOP.java

示例3: compare

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public int compare(Tuple o1, Tuple o2) {
    int ret = 0;
    if (o1 == null) {
        ret = -1;
    } else if (o2 == null) {
        ret = 1;
    } else {
        try {
            Object field1 = o1.get(fieldNum);
            Object field2 = o2.get(fieldNum);
            if (!typeFound) {
                datatype = DataType.findType(field1);
                if(datatype != DataType.NULL) {
                    typeFound = true;
                }
            }
            ret =  DataType.compare(field1, field2, datatype, datatype);
        } catch (ExecException e) {
            throw new RuntimeException("Error while comparing o1:" + o1
                    + " and o2:" + o2, e);
        }
    }
    return isDescOrder ? ret : ret * -1;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:26,代码来源:TOP.java

示例4: getResult

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private Result getResult(ExpressionOperator op) throws ExecException {
    Result res;
    switch (op.getResultType()) {
    case DataType.BAG:
    case DataType.BOOLEAN:
    case DataType.BYTEARRAY:
    case DataType.CHARARRAY:
    case DataType.DOUBLE:
    case DataType.FLOAT:
    case DataType.INTEGER:
    case DataType.LONG:
    case DataType.BIGINTEGER:
    case DataType.BIGDECIMAL:
    case DataType.DATETIME:
    case DataType.MAP:
    case DataType.TUPLE:
        res = op.getNext(op.getResultType());
        break;
    default:
        String msg = "Invalid result type: "
                + DataType.findType(op.getResultType());
        throw new ExecException(msg, 2270, PigException.BUG);
    }

    return res;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:27,代码来源:POPartialAgg.java

示例5: inferWritable

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
protected Object inferWritable(Object o) throws BackendException {
  System.out.println("Got object '" + o + "' type " + o.getClass());
  switch (DataType.findType(o)) {
    case BYTEARRAY: {
      return new BytesWritable(((DataByteArray) o).get());
    }
    case CHARARRAY: {
      return new Text(o.toString());
    }
    case INTEGER: {
      return new IntWritable((Integer) o);
    }
    case LONG: {
      return new LongWritable((Long) o);
    }
    case FLOAT: {
      return new FloatWritable((Float) o);
    }
    case DOUBLE: {
      return new DoubleWritable((Double) o);
    }
    case BOOLEAN: {
      return new BooleanWritable((Boolean) o);
    }
    case BYTE: {
      return new ByteWritable((Byte) o);
    }
  }
  throw new BackendException("Unable to translate " + o.getClass() +
      " to a Writable datatype");
}
 
开发者ID:Hanmourang,项目名称:hiped2,代码行数:32,代码来源:SequenceFileStoreFunc.java

示例6: outputSchema

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
/**
 * Override outputSchema so we can verify the input schema at pig compile time, instead of runtime
 * @param inputSchema input schema
 * @return call to super.outputSchema in case schema was defined elsewhere
 */
@Override
public Schema outputSchema(Schema inputSchema)
{
  if (inputSchema == null) {
    throw new IllegalArgumentException(String.format("%s: null schema passed to %s", _method_signature(), getClass().getName()));
  }

  // check correct number of arguments
  @SuppressWarnings("rawtypes")
  Class parameterTypes[] = m.getParameterTypes();
  if (inputSchema.size() != parameterTypes.length) {
    throw new IllegalArgumentException(String.format("%s: got %d arguments, expected %d.",
                                                     _method_signature(),
                                                     inputSchema.size(),
                                                     parameterTypes.length));
  }

  // check type for each argument
  for (int i=0; i < parameterTypes.length; i++) {
    try {
      byte inputType = inputSchema.getField(i).type;
      byte parameterType = DataType.findType(parameterTypes[i]);
      if (inputType != parameterType) {
        throw new IllegalArgumentException(String.format("%s: argument type mismatch [#%d]; expected %s, got %s",
                                                         _method_signature(),
                                                         i+1,
                                                         DataType.findTypeName(parameterType),
                                                         DataType.findTypeName(inputType)));
      }
    }
    catch (FrontendException fe) {
      throw new IllegalArgumentException(String.format("%s: Problem with input schema: ", _method_signature(), inputSchema), fe);
    }
  }

  // delegate to super to determine the actual outputSchema (if specified)
  return super.outputSchema(inputSchema);
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:44,代码来源:SimpleEvalFunc.java

示例7: outputSchema

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
   public Schema outputSchema(Schema input) {
	// Pull the generic parameter to determine the return type.
	Class<T> typeOfT = (Class<T>)
               ((ParameterizedType)getClass()
               .getGenericSuperclass())
               .getActualTypeArguments()[0];

     return new Schema(new Schema.FieldSchema(null, DataType.findType(typeOfT)));				
}
 
开发者ID:JamesLampton,项目名称:piggybank-squeal,代码行数:11,代码来源:KOpBase.java

示例8: emitSet

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
void emitSet(Set<Entry<Writable, IntWritable>> s, Integer msign) {
			for (Entry<Writable, IntWritable>  ent: s) {
				int count = ent.getValue().get();
//				System.err.println("Pos: " + ent);
				for (int i = 0; i < count ; i++) {
					byte t = DataType.findType(ent.getKey());
					try {
						// Emit to the STORE function if we're a leaf.
						if (isLeaf) {
							// Set the sign reference appropriately.
							sign.set(msign);
							// Attach the input to the store function and empty it.
							for (POStore store : stores) {
//								System.out.println("emitSet: " + ent.getKey());
								Tuple tup = (Tuple) ent.getKey();
								store.attachInput(tup);
								store.getNextTuple();
							}
						}
												
						// Emit to the stream.
						collector.emit(new FValues(null, HDataType.getWritableComparableTypes(ent.getKey(), t), msign));
					} catch (ExecException e) {
						throw new RuntimeException(e);
					}
				}
			}
		}
 
开发者ID:JamesLampton,项目名称:piggybank-squeal,代码行数:29,代码来源:Reduce.java

示例9: negate

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private Object negate(Object o) throws ExecException {
	byte dt = DataType.findType(o);
	Object neg_o = null;
	
	switch(dt) {
	case DataType.BIGDECIMAL:
		neg_o = ((BigDecimal)o).negate();
		break;
	case DataType.BIGINTEGER:
		neg_o = ((BigInteger)o).negate();
		break;
	case DataType.FLOAT:
		// Fall through.
	case DataType.DOUBLE:
		neg_o = new Double(-((Number)o).doubleValue());
		break;
	case DataType.INTEGER:
		// Fall through.
	case DataType.LONG:
		neg_o = new Long(-((Number)o).longValue());
		break;
	default:
		int errCode = 2106;
              throw new ExecException("Unknown data type for object: " + o.getClass().getName(), errCode, PigException.BUG);
	}
	
	return neg_o;
}
 
开发者ID:JamesLampton,项目名称:piggybank-squeal,代码行数:29,代码来源:AlgebraicMathBase.java

示例10: GetUnequalValue

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
Object GetUnequalValue(Object v) {
    byte type = DataType.findType(v);

    if (type == DataType.BAG || type == DataType.TUPLE
            || type == DataType.MAP)
        return null;

    Object zero = generateData(type, "0");

    if (v.equals(zero))
        return generateData(type, "1");

    return zero;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:15,代码来源:AugmentBaseDataVisitor.java

示例11: getResult

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
private Result getResult(ExpressionOperator op) throws ExecException {
    Result res = ERR_RESULT;
    switch (op.getResultType()) {
    case DataType.BAG:
    case DataType.BOOLEAN:
    case DataType.BYTEARRAY:
    case DataType.CHARARRAY:
    case DataType.DOUBLE:
    case DataType.FLOAT:
    case DataType.INTEGER:
    case DataType.LONG:
    case DataType.BIGINTEGER:
    case DataType.BIGDECIMAL:
    case DataType.DATETIME:
    case DataType.MAP:
    case DataType.TUPLE:
        res = op.getNext(op.getResultType());
        break;
    default:
        String msg = "Invalid result type: "
                + DataType.findType(op.getResultType());
        throw new ExecException(msg, 2270, PigException.BUG);
    }

    // allow null as group by key
    if (res.returnStatus == POStatus.STATUS_OK
            || res.returnStatus == POStatus.STATUS_NULL) {
        return res;
    }
    return ERR_RESULT;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:32,代码来源:POPartialAgg.java

示例12: GetLargerValue

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
Object GetLargerValue(Object v) {
    byte type = DataType.findType(v);

    if (type == DataType.BAG || type == DataType.TUPLE
            || type == DataType.MAP)
        return null;

    switch (type) {
    case DataType.CHARARRAY:
        return (String) v + "0";
    case DataType.BYTEARRAY:
        String str = ((DataByteArray) v).toString();
        str = str + "0";
        return new DataByteArray(str);
    case DataType.INTEGER:
        return Integer.valueOf((Integer) v + 1);
    case DataType.LONG:
        return Long.valueOf((Long) v + 1);
    case DataType.FLOAT:
        return Float.valueOf((Float) v + 1);
    case DataType.DOUBLE:
        return Double.valueOf((Double) v + 1);
    case DataType.BIGINTEGER:
        return ((BigInteger)v).add(BigInteger.ONE);
    case DataType.BIGDECIMAL:
        return ((BigDecimal)v).add(BigDecimal.ONE);
    case DataType.DATETIME:
        DateTime dt = (DateTime) v;
        if (dt.getMillisOfSecond() != 0) {
            return dt.plusMillis(1);
        } else if (dt.getSecondOfMinute() != 0) {
            return dt.plusSeconds(1);
        } else if (dt.getMinuteOfHour() != 0) {
            return dt.plusMinutes(1);
        } else if (dt.getHourOfDay() != 0) {
            return dt.plusHours(1);
        } else {
            return dt.plusDays(1);
        }
    default:
        return null;
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:44,代码来源:AugmentBaseDataVisitor.java

示例13: GetSmallerValue

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
Object GetSmallerValue(Object v) {
    byte type = DataType.findType(v);

    if (type == DataType.BAG || type == DataType.TUPLE
            || type == DataType.MAP)
        return null;

    switch (type) {
    case DataType.CHARARRAY:
        String str = (String) v;
        if (str.length() > 0)
            return str.substring(0, str.length() - 1);
        else
            return null;
    case DataType.BYTEARRAY:
        DataByteArray data = (DataByteArray) v;
        if (data.size() > 0)
            return new DataByteArray(data.get(), 0, data.size() - 1);
        else
            return null;
    case DataType.INTEGER:
        return Integer.valueOf((Integer) v - 1);
    case DataType.LONG:
        return Long.valueOf((Long) v - 1);
    case DataType.FLOAT:
        return Float.valueOf((Float) v - 1);
    case DataType.DOUBLE:
        return Double.valueOf((Double) v - 1);
    case DataType.BIGINTEGER:
        return ((BigInteger)v).subtract(BigInteger.ONE);
    case DataType.BIGDECIMAL:
        return ((BigDecimal)v).subtract(BigDecimal.ONE);
    case DataType.DATETIME:
        DateTime dt = (DateTime) v;
        if (dt.getMillisOfSecond() != 0) {
            return dt.minusMillis(1);
        } else if (dt.getSecondOfMinute() != 0) {
            return dt.minusSeconds(1);
        } else if (dt.getMinuteOfHour() != 0) {
            return dt.minusMinutes(1);
        } else if (dt.getHourOfDay() != 0) {
            return dt.minusHours(1);
        } else {
            return dt.minusDays(1);
        }
    default:
        return null;
    }

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

示例14: 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

示例15: getFieldSchema

import org.apache.pig.data.DataType; //导入方法依赖的package包/类
@Override
public LogicalSchema.LogicalFieldSchema getFieldSchema() throws FrontendException {
    if (fieldSchema!=null)
        return fieldSchema;

    LogicalSchema inputSchema = new LogicalSchema();
    List<Operator> succs = plan.getSuccessors(this);

    if (succs!=null) {
        for(Operator lo : succs){
            if (((LogicalExpression)lo).getFieldSchema()==null) {
                inputSchema = null;
                break;
            }
            inputSchema.addField(((LogicalExpression)lo).getFieldSchema());
        }
    }

    if (lazilyInitializeInvokerFunction) {
        initializeInvokerFunction();
    }

    // Since ef only set one time, we never change its value, so we can optimize it by instantiate only once.
    // This significantly optimize the performance of frontend (PIG-1738)
    if (ef==null) {
        ef = (EvalFunc<?>) PigContext.instantiateFuncFromSpec(mFuncSpec);
    }

    ef.setUDFContextSignature(signature);
    Properties props = UDFContext.getUDFContext().getUDFProperties(ef.getClass());
    Schema translatedInputSchema = Util.translateSchema(inputSchema);
    if(translatedInputSchema != null) {
        props.put("pig.evalfunc.inputschema."+signature, translatedInputSchema);
    }
    // Store inputSchema into the UDF context
    ef.setInputSchema(translatedInputSchema);

    Schema udfSchema = ef.outputSchema(translatedInputSchema);
    if (udfSchema != null && udfSchema.size() > 1) {
        throw new FrontendException("Given UDF returns an improper Schema. Schema should only contain one field of a Tuple, Bag, or a single type. Returns: " + udfSchema);
    }

    //TODO appendability should come from a setting
    SchemaTupleFrontend.registerToGenerateIfPossible(translatedInputSchema, false, GenContext.UDF);
    SchemaTupleFrontend.registerToGenerateIfPossible(udfSchema, false, GenContext.UDF);

    if (udfSchema != null) {
        Schema.FieldSchema fs;
        if(udfSchema.size() == 0) {
            fs = new Schema.FieldSchema(null, null, DataType.findType(ef.getReturnType()));
        } else if(udfSchema.size() == 1) {
            fs = new Schema.FieldSchema(udfSchema.getField(0));
        } else {
            fs = new Schema.FieldSchema(null, udfSchema, DataType.TUPLE);
        }
        fieldSchema = Util.translateFieldSchema(fs);
        fieldSchema.normalize();
    } else {
        fieldSchema = new LogicalSchema.LogicalFieldSchema(null, null, DataType.findType(ef.getReturnType()));
    }
    uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
    return fieldSchema;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:64,代码来源:UserFuncExpression.java


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