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


Java DataType.NULL属性代码示例

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


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

示例1: compare

@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,代码行数:21,代码来源:TOP.java

示例2: testProjMixExpand1NoSchema

@Test
public void testProjMixExpand1NoSchema() throws IOException {

    String query;

    query =
        "  l1 = load '" + INP_FILE_5FIELDS + "';"
        + "f = foreach l1 generate TOBAG(*, $0 .. $2) as tt;"
        ; 
    Schema sch = Utils.getSchemaFromString("tt : {(NullALias)}");
    sch.getField(0).schema.getField(0).schema.getField(0).alias = null;
    sch.getField(0).schema.getField(0).schema.getField(0).type = DataType.NULL;
    
    compileAndCompareSchema(sch, query, "f");
    Iterator<Tuple> it = pigServer.openIterator("f");

    List<Tuple> expectedRes = 
        Util.getTuplesFromConstantTupleStringAsByteArray(
                new String[] {
                        "({('10'),('20'),('30'),('40'),('50'),('10'),('20'),('30')})",
                        "({('11'),('21'),('31'),('41'),('51'),('11'),('21'),('31')})",
                });
    Util.checkQueryOutputsAfterSort(it, expectedRes);

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

示例3: getFieldSchema

@Override
public LogicalFieldSchema getFieldSchema() throws FrontendException {
    if (fieldSchema!=null)
        return fieldSchema;
    try {
        fieldSchema =  Util.translateFieldSchema(DataType.determineFieldSchema(val));
    }catch (Exception e) {
        throw new FrontendException(
                "Error determining field schema from object in constant expression",
                1125,
                PigException.INPUT,
                e
        );
    }
    uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
    if (type != DataType.NULL && fieldSchema.type == DataType.BYTEARRAY && val == null) {
        fieldSchema.type = type;
    }
    return fieldSchema;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:20,代码来源:ConstantExpression.java

示例4: compare

@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,代码行数:25,代码来源:TOP.java

示例5: setBytearrayForNULLType

/**
 * For any UNKNOWN type in the schema fields, set the type to BYTEARRAY
 * @param sch
 */
static void setBytearrayForNULLType(LogicalSchema sch){
    for(LogicalFieldSchema fs : sch.getFields()){
        if(fs.type == DataType.NULL){
            fs.type = DataType.BYTEARRAY;
        }
        if(fs.schema != null){
            setBytearrayForNULLType(fs.schema);
        }
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:14,代码来源:LogicalPlanBuilder.java

示例6: setFieldSchemaDefaultType

/**
 * Recursively set NULL type to the specifid type 
 * @param fs the field schema whose NULL type has to be set 
 * @param t the specified type
 */
public static void setFieldSchemaDefaultType(Schema.FieldSchema fs, byte t) {
    if(null == fs) return;
    if(DataType.NULL == fs.type) {
        fs.type = t;
    }
    if(DataType.isSchemaType(fs.type)) {
        setSchemaDefaultType(fs.schema, t);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:14,代码来源:Schema.java

示例7: objToBytes

@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);
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:27,代码来源:HBaseStorage.java

示例8: inheritSchema

public void inheritSchema(LogicalExpression expr) throws FrontendException {
    fieldSchema = expr.getFieldSchema();
    uidOnlyFieldSchema = fieldSchema.mergeUid(uidOnlyFieldSchema);
    if (fieldSchema.type != DataType.NULL) {
        type = fieldSchema.type;
    }
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:7,代码来源:ConstantExpression.java

示例9: fixSchema

public ResourceSchema fixSchema(ResourceSchema s){
  for (ResourceFieldSchema filed : s.getFields()) {
    if(filed.getType() == DataType.NULL)
      filed.setType(DataType.BYTEARRAY);
  }
  return s;
}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:7,代码来源:JsonStorage.java

示例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;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:47,代码来源:VespaQuerySchema.java

示例11: 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());
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:46,代码来源:DataToSketch.java

示例12: 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
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:53,代码来源:DataToSketch.java

示例13: getType

/**
 * Get the data type for this expression.
 * @return data type, one of the static bytes of DataType
 */
public byte getType() throws FrontendException {
    if (getFieldSchema()!=null && getFieldSchema().type!=DataType.NULL)
        return getFieldSchema().type;
    return DataType.BYTEARRAY;
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:9,代码来源:LogicalExpression.java

示例14: getPigType

/**
 * Determines the pig object type of the Avro schema.
 * @param s The avro schema for which to determine the type
 * @return the byte representing the schema type
 * @throws ExecException
 * @see org.apache.avro.Schema.Type
 */
public static byte getPigType(final Schema s) throws ExecException {
  switch (s.getType()) {
  case ARRAY:
    return DataType.BAG;
  case BOOLEAN:
    return DataType.BOOLEAN;
  case BYTES:
    return DataType.BYTEARRAY;
  case DOUBLE:
    return DataType.DOUBLE;
  case ENUM:
    return DataType.CHARARRAY;
  case FIXED:
    return DataType.BYTEARRAY;
  case FLOAT:
    return DataType.FLOAT;
  case INT:
    return DataType.INTEGER;
  case LONG:
    return DataType.LONG;
  case MAP:
    return DataType.MAP;
  case NULL:
    return DataType.NULL;
  case RECORD:
    return DataType.TUPLE;
  case STRING:
    return DataType.CHARARRAY;
  case UNION:
    List<Schema> types = s.getTypes();
    if (types.size() == 1) {
      return getPigType(types.get(0));
    } else if (types.size() == 2 && types.get(0).getType() == Type.NULL) {
        return getPigType(types.get(1));
    } else if (types.size() == 2 && types.get(1).getType() == Type.NULL) {
        return getPigType(types.get(0));
    } else if (isUnionOfSimpleTypes(s)) {
        return DataType.BYTEARRAY;
    }
    throw new ExecException(
        "Currently only supports element unions of a type and null (" + s.toString() +")");
  default:
    throw new ExecException("Unknown type: " + s.getType().toString());
  }
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:52,代码来源:AvroStorageSchemaConversionUtilities.java

示例15: isNullOrUnknownType

private boolean isNullOrUnknownType(FieldSchema fs) {
    return (fs.type == DataType.NULL || fs.type == DataType.UNKNOWN);
}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:3,代码来源:Schema.java


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