Java Code Examples for org.apache.pig.data.DataType#findTypeName()

The following examples show how to use org.apache.pig.data.DataType#findTypeName() . 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: Over.java    From spork with Apache License 2.0 6 votes vote down vote up
Lag(Object[] args) throws IOException {
    rowsBehind = 1;
    deflt = null;
    if (args != null) {
        if (args.length >= 1) {
            try {
                rowsBehind = (Integer)args[0];
            } catch (ClassCastException cce) {
                int errCode = 2107; // TODO not sure this is the right one
                String msg = "Lag expected an integer for arg 2 " +
                    " but received " + DataType.findTypeName(args[0]);
                throw new ExecException(msg, errCode, PigException.INPUT);
            }
        }
        if (args.length >= 2) {
            deflt = args[1];
        }
    }
    reset();
}
 
Example 2
Source File: TypeCheckingExpVisitor.java    From spork with Apache License 2.0 6 votes vote down vote up
private String generateIncompatibleTypesMessage(BinaryExpression binOp)
throws FrontendException {
    String msg = binOp.toString();
    if (currentRelOp.getAlias()!=null){
        msg = "In alias " + currentRelOp.getAlias() + ", ";
    }
    LogicalFieldSchema lhsFs = binOp.getLhs().getFieldSchema();
    LogicalFieldSchema rhsFs = binOp.getRhs().getFieldSchema();

    msg = msg + "incompatible types in " + binOp.getName() + " Operator"
    + " left hand side:" + DataType.findTypeName(lhsFs.type)
    + (lhsFs.schema == null ? "" : " " + lhsFs.schema.toString(false) + " ")
    + " right hand side:" + DataType.findTypeName(rhsFs.type)
    + (rhsFs.schema == null ? "" : " " + rhsFs.schema.toString(false) + " ") ;
    return msg;
}
 
Example 3
Source File: Add.java    From spork with Apache License 2.0 6 votes vote down vote up
protected Number add(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).add((BigInteger) b);
    case DataType.BIGDECIMAL:
        return ((BigDecimal) a).add((BigDecimal) b);
    default:
        throw new ExecException("called on unsupported Number class " + DataType.findTypeName(dataType));
    }
}
 
Example 4
Source File: IsEmpty.java    From spork with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean exec(Tuple input) throws IOException {
    try {
        Object values = input.get(0);
        if (values instanceof DataBag)
            return ((DataBag)values).size() == 0;
        else if (values instanceof Map)
            return ((Map)values).size() == 0;
        else {
            int errCode = 2102;
            String msg = "Cannot test a " +
            DataType.findTypeName(values) + " for emptiness.";
            throw new ExecException(msg, errCode, PigException.BUG);
        }
    } catch (ExecException ee) {
        throw ee;
    }
}
 
Example 5
Source File: EmptyBagToNullFields.java    From datafu with Apache License 2.0 6 votes vote down vote up
@Override
public Schema outputSchema(Schema input)
{
  try
  {
    if (input.size() != 1)
    {
      throw new RuntimeException("Expected only a single field as input");
    }
    
    if (input.getField(0).type != DataType.BAG)
    {
      throw new RuntimeException("Expected a BAG as input, but found " + DataType.findTypeName(input.getField(0).type));
    }
    
    // get the size of the tuple within the bag
    int innerTupleSize = input.getField(0).schema.getField(0).schema.getFields().size();
    getInstanceProperties().put("tuplesize", innerTupleSize);
  }
  catch (FrontendException e)
  {
    throw new RuntimeException(e);
  }
  return input;
}
 
Example 6
Source File: POLocalRearrange.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public String name() {
    return getAliasString() + "Local Rearrange" + "["
            + DataType.findTypeName(resultType) + "]" + "{"
            + DataType.findTypeName(keyType) + "}" + "(" + mIsDistinct
            + ") - " + mKey.toString();
}
 
Example 7
Source File: EqualToExpr.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public Result getNextBoolean() throws ExecException {
  try {
    Result left, right;

    switch (operandType) {
    case DataType.BYTEARRAY:
    case DataType.DOUBLE:
    case DataType.FLOAT:
    case DataType.BOOLEAN:
    case DataType.INTEGER:
    case DataType.BIGINTEGER:
    case DataType.BIGDECIMAL:
    case DataType.LONG:
    case DataType.DATETIME:
    case DataType.CHARARRAY:
    case DataType.TUPLE:
    case DataType.MAP: {
        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);
    }

    }
  } catch (RuntimeException e) {
      throw new ExecException("exception while executing " + this.toString() + ": " + e.toString(), 2067, PigException.BUG, e);
  }
}
 
