Search in sources :

Example 1 with Dependencies

use of org.apache.phoenix.pig.util.PhoenixPigSchemaUtil.Dependencies 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());
}
Also used : ResourceSchema(org.apache.pig.ResourceSchema) Configuration(org.apache.hadoop.conf.Configuration) SQLException(java.sql.SQLException) ResourceFieldSchema(org.apache.pig.ResourceSchema.ResourceFieldSchema) List(java.util.List) Dependencies(org.apache.phoenix.pig.util.PhoenixPigSchemaUtil.Dependencies) Test(org.junit.Test)

Example 2 with Dependencies

use of org.apache.phoenix.pig.util.PhoenixPigSchemaUtil.Dependencies in project phoenix by apache.

the class PhoenixPigSchemaUtilTest method testUnSupportedTypes.

@Test(expected = IllegalDataException.class)
public void testUnSupportedTypes() throws SQLException, IOException {
    final Configuration configuration = mock(Configuration.class);
    when(configuration.get(PhoenixConfigurationUtil.SCHEMA_TYPE)).thenReturn(SchemaType.TABLE.name());
    PhoenixPigSchemaUtil.getResourceSchema(configuration, new Dependencies() {

        List<ColumnInfo> getSelectColumnMetadataList(Configuration configuration) throws SQLException {
            return Lists.newArrayList(ID_COLUMN, LOCATION_COLUMN);
        }
    });
    fail("We currently don't support Array type yet. WIP!!");
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SQLException(java.sql.SQLException) List(java.util.List) Dependencies(org.apache.phoenix.pig.util.PhoenixPigSchemaUtil.Dependencies) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)2 List (java.util.List)2 Configuration (org.apache.hadoop.conf.Configuration)2 Dependencies (org.apache.phoenix.pig.util.PhoenixPigSchemaUtil.Dependencies)2 Test (org.junit.Test)2 ResourceSchema (org.apache.pig.ResourceSchema)1 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)1