本文整理汇总了Java中org.apache.pig.data.DataType.LONG属性的典型用法代码示例。如果您正苦于以下问题:Java DataType.LONG属性的具体用法?Java DataType.LONG怎么用?Java DataType.LONG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.pig.data.DataType
的用法示例。
在下文中一共展示了DataType.LONG属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: typeName
public String typeName(byte type) {
switch(type) {
case (DataType.INTEGER): return "int";
case (DataType.LONG): return "long";
case (DataType.FLOAT): return "float";
case (DataType.DOUBLE): return "double";
case (DataType.BYTEARRAY): return "byte[]";
case (DataType.CHARARRAY): return "String";
case (DataType.BOOLEAN): return "boolean";
case (DataType.DATETIME): return "DateTime";
case (DataType.BIGDECIMAL): return "BigDecimal";
case (DataType.BIGINTEGER): return "BigInteger";
case (DataType.TUPLE): return "Tuple";
case (DataType.BAG): return "DataBag";
case (DataType.MAP): return "Map";
default: throw new RuntimeException("Can't return String for given type " + DataType.findTypeName(type));
}
}
示例2: process
@Override
public void process(int fieldPos, Schema.FieldSchema fs) {
add("public "+typeName()+" getDummy_"+fieldPos+"() {");
switch (fs.type) {
case (DataType.INTEGER): add(" return 0;"); break;
case (DataType.LONG): add(" return 0L;"); break;
case (DataType.FLOAT): add(" return 0.0f;"); break;
case (DataType.DOUBLE): add(" return 0.0;"); break;
case (DataType.BOOLEAN): add(" return true;"); break;
case (DataType.DATETIME): add(" return new DateTime();"); break;
case (DataType.BIGDECIMAL): add(" return (BigDecimal)null;"); break;
case (DataType.BIGINTEGER): add(" return (BigInteger)null;"); break;
case (DataType.BYTEARRAY): add(" return (byte[])null;"); break;
case (DataType.CHARARRAY): add(" return (String)null;"); break;
case (DataType.TUPLE): add(" return (Tuple)null;"); break;
case (DataType.BAG): add(" return (DataBag)null;"); break;
case (DataType.MAP): add(" return (Map<String,Object>)null;"); break;
default: throw new RuntimeException("Unsupported type");
}
add("}");
addBreak();
}
示例3: getPredicateFields
@Override
public List<String> getPredicateFields(String location, Job job) throws IOException {
ResourceSchema schema = getSchema(location, job);
List<String> predicateFields = new ArrayList<String>();
for (ResourceFieldSchema field : schema.getFields()) {
switch(field.getType()) {
case DataType.BOOLEAN:
case DataType.INTEGER:
case DataType.LONG:
case DataType.FLOAT:
case DataType.DOUBLE:
case DataType.DATETIME:
case DataType.CHARARRAY:
case DataType.BIGINTEGER:
case DataType.BIGDECIMAL:
predicateFields.add(field.getName());
break;
default:
// Skip DataType.BYTEARRAY, DataType.TUPLE, DataType.MAP and DataType.BAG
break;
}
}
return predicateFields;
}
示例4: equalsZero
protected boolean equalsZero(Number a, byte dataType) throws ExecException {
switch (dataType) {
case DataType.DOUBLE:
return ((Double) a).equals(0.0);
case DataType.INTEGER:
return ((Integer) a).equals(0);
case DataType.LONG:
return ((Long) a).equals(0L);
case DataType.FLOAT:
return ((Float) a).equals(0.0f);
case DataType.BIGINTEGER:
return BigInteger.ZERO.equals((BigInteger) a);
case DataType.BIGDECIMAL:
return BigDecimal.ZERO.equals((BigDecimal) a);
default:
throw new ExecException("Called on unsupported Number class " + DataType.findTypeName(dataType));
}
}
示例5: 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;
}
}
示例6: outputSchema
/**
* Validates format of input schema and returns a matching schema
* @param input Expects input to be a bag of sketches: <tt>(n, k, {(samples...)})</tt>
* @return Schema based on the
*/
@Override
public Schema outputSchema(final Schema input) {
if (input != null && input.size() > 0) {
try {
Schema source = input;
// if we have a bag, grab one level down to get a tuple
if (source.size() == 1 && source.getField(0).type == DataType.BAG) {
source = source.getField(0).schema;
}
if (source.size() == 1 && source.getField(0).type == DataType.TUPLE) {
source = source.getField(0).schema;
}
final List<Schema.FieldSchema> fields = source.getFields();
if (fields.size() == 3
&& fields.get(0).type == DataType.LONG
&& fields.get(1).type == DataType.INTEGER
&& fields.get(2).type == DataType.BAG) {
return new Schema(new Schema.FieldSchema(getSchemaName(this
.getClass().getName().toLowerCase(), source), source, DataType.TUPLE));
}
} catch (final FrontendException e) {
throw new RuntimeException(e);
}
}
return null;
}
示例7: parseSimpleType
private Object parseSimpleType(byte[] b, ResourceFieldSchema simpleFieldSchema) throws IOException {
Object field;
switch (simpleFieldSchema.getType()) {
case DataType.INTEGER:
field = bytesToInteger(b);
break;
case DataType.LONG:
field = bytesToLong(b);
break;
case DataType.FLOAT:
field = bytesToFloat(b);
break;
case DataType.DOUBLE:
field = bytesToDouble(b);
break;
case DataType.CHARARRAY:
field = bytesToCharArray(b);
break;
case DataType.BYTEARRAY:
field = new DataByteArray(b);
break;
case DataType.BOOLEAN:
field = bytesToBoolean(b);
break;
case DataType.BIGINTEGER:
field = bytesToBigInteger(b);
break;
case DataType.BIGDECIMAL:
field = bytesToBigDecimal(b);
case DataType.DATETIME:
field = bytesToDateTime(b);
break;
default:
throw new IOException("Unknown simple data type");
}
return field;
}
示例8: getBagWithNulls
private DataBag getBagWithNulls(byte type) {
DataBag bag = DefaultBagFactory.getInstance().newDefaultBag();
for(int i = 0; i < 10; i ++) {
Tuple t = TupleFactory.getInstance().newTuple();
if (r.nextInt(4)%3 == 0){
t.append(null);
}else{
switch(type) {
case DataType.BOOLEAN:
t.append(r.nextBoolean());
break;
case DataType.INTEGER:
t.append(r.nextInt(2));
break;
case DataType.LONG:
t.append(r.nextLong() % 2L);
break;
case DataType.FLOAT:
t.append( (i % 2 == 0 ? 1.0f : 0.0f));
break;
case DataType.DOUBLE:
t.append( (i % 2 == 0 ? 1.0 : 0.0));
break;
case DataType.DATETIME:
t.append(new DateTime(r.nextLong() % 2L));
break;
}
}
t.append(1);
t.append(0);
bag.add(t);
}
return bag;
}
示例9: getBag
private DataBag getBag(byte type) {
DataBag bag = DefaultBagFactory.getInstance().newDefaultBag();
for(int i = 0; i < 10; i ++) {
Tuple t = TupleFactory.getInstance().newTuple();
switch(type) {
case DataType.BOOLEAN:
t.append(r.nextBoolean());
break;
case DataType.INTEGER:
t.append(r.nextInt(2));
break;
case DataType.LONG:
t.append(r.nextLong() % 2L);
break;
case DataType.FLOAT:
t.append((i % 2 == 0 ? 1.0f : 0.0f));
break;
case DataType.DOUBLE:
t.append((i % 2 == 0 ? 1.0 : 0.0));
break;
case DataType.DATETIME:
t.append(new DateTime(r.nextLong() % 2L));
break;
}
t.append(1);
t.append(0);
bag.add(t);
}
return bag;
}
示例10: negate
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;
}
示例11: getNextBoolean
@Override
public Result getNextBoolean() throws ExecException {
Result left, right;
switch (operandType) {
case DataType.BYTEARRAY:
case DataType.DOUBLE:
case DataType.FLOAT:
case DataType.INTEGER:
case DataType.BIGINTEGER:
case DataType.BIGDECIMAL:
case DataType.LONG:
case DataType.DATETIME:
case DataType.CHARARRAY: {
Result r = accumChild(null, operandType);
if (r != null) {
return r;
}
left = lhs.getNext(operandType);
right = rhs.getNext(operandType);
return doComparison(left, right);
}
default: {
int errCode = 2067;
String msg = this.getClass().getSimpleName() + " does not know how to " +
"handle type: " + DataType.findTypeName(operandType);
throw new ExecException(msg, errCode, PigException.BUG);
}
}
}
示例12: testPigStorageSchema
@Test
public void testPigStorageSchema() throws Exception {
pigContext.connect();
String query = "a = LOAD '" + datadir + "originput' using PigStorage('\\t') " +
"as (f1:chararray, f2:int);";
pig.registerQuery(query);
Schema origSchema = pig.dumpSchema("a");
pig.store("a", datadir + "aout", "PigStorage('\\t', '-schema')");
// aout now has a schema.
// Verify that loading a-out with no given schema produces
// the original schema.
pig.registerQuery("b = LOAD '" + datadir + "aout' using PigStorage('\\t');");
Schema genSchema = pig.dumpSchema("b");
Assert.assertTrue("generated schema equals original" ,
Schema.equals(genSchema, origSchema, true, false));
// Verify that giving our own schema works
String [] aliases ={"foo", "bar"};
byte[] types = {DataType.INTEGER, DataType.LONG};
Schema newSchema = TypeCheckingTestUtil.genFlatSchema(
aliases,types);
pig.registerQuery("c = LOAD '" + datadir + "aout' using PigStorage('\\t', '-schema') "+
"as (foo:int, bar:long);");
Schema newGenSchema = pig.dumpSchema("c");
Assert.assertTrue("explicit schema overrides metadata",
Schema.equals(newSchema, newGenSchema, true, false));
// Verify that explicitly requesting no schema works
pig.registerQuery("d = LOAD '" + datadir + "aout' using PigStorage('\\t', '-noschema');");
genSchema = pig.dumpSchema("d");
assertNull(genSchema);
}
示例13: 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;
}
示例14: 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);
}
示例15: 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());
}
}
}