Search in sources :

Example 11 with Column

use of org.molgenis.emx2.Column in project simple-bigtable by spotify.

the class ColumnReadImplTest method testParentDataTypeToDataType.

@Test
public void testParentDataTypeToDataType() throws Exception {
    assertEquals(Optional.empty(), columnRead.parentTypeToCurrentType().apply(Optional.empty()));
    assertEquals(Optional.empty(), columnRead.parentTypeToCurrentType().apply(Optional.of(Family.getDefaultInstance())));
    final Column column = Column.getDefaultInstance();
    final Family family = Family.newBuilder().addColumns(column).build();
    assertEquals(Optional.of(column), columnRead.parentTypeToCurrentType().apply(Optional.of(family)));
}
Also used : Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Test(org.junit.Test)

Example 12 with Column

use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.

the class Schema method getSchemaMetadata.

public SchemaMetadata getSchemaMetadata() {
    SchemaMetadata s = new SchemaMetadata();
    s.setSettings(this.settings);
    for (Table t : this.tables) {
        TableMetadata tm = s.create(table(t.getName()));
        tm.setInherit(t.getInherit());
        tm.setSettings(t.getSettings());
        tm.setOldName(t.getOldName());
        if (t.getDrop())
            tm.drop();
        tm.setSemantics(t.getSemantics());
        tm.setDescription(t.getDescription());
        for (Column c : t.getColumns()) {
            int i = 1;
            if (!c.isInherited()) {
                // we remove clearly inherited columns here
                org.molgenis.emx2.Column cm = c.getColumnMetadata(tm);
                tm.add(cm);
            }
        }
        tm.setTableType(t.getTableType());
    }
    return s;
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) SchemaMetadata(org.molgenis.emx2.SchemaMetadata)

Example 13 with Column

use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.

the class Emx1 method loadColumns.

private static List<Emx1Attribute> loadColumns(TableStore store, Map<String, Emx1Entity> entities, SchemaMetadata schema) {
    // line 1 is header
    int line = 2;
    List<Emx1Attribute> attributes = new ArrayList<>();
    try {
        if (store.containsTable("attributes")) {
            for (Row row : store.readTable("attributes")) {
                attributes.add(new Emx1Attribute(row));
                line++;
            }
        }
        // line 1 is header
        line = 2;
        for (Emx1Attribute attribute : attributes) {
            // create the table, if needed
            String entityName = attribute.getEntity();
            String tableName = getTableName(entities, entityName);
            TableMetadata table = schema.getTableMetadata(tableName);
            if (table == null) {
                table = schema.create(table(tableName));
            }
            // create the attribute
            ColumnType type = getColumnType(attribute.getDataType());
            Column column = column(attribute.getName()).setType(type).setRequired(!attribute.getNillable());
            // pkey
            if (attribute.getIdAttribute()) {
                column.setKey(1);
            }
            table.add(column);
            line++;
        }
    } catch (MolgenisException me) {
        throw new MolgenisException(EMX_1_IMPORT_FAILED + me.getMessage() + ". See 'attributes' line " + line, me);
    }
    return attributes;
}
Also used : ColumnType(org.molgenis.emx2.ColumnType) ArrayList(java.util.ArrayList)

Example 14 with Column

use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.

the class ArrayTypeTestExample method createSimpleTypeTest.

public static void createSimpleTypeTest(SchemaMetadata schema) {
    TableMetadata typeTestTable = schema.create(table("ArrayTypeTest"));
    typeTestTable.add(column("id").setPkey());
    ColumnType[] columnTypes = new ColumnType[] { UUID_ARRAY, STRING_ARRAY, BOOL_ARRAY, INT_ARRAY, DECIMAL_ARRAY, TEXT_ARRAY, DATE_ARRAY, DATETIME_ARRAY };
    for (ColumnType columnType : columnTypes) {
        typeTestTable.add(column("Test_" + columnType.toString().toLowerCase()).setType(columnType).setRequired(true));
        typeTestTable.add(column("Test_" + columnType.toString().toLowerCase() + "_nillable").setType(columnType));
    }
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) ColumnType(org.molgenis.emx2.ColumnType)

Example 15 with Column

use of org.molgenis.emx2.Column in project molgenis-emx2 by molgenis.

the class SqlTable method getWhereConditionForBatchDelete.

private Condition getWhereConditionForBatchDelete(Collection<Row> rows) {
    List<Condition> conditions = new ArrayList<>();
    for (Row r : rows) {
        List<Condition> rowCondition = new ArrayList<>();
        if (getMetadata().getPrimaryKeys().isEmpty()) {
            // when no key, use all columns as id
            for (Column keyPart : getMetadata().getStoredColumns()) {
                rowCondition.add(getColumnCondition(r, keyPart));
            }
        } else {
            for (Column keyPart : getMetadata().getPrimaryKeyColumns()) {
                rowCondition.add(getColumnCondition(r, keyPart));
            }
        }
        conditions.add(and(rowCondition));
    }
    return or(conditions);
}
Also used : Row(org.molgenis.emx2.Row)

Aggregations

org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)21 ArrayList (java.util.ArrayList)20 Test (org.junit.Test)20 Row (org.molgenis.emx2.Row)15 Table (org.molgenis.emx2.Table)14 HashMap (java.util.HashMap)11 Column (org.molgenis.emx2.Column)11 List (java.util.List)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)10 ColumnType (org.molgenis.emx2.ColumnType)10 Column (com.google.bigtable.v2.Column)9 TableMetadata (org.molgenis.emx2.TableMetadata)9 Family (com.google.bigtable.v2.Family)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint)8 Schema (org.molgenis.emx2.Schema)8 MolgenisException (org.molgenis.emx2.MolgenisException)7 Collectors (java.util.stream.Collectors)6 Map (java.util.Map)5 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)5