Search in sources :

Example 16 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202205.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>() {

        @Override
        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) {
        Collections.addAll(combinedRows, second.getRows());
    }
    ResultSet combinedResultSet = new ResultSet();
    combinedResultSet.setColumnTypes(first.getColumnTypes());
    combinedResultSet.setRows(combinedRows.toArray(new Row[] {}));
    return combinedResultSet;
}
Also used : Function(com.google.common.base.Function) ColumnType(com.google.api.ads.admanager.axis.v202205.ColumnType) ResultSet(com.google.api.ads.admanager.axis.v202205.ResultSet) Row(com.google.api.ads.admanager.axis.v202205.Row)

Example 17 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202205.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 18 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202205.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 19 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202205.ColumnType in project molgenis-emx2 by molgenis.

the class Column method getReferences.

/**
 * will return self in case of single, and multiple in case of composite key wrapper
 */
public List<Reference> getReferences() {
    // no ref
    if (getRefTable() == null) {
        return new ArrayList<>();
    }
    List<Column> pkeys = getRefTable().getPrimaryKeyColumns();
    List<Reference> refColumns = new ArrayList<>();
    // check if primary key exists
    if (pkeys.size() == 0) {
        throw new MolgenisException("Error in column '" + getName() + "': Reference to " + getRefTableName() + " fails because that table has no primary key");
    }
    // create the refs
    Column refLink = getRefLinkColumn();
    for (Column keyPart : pkeys) {
        if (keyPart.isReference()) {
            for (Reference ref : keyPart.getReferences()) {
                ColumnType type = ref.getPrimitiveType();
                if (!isRef()) {
                    type = getArrayType(type);
                }
                List<String> path = ref.getPath();
                path.add(0, keyPart.getName());
                String name = null;
                if (refLink != null) {
                    for (Reference overlap : refLink.getReferences()) {
                        if (overlap.getTargetTable().equals(ref.getTargetTable()) && overlap.getTargetColumn().equals(ref.getTargetColumn())) {
                            name = overlap.getName();
                        }
                    }
                }
                if (name == null) {
                    name = getName();
                    if (pkeys.size() > 1) {
                        name += COMPOSITE_REF_SEPARATOR + ref.getName();
                    }
                }
                refColumns.add(new Reference(this, name, ref.getName(), getColumnType(), type, keyPart.getColumnType().isArray(), ref.getTargetTable(), ref.getTargetColumn(), ref.isRequired() || this.isRequired(), path));
            }
        } else {
            ColumnType type = keyPart.getColumnType();
            // all but ref is array
            if (!isRef()) {
                type = getArrayType(type);
            }
            // create the ref
            String name = getName();
            if (pkeys.size() > 1) {
                name += COMPOSITE_REF_SEPARATOR + keyPart.getName();
            }
            refColumns.add(new Reference(this, name, keyPart.getName(), getColumnType(), type, getColumnType().isArray(), getRefTableName(), keyPart.getName(), keyPart.isRequired() || this.isRequired(), new ArrayList<>(List.of(keyPart.getName()))));
        }
    }
    // clean up in case only one
    if (refColumns.stream().filter(r -> r.getName().startsWith(getName())).count() == 1) {
        refColumns = refColumns.stream().map(r -> {
            if (r.getName().startsWith(getName()))
                r.setName(getName());
            return r;
        }).collect(Collectors.toList());
    }
    // remove duplicates
    HashSet<Object> seen = new HashSet<>();
    refColumns.removeIf(e -> !seen.add(e.getName()));
    return refColumns;
}
Also used : ColumnType(org.molgenis.emx2.ColumnType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 20 with ColumnType

use of com.google.api.ads.admanager.jaxws.v202205.ColumnType in project googleads-java-lib by googleads.

the class PqlTest method setUp.

@Before
public void setUp() throws Exception {
    column1 = new ColumnType();
    column1.setLabelName("column1");
    column2 = new ColumnType();
    column2.setLabelName("column2");
    column3 = new ColumnType();
    column3.setLabelName("column3");
    textValue1 = new TextValue();
    textValue1.setValue("value1");
    textValue2 = new TextValue();
    textValue2.setValue("value2");
    textValue3 = new TextValue();
    textValue3.setValue("value3");
    textValue4 = new TextValue();
    textValue4.setValue("comma,separated");
    booleanValue1 = new BooleanValue();
    booleanValue1.setValue(false);
    booleanValue2 = new BooleanValue();
    booleanValue2.setValue(true);
    booleanValue3 = new BooleanValue();
    booleanValue3.setValue(false);
    numberValue1 = new NumberValue();
    numberValue1.setValue("1");
    numberValue2 = new NumberValue();
    numberValue2.setValue("1.02");
    numberValue3 = new NumberValue();
    numberValue3.setValue("-1");
    numberValue4 = new NumberValue();
    numberValue4.setValue("");
    numberValue5 = new NumberValue();
    numberValue5.setValue(null);
    dateTime1 = new DateTime();
    date1 = new Date();
    date1.setYear(2012);
    date1.setMonth(12);
    date1.setDay(2);
    dateTime1.setDate(date1);
    dateTime1.setHour(12);
    dateTime1.setMinute(45);
    dateTime1.setSecond(0);
    dateTime1.setTimeZoneId(TIME_ZONE_ID1);
    dateTimeValue1 = new DateTimeValue();
    dateTimeValue1.setValue(dateTime1);
    dateValue1 = new DateValue();
    dateValue1.setValue(date1);
    AdUnitTargeting adUnitTargeting = new AdUnitTargeting();
    adUnitTargeting.setAdUnitId("100");
    InventoryTargeting inventoryTargeting = new InventoryTargeting();
    inventoryTargeting.setTargetedAdUnits(new AdUnitTargeting[] { adUnitTargeting });
    targeting1 = new Targeting();
    targeting1.setInventoryTargeting(inventoryTargeting);
    targetingValue1 = new TargetingValue();
    targetingValue1.setValue(targeting1);
    numberSetValue = new SetValue();
    numberSetValue.setValues(new Value[] { numberValue1, numberValue3 });
    textSetValue = new SetValue();
    textSetValue.setValues(new Value[] { textValue1, textValue2 });
    dateSetValue = new SetValue();
    dateSetValue.setValues(new Value[] { dateValue1 });
    dateTimeSetValue = new SetValue();
    dateTimeSetValue.setValues(new Value[] { dateTimeValue1 });
    mixedSetValue = new SetValue();
    mixedSetValue.setValues(new Value[] { textValue1, dateTimeValue1 });
    commaTextSetValue = new SetValue();
    commaTextSetValue.setValues(new Value[] { textValue1, textValue4 });
}
Also used : ColumnType(com.google.api.ads.admanager.axis.v202105.ColumnType) DateTimeValue(com.google.api.ads.admanager.axis.v202105.DateTimeValue) InventoryTargeting(com.google.api.ads.admanager.axis.v202105.InventoryTargeting) Targeting(com.google.api.ads.admanager.axis.v202105.Targeting) AdUnitTargeting(com.google.api.ads.admanager.axis.v202105.AdUnitTargeting) InventoryTargeting(com.google.api.ads.admanager.axis.v202105.InventoryTargeting) DateTime(com.google.api.ads.admanager.axis.v202105.DateTime) Date(com.google.api.ads.admanager.axis.v202105.Date) AdUnitTargeting(com.google.api.ads.admanager.axis.v202105.AdUnitTargeting) NumberValue(com.google.api.ads.admanager.axis.v202105.NumberValue) TextValue(com.google.api.ads.admanager.axis.v202105.TextValue) DateValue(com.google.api.ads.admanager.axis.v202105.DateValue) BooleanValue(com.google.api.ads.admanager.axis.v202105.BooleanValue) TargetingValue(com.google.api.ads.admanager.axis.v202105.TargetingValue) SetValue(com.google.api.ads.admanager.axis.v202105.SetValue) Before(org.junit.Before)

Aggregations

ColumnType (org.molgenis.emx2.ColumnType)11 Function (com.google.common.base.Function)10 Before (org.junit.Before)10 TableMetadata (org.molgenis.emx2.TableMetadata)5 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 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 DateTimeValue (com.google.api.ads.admanager.axis.v202105.DateTimeValue)1 DateValue (com.google.api.ads.admanager.axis.v202105.DateValue)1