Example 8
Source File: LogicalSchema.java    From spork with Apache License 2.0 5 votes vote down vote up
public String toString(boolean verbose) {
    String uidString = "";
    if (verbose)
        uidString="#" + uid;
    
    String aliasToPrint = "";
    if (alias!=null)
        aliasToPrint = alias;
    
    if( type == DataType.BAG ) {
        if( schema == null ) {
            return ( aliasToPrint + uidString + ":bag{}" );
        }
        return ( aliasToPrint + uidString + ":bag{" + schema.toString(verbose) + "}" );
    } else if( type == DataType.TUPLE ) {
        if( schema == null ) {
            return ( aliasToPrint + uidString + ":tuple()" );
        }
        return ( aliasToPrint + uidString + ":tuple(" + schema.toString(verbose) + ")" );
    } else if (type == DataType.MAP) {
        if (schema == null ) {
            return (aliasToPrint + uidString + ":map");
        } else {
            return (aliasToPrint + uidString + ":map(" + schema.toString(verbose) + ")");
        }
    }
    return ( aliasToPrint + uidString + ":" + DataType.findTypeName(type) );
}
 
Example 9
Source File: POPartitionRearrangeTez.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public String name() {
    return getAliasString() + "Partition Rearrange" + "["
            + DataType.findTypeName(resultType) + "]" + "{"
            + DataType.findTypeName(keyType) + "}" + "(" + mIsDistinct
            + ") - " + mKey.toString() + "\t->\t " + outputKey;
}
 
Example 10
Source File: AlgebraicByteArrayMathBase.java    From spork with Apache License 2.0 5 votes vote down vote up
protected static Double doTupleWork(Tuple input, KnownOpProvider opProvider, byte expectedType)
        throws ExecException {
    DataBag values = (DataBag)input.get(0);
    // if we were handed an empty bag, return NULL
    // this is in compliance with SQL standard
    if(values.size() == 0) {
        return null;
    }
    double sofar = AlgebraicByteArrayMathBase.getSeed(opProvider.getOp());
    boolean sawNonNull = false;
    for (Iterator<Tuple> it = values.iterator(); it.hasNext();) {
        Tuple t = it.next();
        try {
            Double d;
            switch (expectedType) {
            case DataType.BYTEARRAY:
                DataByteArray dba = (DataByteArray)t.get(0);
                d = dba != null ? Double.valueOf(dba.toString()): null;
                break;
            case DataType.DOUBLE:
                d = (Double) t.get(0);
                break;
            default:
                throw new ExecException("Unexpected type in AlgebraicByteArrayMath "
                        + DataType.findTypeName(expectedType));
            }
            if (d == null) continue;
            sawNonNull = true;
            sofar = doWork(sofar, d, opProvider.getOp());
        }catch(RuntimeException exp) {
            int errCode = 2103;
            throw new ExecException("Problem doing work on Doubles", errCode, PigException.BUG, exp);
        }
    }
    return sawNonNull ? sofar : null;
}
 
Example 11
Source File: POPackage.java    From spork with Apache License 2.0 5 votes vote down vote up
@Override
public String name() {
    return getAliasString() + "Package" + "(" + pkgr.name() + ")" + "["
            + DataType.findTypeName(resultType) + "]" + "{"
            + DataType.findTypeName(pkgr.getKeyType()) + "}" + " - "
            + mKey.toString();
}
 
Example 12
Source File: PONot.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    return "Not" + "[" + DataType.findTypeName(resultType) + "]" +" - " + mKey.toString();
}
 
Example 13
Source File: PORelationToExprProject.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    
    return "RelationToExpressionProject" + "[" + DataType.findTypeName(resultType) + "]" + ((isStar()) ? "[*]" : columns) + " - " + mKey.toString();
}
 
Example 14
Source File: PODistinct.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    return getAliasString() + "PODistinct" + "["
            + DataType.findTypeName(resultType) + "]" + " - "
            + mKey.toString();
}
 
Example 15
Source File: TezDagBuilder.java    From spork with Apache License 2.0 4 votes vote down vote up
private static Class<? extends WritableComparator> comparatorForKeyType(byte keyType, boolean hasOrderBy)
        throws JobCreationException {

    switch (keyType) {
    case DataType.BOOLEAN:
        return PigBooleanRawComparator.class;

    case DataType.INTEGER:
        return PigIntRawComparator.class;

    case DataType.BIGINTEGER:
        return PigBigIntegerRawComparator.class;

    case DataType.BIGDECIMAL:
        return PigBigDecimalRawComparator.class;

    case DataType.LONG:
        return PigLongRawComparator.class;

    case DataType.FLOAT:
        return PigFloatRawComparator.class;

    case DataType.DOUBLE:
        return PigDoubleRawComparator.class;

    case DataType.DATETIME:
        return PigDateTimeRawComparator.class;

    case DataType.CHARARRAY:
        return PigTextRawComparator.class;

    case DataType.BYTEARRAY:
        //if (hasOrderBy) {
            return PigBytesRawComparator.class;
        //} else {
        //    return PigDBAWritableComparator.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:
        //TODO: PigTupleWritableComparator gives wrong results with cogroup in
        //Checkin_2 and few other e2e tests. But MR has PigTupleWritableComparator
        //Investigate the difference later
        //if (hasOrderBy) {
            return PigTupleSortComparator.class;
        //} else {
        //    return PigTupleWritableComparator.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 16
Source File: PORank.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    return getAliasString() + "PORank" + "["
    + DataType.findTypeName(resultType) + "]" + " - "
    + mKey.toString();
}
 
Example 17
Source File: POOptimizedForEach.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    String fString = getFlatStr();
    return "Optimized For Each" + "(" + fString + ")" + "[" + DataType.findTypeName(resultType) + "]" +" - " + mKey.toString();
}
 
