use of com.github.os72.protobuf.dynamic.MessageDefinition in project firehose by odpf.
the class KafkaMetadataProtoMessageUtils method createSchema.
private static DynamicSchema createSchema(String kafkaMetadataColumnName) {
DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder().setName(FILE_NAME).setPackage(PACKAGE);
MessageDefinition timestampMessageDefinition = TimestampMetadataProtoMessage.createMessageDefinition();
schemaBuilder.addMessageDefinition(timestampMessageDefinition);
MessageDefinition kafkaMetadataMessageDefinition = KafkaMetadataProtoMessage.createMessageDefinition();
schemaBuilder.addMessageDefinition(kafkaMetadataMessageDefinition);
if (!kafkaMetadataColumnName.isEmpty()) {
MessageDefinition kafkaNestedMetadataProtoMessageDefinition = NestedKafkaMetadataProtoMessage.createMessageDefinition(kafkaMetadataColumnName, KafkaMetadataProtoMessage.getTypeName(), kafkaMetadataMessageDefinition);
schemaBuilder.addMessageDefinition(kafkaNestedMetadataProtoMessageDefinition);
}
DynamicSchema schema;
try {
schema = schemaBuilder.build();
} catch (Descriptors.DescriptorValidationException e) {
throw new IllegalArgumentException("Invalid proto schema", e);
}
return schema;
}
use of com.github.os72.protobuf.dynamic.MessageDefinition in project firehose by odpf.
the class TestProtoMessage method createSchema.
public static DynamicSchema createSchema() {
DynamicSchema.Builder schemaBuilder = DynamicSchema.newBuilder().setName(FILE_NAME).setPackage(PACKAGE);
MessageDefinition messageDefinition = new TestProtoMessage().createMessageDefinition();
schemaBuilder.addMessageDefinition(messageDefinition);
schemaBuilder.addMessageDefinition(TimestampMetadataProtoMessage.createMessageDefinition());
DynamicSchema schema;
try {
schema = schemaBuilder.build();
} catch (Descriptors.DescriptorValidationException e) {
throw new RuntimeException(e);
}
return schema;
}
use of com.github.os72.protobuf.dynamic.MessageDefinition in project firehose by odpf.
the class KafkaMetadataProtoMessageTest method shouldCreateKafkaMetadataDynamicMessage.
@Test
public void shouldCreateKafkaMetadataDynamicMessage() throws Descriptors.DescriptorValidationException {
MessageDefinition messageDefinition = KafkaMetadataProtoMessage.createMessageDefinition();
schemaBuilder.addMessageDefinition(messageDefinition);
schemaBuilder.addMessageDefinition(TimestampMetadataProtoMessage.createMessageDefinition());
DynamicSchema dynamicSchema = schemaBuilder.build();
Descriptors.Descriptor descriptor = dynamicSchema.getMessageDescriptor(KafkaMetadataProtoMessage.getTypeName());
DynamicMessage dynamicMessage = KafkaMetadataProtoMessage.newBuilder(descriptor).setOffset(1).setPartition(1).setTopic("default").setMessageTimestamp(Instant.EPOCH).setLoadTime(Instant.EPOCH).build();
assertEquals(1L, dynamicMessage.getField(descriptor.findFieldByName(KafkaMetadataProtoMessage.MESSAGE_OFFSET_FIELD_NAME)));
assertEquals(1, dynamicMessage.getField(descriptor.findFieldByName(KafkaMetadataProtoMessage.MESSAGE_PARTITION_FIELD_NAME)));
assertEquals("default", dynamicMessage.getField(descriptor.findFieldByName(KafkaMetadataProtoMessage.MESSAGE_TOPIC_FIELD_NAME)));
Timestamp timestamp = Timestamp.newBuilder().setSeconds(0).setNanos(0).build();
assertEquals(timestamp, dynamicMessage.getField(descriptor.findFieldByName(KafkaMetadataProtoMessage.MESSAGE_TIMESTAMP_FIELD_NAME)));
assertEquals(timestamp, dynamicMessage.getField(descriptor.findFieldByName(KafkaMetadataProtoMessage.LOAD_TIME_FIELD_NAME)));
}
Aggregations