Search in sources :

Example 6 with ColumnType

use of org.molgenis.emx2.ColumnType 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 7 with ColumnType

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

the class SimpleTypeTestExample method createSimpleTypeTest.

public static void createSimpleTypeTest(SchemaMetadata schema) {
    TableMetadata typeTestTable = table(TYPE_TEST).add(column("id").setPkey());
    ColumnType[] columnTypes = new ColumnType[] { UUID, STRING, BOOL, INT, DECIMAL, TEXT, DATE, DATETIME };
    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));
    }
    schema.create(typeTestTable);
}
Also used : TableMetadata(org.molgenis.emx2.TableMetadata) ColumnType(org.molgenis.emx2.ColumnType)

Example 8 with ColumnType

use of org.molgenis.emx2.ColumnType 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 9 with ColumnType

use of org.molgenis.emx2.ColumnType in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        combinedRows.addAll(Lists.newArrayList(second.getRows()));
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.getColumnTypes().addAll(first.getColumnTypes());
    combinedResultSet.getRows().addAll(combinedRows);
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.jaxws.v202108.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202108.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202108.Row)

Example 10 with ColumnType

use of org.molgenis.emx2.ColumnType in project googleads-java-lib by googleads.

the class Pql method combineResultSets.

/**
 * Combines the first and second result sets, if and only if, the columns of both result sets
 * match.
 *
 * @throws IllegalArgumentException if the columns of the first result set don't match the second
 */
public static ResultSet combineResultSets(ResultSet first, ResultSet second) {
    Function<ColumnType, String> columnTypeToString = new Function<ColumnType, String>() {

        public String apply(ColumnType input) {
            return input.getLabelName();
        }
    };
    List<String> firstColumns = Lists.transform(Lists.newArrayList(first.getColumnTypes()), columnTypeToString);
    List<String> secondColumns = Lists.transform(Lists.newArrayList(second.getColumnTypes()), columnTypeToString);
    if (!firstColumns.equals(secondColumns)) {
        throw new IllegalArgumentException(String.format("First result set columns [%s] do not match second columns [%s]", Joiner.on(",").join(firstColumns), Joiner.on(",").join(secondColumns)));
    }
    List<Row> combinedRows = Lists.newArrayList(first.getRows());
    if (second.getRows() != null) {
        combinedRows.addAll(Lists.newArrayList(second.getRows()));
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.getColumnTypes().addAll(first.getColumnTypes());
    combinedResultSet.getRows().addAll(combinedRows);
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.jaxws.v202111.ColumnType) ResultSet(com.google.api.ads.admanager.jaxws.v202111.ResultSet) Row(com.google.api.ads.admanager.jaxws.v202111.Row)

Aggregations

Function (com.google.common.base.Function)10 Before (org.junit.Before)10 ColumnType (org.molgenis.emx2.ColumnType)8 ColumnType (com.google.api.ads.admanager.axis.v202105.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202108.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202111.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202202.ColumnType)2 ColumnType (com.google.api.ads.admanager.axis.v202205.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202108.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202202.ColumnType)2 ColumnType (com.google.api.ads.admanager.jaxws.v202205.ColumnType)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TableMetadata (org.molgenis.emx2.TableMetadata)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AdUnitTargeting (com.google.api.ads.admanager.axis.v202105.AdUnitTargeting)1 BooleanValue (com.google.api.ads.admanager.axis.v202105.BooleanValue)1 Date (com.google.api.ads.admanager.axis.v202105.Date)1 DateTime (com.google.api.ads.admanager.axis.v202105.DateTime)1