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;
}
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());
}
}
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;
}
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;
}
Aggregations