本文整理汇总了Java中org.apache.pig.data.DataType.DOUBLE属性的典型用法代码示例。如果您正苦于以下问题:Java DataType.DOUBLE属性的具体用法?Java DataType.DOUBLE怎么用?Java DataType.DOUBLE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.pig.data.DataType
的用法示例。
在下文中一共展示了DataType.DOUBLE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPOBinCondDoubleWithNull
@Test
public void testPOBinCondDoubleWithNull() throws ExecException, PlanException {
bag= getBagWithNulls(DataType.DOUBLE);
TestPoBinCondHelper testHelper= new TestPoBinCondHelper(DataType.DOUBLE, new Double(1.0) );
for (Tuple t : bag) {
testHelper.getPlan().attachInput(t);
Double value=null;
if ( t.get(0)!=null){
value = (Double) t.get(0);
}
Integer dummy = new Integer(0);
Integer result=(Integer)testHelper.getOperator().getNextInteger().result;
int expected;
int actual;
if ( value!=null ) {
expected=(value.intValue() == 1)? 1:0 ;
actual = result.intValue();
assertEquals( expected, actual );
} else {
assertNull(result);
}
}
}
示例2: convertToType
/**
*
* @param caster LoadCaster to be used to convert the bytes into a field.
* @param bytes
* @param fieldSchema schema of Bag or Tuple; pass in null if a simple type.
* @param dataType type from DataType
* @return converted object.
* @throws IOException
*/
public static Object convertToType(LoadCaster caster, byte[] bytes,
ResourceFieldSchema fieldSchema, byte dataType) throws IOException {
switch (dataType) {
case (DataType.BAG): return caster.bytesToBag(bytes, fieldSchema);
case (DataType.BYTEARRAY): return new DataByteArray(bytes);
case (DataType.CHARARRAY): return caster.bytesToCharArray(bytes);
case (DataType.DOUBLE): return caster.bytesToDouble(bytes);
case (DataType.FLOAT): return caster.bytesToFloat(bytes);
case (DataType.INTEGER): return caster.bytesToInteger(bytes);
case (DataType.BIGINTEGER): return caster.bytesToBigInteger(bytes);
case (DataType.BIGDECIMAL): return caster.bytesToBigDecimal(bytes);
case (DataType.LONG): return caster.bytesToLong(bytes);
case (DataType.BOOLEAN): return caster.bytesToBoolean(bytes);
case (DataType.DATETIME): return caster.bytesToDateTime(bytes);
case (DataType.MAP): return caster.bytesToMap(bytes);
case (DataType.TUPLE): return caster.bytesToTuple(bytes, fieldSchema);
default: throw new IOException("Unknown type " + dataType);
}
}
示例3: getTypedObject
private TypedObject getTypedObject(Object data, FieldDetail detail) throws ExecException {
if (data == null) {
return null;
}
byte type = detail.type;
switch (type) {
case DataType.BOOLEAN:
return TypeSystem.asTypedObject(DataType.toBoolean(data, type));
case DataType.INTEGER:
case DataType.LONG:
return TypeSystem.asTypedObject(DataType.toLong(data, type));
case DataType.FLOAT:
case DataType.DOUBLE:
return TypeSystem.asTypedObject(DataType.toDouble(data, type));
case DataType.DATETIME:
return TypeSystem.asTypedObject(new Timestamp(DataType.toDateTime(data, type).getMillis()));
case DataType.BYTE:
case DataType.BYTEARRAY:
case DataType.CHARARRAY:
return TypeSystem.asTypedObject(DataType.toString(data, type));
case DataType.BIGINTEGER:
case DataType.BIGDECIMAL:
return TypeSystem.asTypedObject(DataType.toBigDecimal(data, type));
default:
//TUPLE, BAG, MAP, INTERNALMAP, GENERIC_WRITABLECOMPARABLE, ERROR, UNKNOWN, NULL and anything else
return null;
}
}
示例4: outputSchema
@Override
public Schema outputSchema(final Schema input) {
try {
if (input == null || input.size() == 0) {
throw new IllegalArgumentException("Degenerate input schema to VarOptSampling");
}
// first element must be a bag, weightIdx_ element of tuples must be a float or double
if (input.getField(0).type != DataType.BAG) {
throw new IllegalArgumentException("VarOpt input must be a data bag: "
+ input.toString());
}
final Schema record = input.getField(0).schema; // record has a tuple in field 0
final Schema fields = record.getField(0).schema;
if (fields.getField(weightIdx_).type != DataType.DOUBLE
&& fields.getField(weightIdx_).type != DataType.FLOAT) {
throw new IllegalArgumentException("weightIndex item of VarOpt tuple must be a "
+ "weight (double/float), found " + fields.getField(0).type
+ ": " + fields.toString());
}
final Schema weightedSampleSchema = new Schema();
weightedSampleSchema.add(new Schema.FieldSchema(WEIGHT_ALIAS, DataType.DOUBLE));
weightedSampleSchema.add(new Schema.FieldSchema(RECORD_ALIAS, record, DataType.TUPLE));
return new Schema(new Schema.FieldSchema(getSchemaName(this
.getClass().getName().toLowerCase(), record), weightedSampleSchema, DataType.BAG));
}
catch (final FrontendException e) {
throw new RuntimeException(e);
}
}
示例5: outputSchema
@Override
public Schema outputSchema(final Schema input) {
try {
if (input == null || input.size() == 0) {
throw new IllegalArgumentException("Degenerate input schema to VarOptSampling");
}
// first element must be a bag
if (input.getField(0).type != DataType.BAG) {
throw new IllegalArgumentException("VarOpt input must be a data bag: "
+ input.toString());
}
final Schema record = input.getField(0).schema; // record has a tuple in field 0
final Schema fields = record.getField(0).schema;
if (fields.getField(weightIdx_).type != DataType.DOUBLE
&& fields.getField(weightIdx_).type != DataType.FLOAT) {
throw new IllegalArgumentException("weightIndex item of VarOpt tuple must be a "
+ "weight (double/float), found " + fields.getField(0).type
+ ": " + fields.toString());
}
return new Schema(new Schema.FieldSchema(getSchemaName(this
.getClass().getName().toLowerCase(), input), DataType.BYTEARRAY));
}
catch (final FrontendException e) {
throw new RuntimeException(e);
}
}
示例6: VARBAG
public VARBAG(String bagColName, String tupleColName, String fieldType) {
if ( bagColName== null || tupleColName == null || fieldType == null) {
throw new RuntimeException("The bagColName and fieldType cannot be null");
}
this.bagColName = bagColName;
this.tupleColName = tupleColName;
if ( fieldType.equalsIgnoreCase( "CHARARRAY" )){
this.fieldType = DataType.CHARARRAY;
} else if ( fieldType.equalsIgnoreCase( "DOUBLE" )){
this.fieldType = DataType.DOUBLE;
} else if ( fieldType.equalsIgnoreCase( "FLOAT" )){
this.fieldType = DataType.FLOAT;
} else if ( fieldType.equalsIgnoreCase( "BOOLEAN" )) {
this.fieldType = DataType.BOOLEAN;
} else if ( fieldType.equalsIgnoreCase( "INTEGER" )){
this.fieldType = DataType.INTEGER;
} else if ( fieldType.equalsIgnoreCase( "LONG" )){
this.fieldType = DataType.LONG;
} else if ( fieldType.equalsIgnoreCase( "MAP" )){
this.fieldType = DataType.MAP;
} else {
throw new RuntimeException("This type"+ fieldType +"is not supported in " + this.getClass().getSimpleName());
}
}
示例7: outputSchema
@Override
public Schema outputSchema(Schema input)
{
try {
Schema.FieldSchema inputFieldSchema = input.getField(0);
if (inputFieldSchema.type != DataType.BAG)
{
throw new RuntimeException("Expected a BAG as input");
}
Schema inputBagSchema = inputFieldSchema.schema;
if (inputBagSchema.getField(0).type != DataType.TUPLE)
{
throw new RuntimeException(String.format("Expected input bag to contain a TUPLE, but instead found %s",
DataType.findTypeName(inputBagSchema.getField(0).type)));
}
return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass()
.getName()
.toLowerCase(), input),
DataType.DOUBLE));
} catch (FrontendException e) {
throw new RuntimeException(e);
}
}
示例8: TOBAG
public TOBAG(String bagColName, String tupleColName, String fieldType) {
if ( bagColName== null || tupleColName == null || fieldType == null) {
throw new RuntimeException("The bagColName and fieldType cannot be null");
}
this.bagColName = bagColName;
this.tupleColName = tupleColName;
if ( fieldType.equalsIgnoreCase( "CHARARRAY" )){
this.fieldType = DataType.CHARARRAY;
} else if ( fieldType.equalsIgnoreCase( "DOUBLE" )){
this.fieldType = DataType.DOUBLE;
} else if ( fieldType.equalsIgnoreCase( "FLOAT" )){
this.fieldType = DataType.FLOAT;
} else if ( fieldType.equalsIgnoreCase( "BOOLEAN" )){
this.fieldType = DataType.BOOLEAN;
} else if ( fieldType.equalsIgnoreCase( "INTEGER" )){
this.fieldType = DataType.INTEGER;
} else if ( fieldType.equalsIgnoreCase( "LONG" )){
this.fieldType = DataType.LONG;
} else if ( fieldType.equalsIgnoreCase( "MAP" )){
this.fieldType = DataType.MAP;
} else {
throw new RuntimeException("This type"+ fieldType +"is not supported in TOBAG");
}
}
示例9: getNext
/**
* Implementations that call into the different versions of getNext are often
* identical, differing only in the signature of the getNext() call they make.
* This method allows to cut down on some of the copy-and-paste.
* @param dataType Describes the type of obj; a byte from DataType.
*
* @return result Result of applying this Operator to the Object.
* @throws ExecException
*/
public Result getNext(byte dataType) throws ExecException {
try {
switch (dataType) {
case DataType.BAG:
return getNextDataBag();
case DataType.BOOLEAN:
return getNextBoolean();
case DataType.BYTEARRAY:
return getNextDataByteArray();
case DataType.CHARARRAY:
return getNextString();
case DataType.DOUBLE:
return getNextDouble();
case DataType.FLOAT:
return getNextFloat();
case DataType.INTEGER:
return getNextInteger();
case DataType.LONG:
return getNextLong();
case DataType.BIGINTEGER:
return getNextBigInteger();
case DataType.BIGDECIMAL:
return getNextBigDecimal();
case DataType.DATETIME:
return getNextDateTime();
case DataType.MAP:
return getNextMap();
case DataType.TUPLE:
return getNextTuple();
default:
throw new ExecException("Unsupported type for getNext: " + DataType.findTypeName(dataType));
}
} catch (RuntimeException e) {
throw new ExecException("Exception while executing " + this.toString() + ": " + e.toString(), e);
}
}
示例10: buildTuple
public Tuple buildTuple(int rank, JsonNode hit) {
Tuple tuple = TupleFactory.getInstance().newTuple();
for (VespaQuerySchema.AliasTypePair tupleElement : tupleSchema) {
String alias = tupleElement.getAlias();
Byte type = DataType.findTypeByName(tupleElement.getType());
// reserved word
if ("rank".equals(alias)) {
tuple.append(rank);
} else {
JsonNode field = hit;
String[] path = alias.split("/"); // move outside
for (String p : path) {
field = field.get(p);
if (field == null) {
type = DataType.NULL; // effectively skip field as it is not found
break;
}
}
switch (type) {
case DataType.BOOLEAN:
tuple.append(field.asBoolean());
break;
case DataType.INTEGER:
tuple.append(field.asInt());
break;
case DataType.LONG:
tuple.append(field.asLong());
break;
case DataType.FLOAT:
case DataType.DOUBLE:
tuple.append(field.asDouble());
break;
case DataType.DATETIME:
tuple.append(field.asText());
break;
case DataType.CHARARRAY:
tuple.append(field.asText());
break;
default:
// the rest of the data types are currently not supported
}
}
}
return tuple;
}
示例11: getPigType
/**
* Defines a mapping of HCatalog type to Pig type; not every mapping is exact,
* see {@link #extractPigObject(Object,
* com.cloudera.recordservice.core.Schema.TypeDesc)}
* See http://pig.apache.org/docs/r0.12.0/basic.html#data-types
* See {@link org.apache.hive.hcatalog.pig.HCatBaseStorer#validateSchema(
* Schema.FieldSchema, HCatFieldSchema, Schema, HCatSchema, int)}
* for Pig->Hive type mapping.
*/
static public byte getPigType(Type type) throws IOException {
if (type == Type.STRING || type == Type.CHAR || type == Type.VARCHAR) {
//CHARARRAY is unbounded so Hive->Pig is lossless
return DataType.CHARARRAY;
}
if ((type == Type.INT) || (type == Type.SMALLINT) || (type == Type.TINYINT)) {
return DataType.INTEGER;
}
if (type == Type.ARRAY) {
return DataType.BAG;
}
if (type == Type.STRUCT) {
return DataType.TUPLE;
}
if (type == Type.MAP) {
return DataType.MAP;
}
if (type == Type.BIGINT) {
return DataType.LONG;
}
if (type == Type.FLOAT) {
return DataType.FLOAT;
}
if (type == Type.DOUBLE) {
return DataType.DOUBLE;
}
if (type == Type.BINARY) {
return DataType.BYTEARRAY;
}
if (type == Type.BOOLEAN && pigHasBooleanSupport) {
return DataType.BOOLEAN;
}
if(type == Type.DECIMAL) {
//Hive is more restrictive, so Hive->Pig works
return DataType.BIGDECIMAL;
}
if(type == Type.DATE || type == Type.TIMESTAMP) {
//Hive Date is representable as Pig DATETIME
return DataType.DATETIME;
}
throw new PigException("HCatalog column type '" + type.toString()
+ "' is not supported in Pig as a column type", PIG_EXCEPTION_CODE);
}
示例12: updateUnion
static void updateUnion(final DataBag bag, final Union union) throws ExecException {
//Bag is not empty. process each innerTuple in the bag
for (final Tuple innerTuple: bag) {
final Object f0 = innerTuple.get(0); // consider only field 0
if (f0 == null) {
continue;
}
final byte type = innerTuple.getType(0);
switch (type) {
case DataType.NULL:
break;
case DataType.BYTE:
union.update((byte) f0);
break;
case DataType.INTEGER:
union.update((int) f0);
break;
case DataType.LONG:
union.update((long) f0);
break;
case DataType.FLOAT:
union.update((float) f0);
break;
case DataType.DOUBLE:
union.update((double) f0);
break;
case DataType.BYTEARRAY: {
final DataByteArray dba = (DataByteArray) f0;
union.update(dba.get());
break;
}
case DataType.CHARARRAY: {
final String str = (String) f0;
// conversion to char[] avoids costly UTF-8 encoding
union.update(str.toCharArray());
break;
}
default:
throw new IllegalArgumentException("Field 0 of innerTuple must be one of "
+ "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. "
+ "Given Type = " + DataType.findTypeName(type)
+ ", Object = " + f0.toString());
}
}
}
示例13: updateSketch
static void updateSketch(
final DataBag bag, final ArrayOfDoublesUpdatableSketch sketch, final int numValues)
throws ExecException {
if (bag == null) {
throw new IllegalArgumentException("InputTuple.Field0: Bag may not be null");
}
final double[] values = new double[numValues];
for (final Tuple tuple: bag) {
if (tuple.size() != numValues + 1) {
throw new IllegalArgumentException("Inner tuple of input bag must have " + (numValues + 1)
+ " fields.");
}
final Object key = tuple.get(0);
if (key == null) { continue; }
for (int i = 0; i < numValues; i++) {
values[i] = (Double) tuple.get(i + 1);
}
switch (tuple.getType(0)) {
case DataType.BYTE:
sketch.update(((Byte) key).longValue(), values);
break;
case DataType.INTEGER:
sketch.update(((Integer) key).longValue(), values);
break;
case DataType.LONG:
sketch.update((Long) key, values);
break;
case DataType.FLOAT:
sketch.update((Float) key, values);
break;
case DataType.DOUBLE:
sketch.update((Double) key, values);
break;
case DataType.BYTEARRAY:
final DataByteArray dba = (DataByteArray) key;
if (dba.size() != 0) {
sketch.update(dba.get(), values);
}
break;
case DataType.CHARARRAY:
final String s = key.toString();
if (!s.isEmpty()) {
sketch.update(s, values);
}
break;
default:
throw new IllegalArgumentException("Field 0 must be one of "
+ "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. " + "Type = "
+ DataType.findTypeName(tuple.getType(0)) + ", Object = " + key.toString());
}
}
}
示例14: updateSketch
static <U, S extends UpdatableSummary<U>> void updateSketch(final DataBag bag,
final UpdatableSketch<U, S> sketch) throws ExecException {
if (bag == null) {
throw new IllegalArgumentException("InputTuple.Field0: Bag may not be null");
}
for (final Tuple tuple: bag) {
if (tuple.size() != 2) {
throw new IllegalArgumentException("Inner tuple of input bag must have 2 fields.");
}
final Object key = tuple.get(0);
if (key == null) { continue; }
@SuppressWarnings("unchecked")
final U value = (U) tuple.get(1);
switch (tuple.getType(0)) {
case DataType.BYTE:
sketch.update(((Byte) key).longValue(), value);
break;
case DataType.INTEGER:
sketch.update(((Integer) key).longValue(), value);
break;
case DataType.LONG:
sketch.update((Long) key, value);
break;
case DataType.FLOAT:
sketch.update((Float) key, value);
break;
case DataType.DOUBLE:
sketch.update((Double) key, value);
break;
case DataType.BYTEARRAY:
final DataByteArray dba = (DataByteArray) key;
if (dba.size() != 0) {
sketch.update(dba.get(), value);
}
break;
case DataType.CHARARRAY:
final String s = key.toString();
if (!s.isEmpty()) {
sketch.update(s, value);
}
break;
default:
throw new IllegalArgumentException("Field 0 must be one of "
+ "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. " + "Type = "
+ DataType.findTypeName(tuple.getType(0)) + ", Object = " + key.toString());
}
}
}
示例15: updateUnion
/*************************************************************************************************
* Updates a union with the data from the given bag.
*
* @param bag A bag of tuples to insert.
* @param union the union to update
*/
private static void updateUnion(final DataBag bag, final Union union) {
//Bag is not empty. process each innerTuple in the bag
for (Tuple innerTuple : bag) {
final Object f0 = extractFieldAtIndex(innerTuple, 0); //consider only field 0
if (f0 == null) {
continue;
}
final Byte type = extractTypeAtIndex(innerTuple, 0);
if (type == null) {
continue;
}
switch (type) {
case DataType.NULL:
break;
case DataType.BYTE:
union.update((byte) f0);
break;
case DataType.INTEGER:
union.update((int) f0);
break;
case DataType.LONG:
union.update((long) f0);
break;
case DataType.FLOAT:
union.update((float) f0);
break;
case DataType.DOUBLE:
union.update((double) f0);
break;
case DataType.BYTEARRAY: {
final DataByteArray dba = (DataByteArray) f0;
union.update(dba.get()); //checks null, empty
break;
}
case DataType.CHARARRAY: {
union.update(f0.toString()); //checks null, empty
break;
}
default: // types not handled
throw new IllegalArgumentException("Field 0 of innerTuple must be one of "
+ "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. "
+ "Given Type = " + DataType.findTypeName(type)
+ ", Object = " + f0.toString());
} //End switch
} //End for
}