Search in sources :

Example 86 with Column

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

the class JsonLdExample method create.

public static void create(Schema schema) {
    Table personTable = schema.create(table("Person").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#Person").add(column("name").setPkey().setSemantics("https://schema.org/docs/jsonldcontext.jsonld#name"), column("jobTitle").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#jobTitle").setRequired(true), column("telephone").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#telephone"), column("url").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#url")));
    personTable.insert(row("name", "Jane Doe", "jobTitle", "Professor", "telephone", "(425) 123-4567", "url", "http://www.janedoe.com"), row("id", "2", "name", "Mary Stone", "jobTitle", "Cook"));
    Table recipeTable = schema.create(table("Recipe").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#Recipe").add(column("name").setPkey().setSemantics("https://schema.org/docs/jsonldcontext.jsonld#name"), column("author").setType(REF).setRefTable("Person").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#author").setRequired(true), column("datePublished").setType(DATE).setSemantics("https://schema.org/docs/jsonldcontext.jsonld#datePublished").setRequired(true), column("prepTime").setSemantics("https://schema.org/docs/jsonldcontext.jsonld#prepTime").setRequired(true)));
    recipeTable.insert(row("name", "Mary's Cookies", "author", "Mary Stone", "datePublished", "2018-03-10", "prepTime", "PT20M"));
}
Also used : Table(org.molgenis.emx2.Table)

Example 87 with Column

use of org.molgenis.emx2.Column in project SpinalTap by airbnb.

the class Table method toThriftTable.

public static com.airbnb.jitney.event.spinaltap.v1.Table toThriftTable(Table table) {
    Set<String> primaryKey = ImmutableSet.of();
    if (table.getPrimaryKey().isPresent()) {
        primaryKey = ImmutableSet.copyOf(table.getPrimaryKey().get().getColumns().values().stream().map(ColumnMetadata::getName).sorted().collect(Collectors.toList()));
    }
    Map<String, Column> columns = table.getColumns().values().stream().map(c -> {
        com.airbnb.jitney.event.spinaltap.v1.Column column = new com.airbnb.jitney.event.spinaltap.v1.Column(c.getColType().getCode(), c.isPrimaryKey(), c.getName());
        column.setPosition(c.getPosition());
        return column;
    }).collect(Collectors.toMap(c -> c.getName(), c -> c));
    com.airbnb.jitney.event.spinaltap.v1.Table thriftTable = new com.airbnb.jitney.event.spinaltap.v1.Table(table.getId(), table.getName(), table.getDatabase(), primaryKey, columns);
    if (!Strings.isNullOrEmpty(table.getOverridingDatabase())) {
        thriftTable.setOverridingDatabase(table.getOverridingDatabase());
    }
    return thriftTable;
}
Also used : Column(com.airbnb.jitney.event.spinaltap.v1.Column) ImmutableSet(com.google.common.collect.ImmutableSet) Getter(lombok.Getter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Value(lombok.Value) Strings(com.google.common.base.Strings) List(java.util.List) Optional(com.google.common.base.Optional) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Column(com.airbnb.jitney.event.spinaltap.v1.Column) Column(com.airbnb.jitney.event.spinaltap.v1.Column)

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