Search in sources :

Example 1 with PubSubDatasetProperties

use of org.talend.components.pubsub.PubSubDatasetProperties in project components by Talend.

the class PubSubTestConstants method createDatasetFromAvro.

public static PubSubDatasetProperties createDatasetFromAvro(PubSubDatastoreProperties datastore, String topic, String schema) {
    PubSubDatasetProperties dataset = createDataset(datastore, topic);
    dataset.valueFormat.setValue(PubSubDatasetProperties.ValueFormat.AVRO);
    dataset.avroSchema.setValue(schema);
    return dataset;
}
Also used : PubSubDatasetProperties(org.talend.components.pubsub.PubSubDatasetProperties)

Example 2 with PubSubDatasetProperties

use of org.talend.components.pubsub.PubSubDatasetProperties in project components by Talend.

the class PubSubOutputRuntime method expand.

@Override
public PDone expand(PCollection<IndexedRecord> in) {
    PubSubDatasetProperties dataset = properties.getDatasetProperties();
    PubSubDatastoreProperties datastore = dataset.getDatastoreProperties();
    try {
        createTopicSubscriptionIfNeeded(properties);
    } catch (IOException e) {
        throw TalendRuntimeException.createUnexpectedException(e);
    }
    PubsubIO.Write<PubsubMessage> pubsubWrite = PubsubIO.writeMessages().to(String.format("projects/%s/topics/%s", datastore.projectName.getValue(), dataset.topic.getValue()));
    if (properties.idLabel.getValue() != null && !"".equals(properties.idLabel.getValue())) {
        pubsubWrite.withIdAttribute(properties.idLabel.getValue());
    }
    if (properties.timestampLabel.getValue() != null && !"".equals(properties.timestampLabel.getValue())) {
        pubsubWrite.withTimestampAttribute(properties.timestampLabel.getValue());
    }
    switch(dataset.valueFormat.getValue()) {
        case CSV:
            {
                return in.apply(MapElements.via(new FormatCsv(dataset.fieldDelimiter.getValue()))).apply(pubsubWrite);
            }
        case AVRO:
            {
                return in.apply(MapElements.via(new FormatAvro())).apply(pubsubWrite);
            }
        default:
            throw new RuntimeException("To be implemented: " + dataset.valueFormat.getValue());
    }
}
Also used : PubSubDatasetProperties(org.talend.components.pubsub.PubSubDatasetProperties) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) PubsubIO(org.apache.beam.sdk.io.gcp.pubsub.PubsubIO) PubSubDatastoreProperties(org.talend.components.pubsub.PubSubDatastoreProperties) IOException(java.io.IOException) PubsubMessage(org.apache.beam.sdk.io.gcp.pubsub.PubsubMessage)

Example 3 with PubSubDatasetProperties

use of org.talend.components.pubsub.PubSubDatasetProperties in project components by Talend.

the class PubSubTestConstants method createDataset.

public static PubSubDatasetProperties createDataset(PubSubDatastoreProperties datastore, String topic) {
    PubSubDatasetProperties dataset = new PubSubDatasetProperties("dataset");
    dataset.init();
    dataset.setDatastoreProperties(datastore);
    dataset.topic.setValue(topic);
    return dataset;
}
Also used : PubSubDatasetProperties(org.talend.components.pubsub.PubSubDatasetProperties)

Example 4 with PubSubDatasetProperties

use of org.talend.components.pubsub.PubSubDatasetProperties in project components by Talend.

the class PubSubTestConstants method createDatasetFromCSV.

public static PubSubDatasetProperties createDatasetFromCSV(PubSubDatastoreProperties datastore, String topic, String fieldDelimited) {
    PubSubDatasetProperties dataset = createDataset(datastore, topic);
    dataset.valueFormat.setValue(PubSubDatasetProperties.ValueFormat.CSV);
    dataset.fieldDelimiter.setValue(fieldDelimited);
    return dataset;
}
Also used : PubSubDatasetProperties(org.talend.components.pubsub.PubSubDatasetProperties)

Aggregations

PubSubDatasetProperties (org.talend.components.pubsub.PubSubDatasetProperties)4 IOException (java.io.IOException)1 PubsubIO (org.apache.beam.sdk.io.gcp.pubsub.PubsubIO)1 PubsubMessage (org.apache.beam.sdk.io.gcp.pubsub.PubsubMessage)1 PubSubDatastoreProperties (org.talend.components.pubsub.PubSubDatastoreProperties)1 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)1