HCatalogIO { public static Read read() { return new AutoValue_HCatalogIO_Read.Builder() .setDatabase(DEFAULT_DATABASE) .setPartitionCols(new ArrayList<>()) .build(); } private  HCatalogIO(); static Write write(); static Read read();  }
@Test public void testReadFailureTableDoesNotExist() { defaultPipeline.apply( HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withTable("myowntable")); thrown.expectCause(isA(NoSuchObjectException.class)); defaultPipeline.run(); }
@Test public void testReadFailureValidationConfig() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("withConfigProperties() is required"); HCatalogIO.read().withTable("myowntable").expand(null); }
@Test public void testReadFailureValidationTable() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("withTable() is required"); HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .expand(null); }
@Test public void testReadTransformCanBeSerializedMultipleTimes() throws Exception { ReaderContext context = getReaderContext(getConfigPropertiesAsMap(service.getHiveConf())); HCatalogIO.Read spec = HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withContext(context) .withTable(TEST_TABLE); SerializableUtils.clone(SerializableUtils.clone(spec)); }
@Test public void testSourceCanBeSerializedMultipleTimes() throws Exception { ReaderContext context = getReaderContext(getConfigPropertiesAsMap(service.getHiveConf())); HCatalogIO.Read spec = HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withContext(context) .withTable(TEST_TABLE); BoundedHCatalogSource source = new BoundedHCatalogSource(spec); SerializableUtils.clone(SerializableUtils.clone(source)); }
@Test @NeedsTestData public void testReadFromSource() throws Exception { ReaderContext context = getReaderContext(getConfigPropertiesAsMap(service.getHiveConf())); HCatalogIO.Read spec = HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withContext(context) .withTable(TEST_TABLE); List<String> records = new ArrayList<>(); for (int i = 0; i < context.numSplits(); i++) { BoundedHCatalogSource source = new BoundedHCatalogSource(spec.withSplitId(i)); for (HCatRecord record : SourceTestUtils.readFromSource(source, OPTIONS)) { records.add(record.get(0).toString()); } } assertThat(records, containsInAnyOrder(getExpectedRecords(TEST_RECORDS_COUNT).toArray())); }
@Test @NeedsTestData public void testSourceEqualsSplits() throws Exception { final int numRows = 1500; final int numSamples = 10; final long bytesPerRow = 15; ReaderContext context = getReaderContext(getConfigPropertiesAsMap(service.getHiveConf())); HCatalogIO.Read spec = HCatalogIO.read() .withConfigProperties(getConfigPropertiesAsMap(service.getHiveConf())) .withContext(context) .withTable(TEST_TABLE); BoundedHCatalogSource source = new BoundedHCatalogSource(spec); List<BoundedSource<HCatRecord>> unSplitSource = source.split(-1, OPTIONS); assertEquals(1, unSplitSource.size()); List<BoundedSource<HCatRecord>> splits = source.split(numRows * bytesPerRow / numSamples, OPTIONS); assertTrue(splits.size() >= 1); SourceTestUtils.assertSourcesEqualReferenceSource(unSplitSource.get(0), splits, OPTIONS); }