Search in sources :

Example 26 with ResourceSchema

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));
    }
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) MongoUpdateWritable(com.mongodb.hadoop.io.MongoUpdateWritable) UDFContext(org.apache.pig.impl.util.UDFContext) IOException(java.io.IOException) Properties(java.util.Properties) IOException(java.io.IOException)

Example 27 with ResourceSchema

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));
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) Test(org.junit.Test)

Example 28 with ResourceSchema

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);
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) ResourceSchema(org.apache.pig.ResourceSchema) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) ArrayList(java.util.ArrayList) DescriptorProtos(com.google.protobuf.DescriptorProtos) PhoneType(com.twitter.data.proto.tutorial.AddressBookProtos.Person.PhoneType) DataType(org.apache.pig.data.DataType) Descriptors(com.google.protobuf.Descriptors) Pair(org.apache.pig.impl.util.Pair) Test(org.junit.Test)

Example 29 with ResourceSchema

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));
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) ResourceSchema(org.apache.pig.ResourceSchema) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) Test(org.junit.Test)

Example 30 with ResourceSchema

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));
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) Schema(org.apache.pig.impl.logicalLayer.schema.Schema) ResourceSchema(org.apache.pig.ResourceSchema)

Aggregations

ResourceSchema (org.apache.pig.ResourceSchema)35 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)20 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)11 Test (org.junit.Test)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)6 HCatFieldSchema (org.apache.hive.hcatalog.data.schema.HCatFieldSchema)6 Properties (java.util.Properties)5 FieldSchema (org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema)4 UDFContext (org.apache.pig.impl.util.UDFContext)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 HCatSchema (org.apache.hive.hcatalog.data.schema.HCatSchema)3 Tuple (org.apache.pig.data.Tuple)3 Descriptors (com.google.protobuf.Descriptors)2 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)2 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 Field (org.apache.avro.Schema.Field)2