use of io.cdap.cdap.spi.data.table.StructuredTableSpecification in project cdap by caskdata.
the class FieldValidatorTest method init.
@BeforeClass
public static void init() {
StructuredTableSpecification spec = new StructuredTableSpecification.Builder().withId(SIMPLE_TABLE).withFields(Fields.intType(KEY), Fields.longType(KEY2), Fields.stringType(KEY3), Fields.stringType(STRING_COL)).withPrimaryKeys(KEY, KEY2, KEY3).build();
schema = new StructuredTableSchema(spec);
}
use of io.cdap.cdap.spi.data.table.StructuredTableSpecification in project cdap by caskdata.
the class DefaultAppConfigurer method addSystemTableSpecs.
private void addSystemTableSpecs(Collection<StructuredTableSpecification> specs) {
for (StructuredTableSpecification spec : specs) {
StructuredTableSpecification existing = systemTables.get(spec.getTableId());
if (existing != null && !existing.equals(spec)) {
throw new IllegalArgumentException(String.format("System table '%s' was created more than once with different specifications.", spec.getTableId().getName()));
}
systemTables.put(spec.getTableId(), spec);
}
}
use of io.cdap.cdap.spi.data.table.StructuredTableSpecification in project cdap by caskdata.
the class SqlStructuredTableRegistry method createRegistryTable.
private void createRegistryTable() throws IOException {
// Use a no-op registry to create PostgresSqlStructuredTableAdmin.
// During a table creation, except for registerSpecification and getSpecification, no other methods on the
// registry will be called by PostgresSqlStructuredTableAdmin. Since we always check existence before we create
// the registry table, we can safely return null for the getSpecification method.
StructuredTableRegistry noOpRegistry = new StructuredTableRegistry() {
final UnsupportedOperationException exception = new UnsupportedOperationException("Not expected to be called during creation of registry!");
@Override
public void registerSpecification(StructuredTableSpecification specification) {
// Do nothing
}
@Nullable
@Override
public StructuredTableSpecification getSpecification(StructuredTableId tableId) {
return null;
}
@Override
public void removeSpecification(StructuredTableId tableId) {
throw exception;
}
@Override
public boolean isEmpty() {
throw exception;
}
};
try {
// Create the table if needed
PostgreSqlStructuredTableAdmin admin = new PostgreSqlStructuredTableAdmin(noOpRegistry, dataSource);
if (!admin.tableExists(REGISTRY)) {
LOG.info("Creating SQL table {}", REGISTRY);
admin.create(SPEC);
}
} catch (TableAlreadyExistsException e) {
// Looks like the table was created concurrently by some other process
LOG.debug(String.format("Got exception when trying to create table %s", REGISTRY), e);
}
}
Aggregations