@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { String columnNamesToIndex = properties.getProperties().get(IndexedTable.INDEX_COLUMNS_CONF_KEY); if (columnNamesToIndex == null) { throw new IllegalArgumentException("columnsToIndex must be specified"); } return super.configure(instanceName, properties); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { return super.reconfigure(instanceName, noConflictDetection(newProperties), currentSpec); }
@Override public final DatasetAdmin getAdmin(DatasetContext datasetContext, DatasetSpecification spec, ClassLoader classLoader) throws IOException { if (1 == delegates.size()) { // for a single delegate, we don't need a composite admin return getAdmin(datasetContext, delegates.keySet().iterator().next(), spec, classLoader); } Map<String, DatasetAdmin> admins = new HashMap<>(); for (String name : this.delegates.keySet()) { admins.put(name, getAdmin(datasetContext, name, spec, classLoader)); } return new CompositeDatasetAdmin(admins); }
@Test public void testCompositeDatasetReconfigure() throws IncompatibleUpdateException { CompositeDatasetDefinition composite = new CompositeDatasetDefinition( "composite", "pedantic", new PedanticDatasetDefinition("pedantic")) { @Override public Dataset getDataset(DatasetContext datasetContext, DatasetSpecification spec, Map arguments, ClassLoader classLoader) throws IOException { return null; } }; DatasetSpecification spec = composite.configure("nn", DatasetProperties.EMPTY); DatasetSpecification respec = composite.reconfigure("nn", DatasetProperties.EMPTY, spec); Assert.assertEquals(spec, respec); try { composite.reconfigure("nn", DatasetProperties.builder().add("immutable", "x").build(), spec); Assert.fail("reconfigure should have thrown exception"); } catch (IncompatibleUpdateException e) { // expected } }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { List<DatasetSpecification> specs = new ArrayList<>(); for (Map.Entry<String, ? extends DatasetDefinition> impl : this.delegates.entrySet()) { specs.add(reconfigure(impl.getValue(), impl.getKey(), newProperties, currentSpec.getSpecification(impl.getKey()))); } return DatasetSpecification.builder(instanceName, getName()) .properties(newProperties.getProperties()) .datasets(specs) .build(); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { TableProperties.Builder tableProps = TableProperties.builder(); tableProps.addAll(properties.getProperties()); tableProps.setConflictDetection(ConflictDetection.COLUMN); Preconditions.checkNotNull(properties.getProperties().get(Constants.Scheduler.JOB_QUEUE_NUM_PARTITIONS), "Property '{}' must be given when creating job queue dataset", Constants.Scheduler.JOB_QUEUE_NUM_PARTITIONS); DatasetSpecification tableSpec = super.getDelegate(JobQueueDataset.EMBEDDED_TABLE_NAME).configure( JobQueueDataset.EMBEDDED_TABLE_NAME, tableProps.build()); return DatasetSpecification.builder(instanceName, getName()) .properties(properties.getProperties()) .datasets(Collections.singletonList(tableSpec)) .build(); }
/** * Constructor that takes two underlying datasets. * @param name this dataset type name * @param delegateNameA name of the first delegate * @param delegateA dataset definition for the first delegate * @param delegateNameB name of the second delegate * @param delegateB dataset definition for the second delegate */ protected CompositeDatasetDefinition(String name, String delegateNameA, DatasetDefinition delegateA, String delegateNameB, DatasetDefinition delegateB) { this(name, makeMap(delegateNameA, delegateA, delegateNameB, delegateB)); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { List<DatasetSpecification> specs = this.delegates.entrySet().stream() .map(impl -> impl.getValue().configure(impl.getKey(), properties)) .collect(Collectors.toList()); return DatasetSpecification.builder(instanceName, getName()) .properties(properties.getProperties()) .datasets(specs) .build(); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { TableProperties.Builder tableProps = TableProperties.builder(); tableProps.addAll(properties.getProperties()); tableProps.setConflictDetection(ConflictDetection.COLUMN); Preconditions.checkNotNull(properties.getProperties().get(Constants.Scheduler.JOB_QUEUE_NUM_PARTITIONS), "Property '{}' must be given when creating job queue dataset", Constants.Scheduler.JOB_QUEUE_NUM_PARTITIONS); DatasetSpecification tableSpec = super.getDelegate(JobQueueDataset.EMBEDDED_TABLE_NAME).configure( JobQueueDataset.EMBEDDED_TABLE_NAME, tableProps.build()); return DatasetSpecification.builder(instanceName, getName()) .properties(properties.getProperties()) .datasets(Collections.singletonList(tableSpec)) .build(); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { // TODO (CDAP-6268): validate schema compatibility return super.reconfigure(instanceName, configureSchema(newProperties), currentSpec); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { return super.configure(instanceName, configureSchema(properties)); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { TimeseriesTableDefinition.validateNewIntervalSize(newProperties, currentSpec); return super.reconfigure(instanceName, newProperties, currentSpec); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { return super.configure(instanceName, noConflictDetection(properties)); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { validateNewIntervalSize(newProperties, currentSpec); return super.reconfigure(instanceName, newProperties, currentSpec); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { return super.configure(instanceName, configureSchema(properties)); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { return super.reconfigure(instanceName, noConflictDetection(newProperties), currentSpec); }
@Override public DatasetSpecification configure(String instanceName, DatasetProperties properties) { return super.configure(instanceName, noConflictDetection(properties)); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { // TODO (CDAP-6268): validate schema compatibility return super.reconfigure(instanceName, configureSchema(newProperties), currentSpec); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { // validate that the columns to index property is not null and the same as before String columnNamesToIndex = newProperties.getProperties().get(IndexedTable.INDEX_COLUMNS_CONF_KEY); if (columnNamesToIndex == null) { throw new IllegalArgumentException("columnsToIndex must be specified"); } String oldColumnsToIndex = currentSpec.getProperty(IndexedTable.INDEX_COLUMNS_CONF_KEY); if (!columnNamesToIndex.equals(oldColumnsToIndex)) { Set<byte[]> newColumns = parseColumns(columnNamesToIndex); Set<byte[]> oldColumns = parseColumns(oldColumnsToIndex); if (!newColumns.equals(oldColumns)) { throw new IncompatibleUpdateException(String.format("Attempt to change columns to index from '%s' to '%s'", oldColumnsToIndex, columnNamesToIndex)); } } return super.reconfigure(instanceName, newProperties, currentSpec); }
@Override public DatasetSpecification reconfigure(String instanceName, DatasetProperties newProperties, DatasetSpecification currentSpec) throws IncompatibleUpdateException { String currentValue = currentSpec.getProperty("immutable"); String newValue = newProperties.getProperties().get("immutable"); if (!Objects.equals(currentValue, newValue)) { throw new IncompatibleUpdateException(String.format("Cannot change property 'immutable' from %s to %s", currentValue, newValue)); } return super.reconfigure(instanceName, newProperties, currentSpec); }