Java Code Examples for org.apache.pig.data.DataType#LONG
The following examples show how to use
org.apache.pig.data.DataType#LONG .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveRCSchemaUtil.java From spork with Apache License 2.0 | 6 votes |
/** * Returns the pig DataType for the hive type * * @param hiveType * @return byte from DataType */ public static byte findPigDataType(String hiveType) { hiveType = hiveType.toLowerCase(); if (hiveType.equals("string")) return DataType.CHARARRAY; else if (hiveType.equals("int")) return DataType.INTEGER; else if (hiveType.equals("bigint") || hiveType.equals("long")) return DataType.LONG; else if (hiveType.equals("float")) return DataType.FLOAT; else if (hiveType.equals("double")) return DataType.DOUBLE; else if (hiveType.equals("boolean")) return DataType.BOOLEAN; else if (hiveType.equals("byte")) return DataType.INTEGER; else if (hiveType.contains("array")) return DataType.TUPLE; else if (hiveType.contains("map")) return DataType.MAP; else return DataType.ERROR; }
Example 2
Source File: Multiply.java From spork with Apache License 2.0 | 6 votes |
protected Number multiply(Number a, Number b, byte dataType) throws ExecException { switch(dataType) { case DataType.DOUBLE: return Double.valueOf((Double) a * (Double) b); case DataType.INTEGER: return Integer.valueOf((Integer) a * (Integer) b); case DataType.LONG: return Long.valueOf((Long) a * (Long) b); case DataType.FLOAT: return Float.valueOf((Float) a * (Float) b); case DataType.BIGINTEGER: return ((BigInteger) a).multiply((BigInteger) b); case DataType.BIGDECIMAL: return ((BigDecimal) a).multiply((BigDecimal) b); default: throw new ExecException("called on unsupported Number class " + DataType.findTypeName(dataType)); } }
Example 3
Source File: Subtract.java From spork with Apache License 2.0 | 6 votes |
protected Number subtract(Number a, Number b, byte dataType) throws ExecException { switch(dataType) { case DataType.DOUBLE: return Double.valueOf((Double) a - (Double) b); case DataType.INTEGER: return Integer.valueOf((Integer) a - (Integer) b); case DataType.LONG: return Long.valueOf((Long) a - (Long) b); case DataType.FLOAT: return Float.valueOf((Float) a - (Float) b); case DataType.BIGINTEGER: return ((BigInteger) a).subtract((BigInteger) b); case DataType.BIGDECIMAL: return ((BigDecimal) a).subtract((BigDecimal) b); default: throw new ExecException("called on unsupported Number class " + DataType.findTypeName(dataType)); } }
Example 4
Source File: TOBAG.java From spork with Apache License 2.0 | 5 votes |
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"); } }
Example 5
Source File: TestPOBinCond.java From spork with Apache License 2.0 | 5 votes |
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; }
Example 6
Source File: MetricUDF.java From datafu with Apache License 2.0 | 5 votes |
/** * Validate the input schema to ensure that our input is consistent and that we fail fast. * @param input input schema * @throws FrontendException */ private void validateInputSchema(Schema input) throws FrontendException { { FieldSchema vectorSchema = input.getField(0); if(!DataTypeUtil.isValidVector(vectorSchema, dim)) { throw new FrontendException("Invalid vector element: Expected either a tuple or a bag, but found " + vectorSchema); } } { FieldSchema distanceSchema = input.getField(1); if(distanceSchema.type != DataType.DOUBLE && distanceSchema.type != DataType.INTEGER && distanceSchema.type != DataType.LONG ) { throw new FrontendException("Invalid distance element: Expected a number, but found " + distanceSchema); } } { FieldSchema pointsSchema = input.getField(2); if( pointsSchema.type != DataType.BAG) { throw new FrontendException("Invalid points element: Expected a bag, but found " + pointsSchema); } FieldSchema tupleInBag = pointsSchema.schema.getField(0); FieldSchema vectorInTuple = tupleInBag.schema.getField(0); if(!DataTypeUtil.isValidVector(vectorInTuple, dim)) { throw new FrontendException("Invalid points element: Expected a bag of vectors, but found " + vectorInTuple.schema); } } }
Example 7
Source File: HBaseStorage.java From spork with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private byte[] objToBytes(Object o, byte type) throws IOException { LoadStoreCaster caster = (LoadStoreCaster) caster_; if (o == null) return null; switch (type) { case DataType.BYTEARRAY: return ((DataByteArray) o).get(); case DataType.BAG: return caster.toBytes((DataBag) o); case DataType.CHARARRAY: return caster.toBytes((String) o); case DataType.DOUBLE: return caster.toBytes((Double) o); case DataType.FLOAT: return caster.toBytes((Float) o); case DataType.INTEGER: return caster.toBytes((Integer) o); case DataType.LONG: return caster.toBytes((Long) o); case DataType.BIGINTEGER: return caster.toBytes((BigInteger) o); case DataType.BIGDECIMAL: return caster.toBytes((BigDecimal) o); case DataType.BOOLEAN: return caster.toBytes((Boolean) o); case DataType.DATETIME: return caster.toBytes((DateTime) o); // The type conversion here is unchecked. // Relying on DataType.findType to do the right thing. case DataType.MAP: return caster.toBytes((Map<String, Object>) o); case DataType.NULL: return null; case DataType.TUPLE: return caster.toBytes((Tuple) o); case DataType.ERROR: throw new IOException("Unable to determine type of " + o.getClass()); default: throw new IOException("Unable to find a converter for tuple field " + o); } }
Example 8
Source File: POIsNull.java From spork with Apache License 2.0 | 5 votes |
@Override public Result getNextBoolean() throws ExecException { Result res = null; switch(operandType) { case DataType.BYTEARRAY: case DataType.DOUBLE: case DataType.INTEGER: case DataType.BIGINTEGER: case DataType.BIGDECIMAL: case DataType.CHARARRAY: case DataType.BOOLEAN: case DataType.LONG: case DataType.FLOAT: case DataType.DATETIME: case DataType.MAP: case DataType.TUPLE: case DataType.BAG: res = expr.getNext(operandType); if(res.returnStatus == POStatus.STATUS_OK) { if (res.result == null) { res.result = true; } else { res.result = false; } illustratorMarkup(null, res.result, (Boolean) res.result ? 0 : 1); } return res; 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); } } }
Example 9
Source File: LTOrEqualToExpr.java From spork with Apache License 2.0 | 5 votes |
@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); } } }
Example 10
Source File: LessThanExpr.java From spork with Apache License 2.0 | 5 votes |
@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); } } }
Example 11
Source File: TezDagBuilder.java From spork with Apache License 2.0 | 4 votes |
private static Class<? extends WritableComparator> getGroupingComparatorForKeyType(byte keyType) throws JobCreationException { switch (keyType) { case DataType.BOOLEAN: return PigGroupingBooleanWritableComparator.class; case DataType.INTEGER: return PigGroupingIntWritableComparator.class; case DataType.BIGINTEGER: return PigGroupingBigIntegerWritableComparator.class; case DataType.BIGDECIMAL: return PigGroupingBigDecimalWritableComparator.class; case DataType.LONG: return PigGroupingLongWritableComparator.class; case DataType.FLOAT: return PigGroupingFloatWritableComparator.class; case DataType.DOUBLE: return PigGroupingDoubleWritableComparator.class; case DataType.DATETIME: return PigGroupingDateTimeWritableComparator.class; case DataType.CHARARRAY: return PigGroupingCharArrayWritableComparator.class; case DataType.BYTEARRAY: return PigGroupingDBAWritableComparator.class; case DataType.MAP: int errCode = 1068; String msg = "Using Map as key not supported."; throw new JobCreationException(msg, errCode, PigException.INPUT); case DataType.TUPLE: return PigGroupingTupleWritableComparator.class; case DataType.BAG: errCode = 1068; msg = "Using Bag as key not supported."; throw new JobCreationException(msg, errCode, PigException.INPUT); default: errCode = 2036; msg = "Unhandled key type " + DataType.findTypeName(keyType); throw new JobCreationException(msg, errCode, PigException.BUG); } }
Example 12
Source File: ISOMonthsBetween.java From spork with Apache License 2.0 | 4 votes |
@Override public Schema outputSchema(Schema input) { return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG)); }
Example 13
Source File: ISOYearsBetween.java From spork with Apache License 2.0 | 4 votes |
@Override public Schema outputSchema(Schema input) { return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG)); }
Example 14
Source File: YearsBetween.java From spork with Apache License 2.0 | 4 votes |
@Override public Schema outputSchema(Schema input) { return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG)); }
Example 15
Source File: ISOMinutesBetween.java From spork with Apache License 2.0 | 4 votes |
@Override public Schema outputSchema(Schema input) { return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG)); }
Example 16
Source File: AugmentBaseDataVisitor.java From spork with Apache License 2.0 | 4 votes |
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; } }
Example 17
Source File: EmpiricalCountEntropy.java From datafu with Apache License 2.0 | 4 votes |
@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))); } Schema tupleSchema = inputBagSchema.getField(0).schema; if(tupleSchema == null) { throw new RuntimeException("The tuple of input bag has no schema"); } List<Schema.FieldSchema> fieldSchemaList = tupleSchema.getFields(); if(fieldSchemaList == null || fieldSchemaList.size() != 1) { throw new RuntimeException("The field schema of the input tuple is null or its size is not 1"); } if(fieldSchemaList.get(0).type != DataType.INTEGER && fieldSchemaList.get(0).type != DataType.LONG ) { String[] expectedTypes = new String[] {DataType.findTypeName(DataType.INTEGER), DataType.findTypeName(DataType.LONG)}; throw new RuntimeException("Expect the type of the input tuple to be of (" + java.util.Arrays.toString(expectedTypes) + "), but instead found " + DataType.findTypeName(fieldSchemaList.get(0).type)); } return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass() .getName() .toLowerCase(), input), DataType.DOUBLE)); } catch (FrontendException e) { throw new RuntimeException(e); } }
Example 18
Source File: TestSchema.java From spork with Apache License 2.0 | 4 votes |
@Test public void testSchemaEqual1() { List<FieldSchema> innerList1 = new ArrayList<FieldSchema>(); innerList1.add(new FieldSchema("11a", DataType.INTEGER)); innerList1.add(new FieldSchema("11b", DataType.LONG)); List<FieldSchema> innerList2 = new ArrayList<FieldSchema>(); innerList2.add(new FieldSchema("11a", DataType.INTEGER)); innerList2.add(new FieldSchema("11b", DataType.LONG)); Schema innerSchema1 = new Schema(innerList1); Schema innerSchema2 = new Schema(innerList2); List<FieldSchema> list1 = new ArrayList<FieldSchema>(); list1.add(new FieldSchema("1a", DataType.BYTEARRAY)); list1.add(new FieldSchema("1b", innerSchema1)); list1.add(new FieldSchema("1c", DataType.INTEGER)); List<FieldSchema> list2 = new ArrayList<FieldSchema>(); list2.add(new FieldSchema("1a", DataType.BYTEARRAY)); list2.add(new FieldSchema("1b", innerSchema2)); list2.add(new FieldSchema("1c", DataType.INTEGER)); Schema schema1 = new Schema(list1); Schema schema2 = new Schema(list2); assertTrue(Schema.equals(schema1, schema2, false, false)); innerList2.get(1).alias = "pi"; assertFalse(Schema.equals(schema1, schema2, false, false)); assertTrue(Schema.equals(schema1, schema2, false, true)); innerList2.get(1).alias = "11b"; innerList2.get(1).type = DataType.BYTEARRAY; assertFalse(Schema.equals(schema1, schema2, false, false)); assertTrue(Schema.equals(schema1, schema2, true, false)); innerList2.get(1).type = DataType.LONG; assertTrue(Schema.equals(schema1, schema2, false, false)); list2.get(0).type = DataType.CHARARRAY; assertFalse(Schema.equals(schema1, schema2, false, false)); }
Example 19
Source File: TypeUtil.java From phoenix with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * This method returns the most appropriate PDataType associated with * the incoming Pig type. Note for Pig DataType DATETIME, returns DATE as * inferredSqlType. * * This is later used to make a cast to targetPhoenixType accordingly. See * {@link #castPigTypeToPhoenix(Object, byte, PDataType)} * * @param obj * @return PDataType */ public static PDataType getType(Object obj, byte type) { if (obj == null) { return null; } PDataType sqlType; switch (type) { case DataType.BYTEARRAY: sqlType = PDataType.VARBINARY; break; case DataType.CHARARRAY: sqlType = PDataType.VARCHAR; break; case DataType.DOUBLE: sqlType = PDataType.DOUBLE; break; case DataType.FLOAT: sqlType = PDataType.FLOAT; break; case DataType.INTEGER: sqlType = PDataType.INTEGER; break; case DataType.LONG: sqlType = PDataType.LONG; break; case DataType.BOOLEAN: sqlType = PDataType.BOOLEAN; break; case DataType.DATETIME: sqlType = PDataType.DATE; break; default: throw new RuntimeException("Unknown type " + obj.getClass().getName() + " passed to PhoenixHBaseStorage"); } return sqlType; }
Example 20
Source File: ToMilliSeconds.java From spork with Apache License 2.0 | 4 votes |
@Override public Schema outputSchema(Schema input) { return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG)); }