Search in sources :

Example 1 with StructuredTableSpecification

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);
}
Also used : StructuredTableSchema(io.cdap.cdap.spi.data.table.StructuredTableSchema) StructuredTableSpecification(io.cdap.cdap.spi.data.table.StructuredTableSpecification) BeforeClass(org.junit.BeforeClass)

Example 2 with StructuredTableSpecification

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);
    }
}
Also used : StructuredTableSpecification(io.cdap.cdap.spi.data.table.StructuredTableSpecification)

Example 3 with StructuredTableSpecification

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);
    }
}
Also used : TableAlreadyExistsException(io.cdap.cdap.spi.data.TableAlreadyExistsException) StructuredTableId(io.cdap.cdap.spi.data.table.StructuredTableId) StructuredTableSpecification(io.cdap.cdap.spi.data.table.StructuredTableSpecification) StructuredTableRegistry(io.cdap.cdap.spi.data.common.StructuredTableRegistry)

Aggregations

StructuredTableSpecification (io.cdap.cdap.spi.data.table.StructuredTableSpecification)3 TableAlreadyExistsException (io.cdap.cdap.spi.data.TableAlreadyExistsException)1 StructuredTableRegistry (io.cdap.cdap.spi.data.common.StructuredTableRegistry)1 StructuredTableId (io.cdap.cdap.spi.data.table.StructuredTableId)1 StructuredTableSchema (io.cdap.cdap.spi.data.table.StructuredTableSchema)1 BeforeClass (org.junit.BeforeClass)1