Search in sources :

Example 11 with DatasetDefinition

use of co.cask.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class PrefixedTable method register.

@Override
public void register(DatasetDefinitionRegistry registry) {
    DatasetDefinition<KeyValueTable, DatasetAdmin> kvTableDef = registry.get("keyValueTable");
    DatasetDefinition definition = new PrefixedTableDefinition("prefixedTable", kvTableDef);
    registry.add(definition);
}
Also used : DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition)

Example 12 with DatasetDefinition

use of co.cask.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class DatasetDefinitionRegistryWithDefaultModules method testPFSReconfigure.

@Test
public void testPFSReconfigure() throws IncompatibleUpdateException {
    DatasetDefinition pfsDef = registry.get(PartitionedFileSet.class.getName());
    Assert.assertTrue(pfsDef instanceof Reconfigurable);
    DatasetProperties props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addIntField("i").addStringField("s").build()).build();
    DatasetSpecification spec = pfsDef.configure("pfs", props);
    DatasetProperties noIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", noIprops, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    DatasetProperties longIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addLongField("i").addStringField("s").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", longIprops, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    DatasetProperties revProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").addIntField("i").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", revProps, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    // test reconfiguring a PFS created before CDAP-13120, with no defaulted base path
    // no base path should be set for the reconfigured dataset either
    DatasetProperties oldProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).add(PartitionedFileSetDefinition.NAME_AS_BASE_PATH_DEFAULT, "false").build();
    DatasetSpecification oldSpec = pfsDef.configure("pfs", oldProps);
    DatasetSpecification newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", oldProps, oldSpec);
    // make sure base path is not set
    Assert.assertNull(newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
    // test reconfiguring a PFS created after CDAP-13120, where base path is default to the dataset name
    props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
    oldSpec = pfsDef.configure("pfs", props);
    newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
    // make sure base path is similarly set, even when not explicitly given
    Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
    // make sure it is set for subsequent reconfigures as well
    newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
    // make sure base path is similarly set, even when not explicitly given
    Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition) Reconfigurable(co.cask.cdap.api.dataset.Reconfigurable) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Example 13 with DatasetDefinition

use of co.cask.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class DatasetDefinitionRegistryWithDefaultModules method testIndexedTableReconfigure.

@Test
public void testIndexedTableReconfigure() throws IncompatibleUpdateException {
    DatasetDefinition indexedTableDef = registry.get(IndexedTable.class.getName());
    Assert.assertTrue(indexedTableDef instanceof Reconfigurable);
    DatasetProperties props = TableProperties.builder().setReadlessIncrementSupport(false).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,b,c").build();
    DatasetSpecification spec = indexedTableDef.configure("idxtb", props);
    DatasetProperties compat = TableProperties.builder().setReadlessIncrementSupport(// turning on is ok
    true).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "c,b,a").build();
    spec = ((Reconfigurable) indexedTableDef).reconfigure("idxtb", compat, spec);
    DatasetProperties incompat = TableProperties.builder().setReadlessIncrementSupport(true).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,d").build();
    try {
        ((Reconfigurable) indexedTableDef).reconfigure("idxtb", incompat, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    incompat = TableProperties.builder().setReadlessIncrementSupport(// turning off is not ok
    false).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,b,c").build();
    try {
        ((Reconfigurable) indexedTableDef).reconfigure("idxtb", incompat, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
}
Also used : DatasetProperties(co.cask.cdap.api.dataset.DatasetProperties) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition) Reconfigurable(co.cask.cdap.api.dataset.Reconfigurable) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Aggregations

DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)13 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)11 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)7 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)5 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)3 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)3 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)2 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)2 Reconfigurable (co.cask.cdap.api.dataset.Reconfigurable)2 Nullable (javax.annotation.Nullable)2 Test (org.junit.Test)2 Dataset (co.cask.cdap.api.dataset.Dataset)1 DatasetContext (co.cask.cdap.api.dataset.DatasetContext)1 Updatable (co.cask.cdap.api.dataset.Updatable)1 CompositeDatasetDefinition (co.cask.cdap.api.dataset.lib.CompositeDatasetDefinition)1 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)1 DatasetType (co.cask.cdap.api.dataset.module.DatasetType)1 EmbeddedDataset (co.cask.cdap.api.dataset.module.EmbeddedDataset)1 IOException (java.io.IOException)1