Example 18
Source File: TypeCheckingExpVisitor.java    From spork with Apache License 2.0 4 votes vote down vote up
/***
 * Helper for collecting warning when casting is inserted
 * to the plan (implicit casting)
 *
 * @param node
 * @param originalType
 * @param toType
 */
static void collectCastWarning(Operator node,
        byte originalType,
        byte toType,
        CompilationMessageCollector msgCollector
) {
    String originalTypeName = DataType.findTypeName(originalType) ;
    String toTypeName = DataType.findTypeName(toType) ;
    String opName= node.getClass().getSimpleName() ;
    PigWarning kind = null;
    switch(toType) {
    case DataType.BAG:
        kind = PigWarning.IMPLICIT_CAST_TO_BAG;
        break;
    case DataType.CHARARRAY:
        kind = PigWarning.IMPLICIT_CAST_TO_CHARARRAY;
        break;
    case DataType.DOUBLE:
        kind = PigWarning.IMPLICIT_CAST_TO_DOUBLE;
        break;
    case DataType.FLOAT:
        kind = PigWarning.IMPLICIT_CAST_TO_FLOAT;
        break;
    case DataType.INTEGER:
        kind = PigWarning.IMPLICIT_CAST_TO_INT;
        break;
    case DataType.LONG:
        kind = PigWarning.IMPLICIT_CAST_TO_LONG;
        break;
    case DataType.BOOLEAN:
        kind = PigWarning.IMPLICIT_CAST_TO_BOOLEAN;
        break;
    case DataType.DATETIME:
        kind = PigWarning.IMPLICIT_CAST_TO_DATETIME;
        break;
    case DataType.MAP:
        kind = PigWarning.IMPLICIT_CAST_TO_MAP;
        break;
    case DataType.TUPLE:
        kind = PigWarning.IMPLICIT_CAST_TO_TUPLE;
        break;
    case DataType.BIGINTEGER:
        kind = PigWarning.IMPLICIT_CAST_TO_BIGINTEGER;
        break;
    case DataType.BIGDECIMAL:
        kind = PigWarning.IMPLICIT_CAST_TO_BIGDECIMAL;
        break;
    }
    msgCollector.collect(originalTypeName + " is implicitly cast to "
            + toTypeName +" under " + opName + " Operator",
            MessageType.Warning, kind) ;
}
 
Example 19
Source File: WeightedReservoirSample.java    From datafu with Apache License 2.0 4 votes vote down vote up
@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() <= Math.max(0, this.weightIdx)) {
        throw new RuntimeException("The field schema of the input tuple is null " +
        		                   "or the tuple size is no more than the weight field index: "
                                   + this.weightIdx);
    }
    
    if(fieldSchemaList.get(this.weightIdx).type != DataType.INTEGER &&
       fieldSchemaList.get(this.weightIdx).type != DataType.LONG &&
       fieldSchemaList.get(this.weightIdx).type != DataType.FLOAT &&
       fieldSchemaList.get(this.weightIdx).type != DataType.DOUBLE)
    {
        String[] expectedTypes = new String[] {DataType.findTypeName(DataType.INTEGER),
                                               DataType.findTypeName(DataType.LONG),
                                               DataType.findTypeName(DataType.FLOAT),
                                               DataType.findTypeName(DataType.DOUBLE)};
        throw new RuntimeException("Expect the type of the weight field of the input tuple to be of (" +
                java.util.Arrays.toString(expectedTypes) + "), but instead found (" + 
                DataType.findTypeName(fieldSchemaList.get(this.weightIdx).type) + "), weight field: " + 
                this.weightIdx);
    } 
    
    return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input),
                                             inputFieldSchema.schema, DataType.BAG));    
  } catch (FrontendException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
}
 
Example 20
Source File: GreaterThanExpr.java    From spork with Apache License 2.0 4 votes vote down vote up
@Override
public String name() {
    return "Greater Than" + "[" + DataType.findTypeName(resultType) + "]" +" - " + mKey.toString();
}