@Test public void testFieldOrder() { Partitioning partitioning = Partitioning.builder() .addIntField("1") .addLongField("2") .addStringField("3") .build(); Iterator<Map.Entry<String, FieldType>> iterator = partitioning.getFields().entrySet().iterator(); Assert.assertEquals("1", iterator.next().getKey()); Assert.assertEquals("2", iterator.next().getKey()); Assert.assertEquals("3", iterator.next().getKey()); Assert.assertFalse(iterator.hasNext()); // the previous order may have been preserved by chance. Now try the reverse order partitioning = Partitioning.builder() .addIntField("3") .addLongField("2") .addStringField("1") .build(); iterator = partitioning.getFields().entrySet().iterator(); Assert.assertEquals("3", iterator.next().getKey()); Assert.assertEquals("2", iterator.next().getKey()); Assert.assertEquals("1", iterator.next().getKey()); Assert.assertFalse(iterator.hasNext()); }
private void testIllegalFieldValue(Function<PartitionKey.Builder, PartitionKey.Builder> function) { PartitionKey.Builder builder = PartitionKey.builder( Partitioning.builder().addIntField("x").addLongField("y").addStringField("z").build()); try { function.apply(builder); Assert.fail("builder should have thrown exception for invalid field type"); } catch (IllegalArgumentException e) { //expected } }
@Test public void testBuilderGetters() { Partitioning partitioning = Partitioning.builder() .addField("a", FieldType.STRING) .addField("b", FieldType.INT) .addField("c", FieldType.LONG) .addStringField("d") .addIntField("e") .addLongField("f") .build(); Assert.assertEquals(FieldType.STRING, partitioning.getFieldType("a")); Assert.assertEquals(FieldType.INT, partitioning.getFieldType("b")); Assert.assertEquals(FieldType.LONG, partitioning.getFieldType("c")); Assert.assertEquals(FieldType.STRING, partitioning.getFieldType("d")); Assert.assertEquals(FieldType.INT, partitioning.getFieldType("e")); Assert.assertEquals(FieldType.LONG, partitioning.getFieldType("f")); Assert.assertNull(partitioning.getFieldType("x")); Assert.assertEquals(partitioning.getFields().keySet(), ImmutableSet.of("a", "b", "c", "d", "e", "f")); }
Partitioning.builder().addIntField("i").addStringField("s").build()).build(); DatasetSpecification spec = pfsDef.configure("pfs", props); Partitioning.builder().addStringField("s").build()).build(); try { ((Reconfigurable) pfsDef).reconfigure("pfs", noIprops, spec); Partitioning.builder().addLongField("i").addStringField("s").build()).build(); try { ((Reconfigurable) pfsDef).reconfigure("pfs", longIprops, spec); Partitioning.builder().addStringField("s").addIntField("i").build()).build(); try { ((Reconfigurable) pfsDef).reconfigure("pfs", revProps, spec); .setPartitioning(Partitioning.builder().addStringField("s").build()) .add(PartitionedFileSetDefinition.NAME_AS_BASE_PATH_DEFAULT, "false") .build(); .setPartitioning(Partitioning.builder().addStringField("s").build()) .build(); oldSpec = pfsDef.configure("pfs", props);
@Override public void configure() { try { createDataset("fs", FileSet.class, FileSetProperties.builder() .setInputFormat(MyTextInputFormat.class) .setOutputFormat(MyTextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, ":").build()); createDataset("pfs", PartitionedFileSet.class, PartitionedFileSetProperties.builder() .setPartitioning(Partitioning.builder().addStringField("x").build()) .setInputFormat(MyTextInputFormat.class) .setOutputFormat(TextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, ":").build()); createDataset("tpfs", TimePartitionedFileSet.class, FileSetProperties.builder() .setInputFormat(MyTextInputFormat.class) .setOutputFormat(TextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, ":").build()); createDataset("myfs", MyFileSet.class, FileSetProperties.builder() .setInputFormat(MyTextInputFormat.class) .setOutputFormat(TextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, ":").build()); addSpark(new FileCountSparkProgram()); addSpark(new ScalaFileCountSparkProgram()); } catch (Throwable t) { throw Throwables.propagate(t); } }
@Override public void configure() { setName("AppWithMapReduceUsingFile"); setDescription("Application with MapReduce job using file as dataset"); createDataset(INPUT, "table"); createDataset(OUTPUT, "table"); Class<? extends InputFormat> inputFormatClass = getConfig().isUseCombineFileInputFormat() ? CombineTextInputFormat.class : TextInputFormat.class; createDataset(PARTITIONED, "partitionedFileSet", PartitionedFileSetProperties.builder() .setPartitioning(Partitioning.builder() .addStringField("type") .addLongField("time") .build()) // properties for file set .setBasePath("partitioned") .setInputFormat(inputFormatClass) .setOutputFormat(TextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, SEPARATOR) // don't configure properties for the Hive table - this is used in a context where explore is disabled .build()); addMapReduce(new PartitionWriter()); addMapReduce(new PartitionReader()); }
@Test public void testMultipleTransitiveDependencies() throws DatasetManagementException, IOException { // Adding modules DatasetFramework framework = getFramework(); try { framework.addModule(IN_MEMORY, new InMemoryTableModule()); framework.addModule(CORE, new CoreDatasetsModule()); framework.addModule(FILE, new FileSetModule()); framework.addModule(PFS, new PartitionedFileSetModule()); framework.addModule(TWICE, new SingleTypeModule(EmbedsTableTwiceDataset.class)); // Creating an instances framework.addInstance(EmbedsTableTwiceDataset.class.getName(), MY_DS, PartitionedFileSetProperties.builder() .setPartitioning(Partitioning.builder().addStringField("x").build()) .build()); Assert.assertTrue(framework.hasInstance(MY_DS)); framework.getDataset(MY_DS, DatasetProperties.EMPTY.getProperties(), null); } finally { framework.deleteAllInstances(NAMESPACE_ID); framework.deleteAllModules(NAMESPACE_ID); } }
@Override public void configure() { addService(new PartitionService()); // Create a partitioned file set, configure it to work with MapReduce and with Explore createDataset("pfs", PartitionedFileSet.class, PartitionedFileSetProperties.builder() // Properties for partitioning .setPartitioning(Partitioning.builder().addStringField("partition").addIntField("sub-partition").build()) // Properties for file set .setInputFormat(TextInputFormat.class) .setOutputFormat(TextOutputFormat.class) .setOutputProperty(TextOutputFormat.SEPERATOR, ",") // Properties for Explore (to create a partitioned Hive table) .setEnableExploreOnCreate(true) .setExploreFormat("csv") .setExploreSchema("f1 STRING, f2 INT") .setDescription("App for testing authorization in partitioned filesets.") .build()); }
@Test(expected = IllegalArgumentException.class) public void testBuilderEmptyName() { Partitioning.builder().addStringField("").build(); }
@Test(expected = IllegalArgumentException.class) public void testBuilderDuplicate() { Partitioning.builder() .addField("name", FieldType.STRING) .addIntField("age") .addStringField("name") .build(); }
@Test(expected = IllegalStateException.class) public void testBuilderMissingField() { PartitionKey.builder( Partitioning.builder().addIntField("x").addLongField("y").addStringField("z").build()) .addField("x", 10).addField("y", 10L).build(); }