use of org.apache.pig.ResourceSchema in project phoenix by apache.
the class PhoenixPigSchemaUtilTest method testSchema.
@Test
public void testSchema() throws SQLException, IOException {
final Configuration configuration = mock(Configuration.class);
when(configuration.get(PhoenixConfigurationUtil.SCHEMA_TYPE)).thenReturn(SchemaType.TABLE.name());
final ResourceSchema actual = PhoenixPigSchemaUtil.getResourceSchema(configuration, new Dependencies() {
List<ColumnInfo> getSelectColumnMetadataList(Configuration configuration) throws SQLException {
return Lists.newArrayList(ID_COLUMN, NAME_COLUMN);
}
});
// expected schema.
final ResourceFieldSchema[] fields = new ResourceFieldSchema[2];
fields[0] = new ResourceFieldSchema().setName("ID").setType(DataType.LONG);
fields[1] = new ResourceFieldSchema().setName("NAME").setType(DataType.CHARARRAY);
final ResourceSchema expected = new ResourceSchema().setFields(fields);
assertEquals(expected.toString(), actual.toString());
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class ResourceSchemaUtil method createResourceFieldSchema.
/**
* Creates a new ResourceFieldSchema which reflects data from an input RequiredField.
*
* @param field
* @return new ResourceFieldSchema which reflects {@code field}.
* @throws IOException
*/
public static ResourceFieldSchema createResourceFieldSchema(RequiredField field) throws IOException {
ResourceFieldSchema schema = new ResourceFieldSchema().setName(field.getAlias()).setType(field.getType());
List<RequiredField> subFields = field.getSubFields();
if (subFields != null && !subFields.isEmpty()) {
ResourceFieldSchema[] subSchemaFields = new ResourceFieldSchema[subFields.size()];
int i = 0;
for (RequiredField subField : subFields) {
subSchemaFields[i++] = createResourceFieldSchema(subField);
}
ResourceSchema subSchema = new ResourceSchema();
subSchema.setFields(subSchemaFields);
schema.setSchema(subSchema);
}
return schema;
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class ThriftWritableConverter method checkStoreSchema.
@Override
public void checkStoreSchema(ResourceFieldSchema schema) throws IOException {
Preconditions.checkNotNull(schema, "Schema is null");
Preconditions.checkArgument(DataType.TUPLE == schema.getType(), "Expected schema type '%s' but found type '%s'", DataType.findTypeName(DataType.TUPLE), DataType.findTypeName(schema.getType()));
ResourceSchema childSchema = schema.getSchema();
Preconditions.checkNotNull(childSchema, "Child schema is null");
Schema actualSchema = Schema.getPigSchema(childSchema);
Preconditions.checkArgument(Schema.equals(expectedSchema, actualSchema, false, true), "Expected store schema '%s' but found schema '%s'", expectedSchema, actualSchema);
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class TestPigToProtobuf method testConvertInvalidTypeMap.
@Test(expected = IllegalArgumentException.class)
public void testConvertInvalidTypeMap() throws Descriptors.DescriptorValidationException {
Schema schema = new Schema();
schema.add(new Schema.FieldSchema("map", DataType.MAP));
PigToProtobuf.schemaToProtoDescriptor(new ResourceSchema(schema));
}
use of org.apache.pig.ResourceSchema in project elephant-bird by twitter.
the class TestPigToProtobuf method testConvertInvalidTypeTuple.
@Test(expected = IllegalArgumentException.class)
public void testConvertInvalidTypeTuple() throws Descriptors.DescriptorValidationException {
Schema schema = new Schema();
schema.add(new Schema.FieldSchema("tuple", DataType.TUPLE));
PigToProtobuf.schemaToProtoDescriptor(new ResourceSchema(schema));
}
Aggregations