use of org.apache.pig.ResourceSchema in project mongo-hadoop by mongodb.
the class MongoUpdateStorage method prepareToWrite.
@Override
public void prepareToWrite(final RecordWriter writer) throws IOException {
// noinspection unchecked
recordWriter = (MongoRecordWriter<?, MongoUpdateWritable>) writer;
LOG.info("Preparing to write to " + recordWriter);
if (recordWriter == null) {
throw new IOException("Invalid Record Writer");
}
UDFContext context = UDFContext.getUDFContext();
Properties p = context.getUDFProperties(getClass(), new String[] { signature });
/*
* In determining the schema to use, the user-defined schema should take
* precedence over the "inferred" schema
*/
if (schemaStr != null) {
try {
schema = new ResourceSchema(Utils.getSchemaFromString(schemaStr));
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
} else {
String s = p.getProperty(SCHEMA_SIGNATURE);
if (s == null) {
throw new IOException("Could not find schema in UDF context. You'd have to explicitly specify a Schema.");
}
schema = new ResourceSchema(Utils.getSchemaFromString(s));
}
}
use of org.apache.pig.ResourceSchema in project mongo-hadoop by mongodb.
the class BSONStorageTest method testNullMap.
@Test
public void testNullMap() throws Exception {
ResourceSchema schema = new ResourceSchema(Utils.getSchemaFromString("m:map[]"));
assertNull(BSONStorage.getTypeForBSON(null, schema.getFields()[0], null));
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class TestPigToProtobuf method testConvertExtraFields.
@Test
public void testConvertExtraFields() throws Descriptors.DescriptorValidationException {
Schema schema = new Schema();
schema.add(new Schema.FieldSchema("chararray", DataType.CHARARRAY));
schema.add(new Schema.FieldSchema("bytearray", DataType.BYTEARRAY));
List<Pair<String, DescriptorProtos.FieldDescriptorProto.Type>> extraFields = new ArrayList<Pair<String, DescriptorProtos.FieldDescriptorProto.Type>>();
extraFields.add(new Pair<String, DescriptorProtos.FieldDescriptorProto.Type>("extra_string", DescriptorProtos.FieldDescriptorProto.Type.TYPE_STRING));
extraFields.add(new Pair<String, DescriptorProtos.FieldDescriptorProto.Type>("extra_int", DescriptorProtos.FieldDescriptorProto.Type.TYPE_INT32));
Descriptors.Descriptor descriptor = PigToProtobuf.schemaToProtoDescriptor(new ResourceSchema(schema), extraFields);
Assert.assertEquals("Incorrect data size", 4, descriptor.getFields().size());
Iterator<Descriptors.FieldDescriptor> fieldIterator = descriptor.getFields().iterator();
assetFieldDescriptor(fieldIterator.next(), "chararray", Descriptors.FieldDescriptor.Type.STRING);
assetFieldDescriptor(fieldIterator.next(), "bytearray", Descriptors.FieldDescriptor.Type.BYTES);
assetFieldDescriptor(fieldIterator.next(), "extra_string", Descriptors.FieldDescriptor.Type.STRING);
assetFieldDescriptor(fieldIterator.next(), "extra_int", Descriptors.FieldDescriptor.Type.INT32);
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class TestPigToProtobuf method testConvertInvalidTypeBag.
@Test(expected = IllegalArgumentException.class)
public void testConvertInvalidTypeBag() throws Descriptors.DescriptorValidationException {
Schema schema = new Schema();
schema.add(new Schema.FieldSchema("bag", DataType.BAG));
PigToProtobuf.schemaToProtoDescriptor(new ResourceSchema(schema));
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class TestThriftToPig method nestedInListTestHelper.
public void nestedInListTestHelper(String s, String expSchema) throws FrontendException {
TypeRef<? extends TBase<?, ?>> typeRef_ = PigUtil.getThriftTypeRef(s);
Schema schema = ThriftToPig.toSchema(typeRef_.getRawClass());
Schema oldSchema = Schema.getPigSchema(new ResourceSchema(schema));
assertTrue(Schema.equals(schema, oldSchema, false, true));
Schema expectedSchema = Utils.getSchemaFromString(expSchema);
assertTrue("expected : " + expSchema + " got " + schema.toString(), Schema.equals(schema, expectedSchema, false, true));
}
Aggregations