Search in sources :

Example 21 with SamzaSqlRelMessage

use of org.apache.samza.sql.data.SamzaSqlRelMessage in project samza by apache.

the class ProjectTranslator method translateFlatten.

private MessageStream<SamzaSqlRelMessage> translateFlatten(Integer flattenIndex, MessageStream<SamzaSqlRelMessage> inputStream) {
    return inputStream.flatMap(message -> {
        Object targetFlattenColumn = message.getSamzaSqlRelRecord().getFieldValues().get(flattenIndex);
        final List<SamzaSqlRelMessage> outMessages = new ArrayList<>();
        if (targetFlattenColumn != null && targetFlattenColumn instanceof List) {
            List<Object> objectList = (List<Object>) targetFlattenColumn;
            SamzaSqlRelMsgMetadata messageMetadata = message.getSamzaSqlRelMsgMetadata();
            SamzaSqlRelMsgMetadata newMetadata = new SamzaSqlRelMsgMetadata(messageMetadata.getEventTime(), messageMetadata.getArrivalTime(), messageMetadata.getScanTimeNanos(), messageMetadata.getScanTimeMillis());
            for (Object fieldValue : objectList) {
                List<Object> newValues = new ArrayList<>(message.getSamzaSqlRelRecord().getFieldValues());
                newValues.set(flattenIndex, fieldValue);
                outMessages.add(new SamzaSqlRelMessage(message.getSamzaSqlRelRecord().getFieldNames(), newValues, newMetadata));
                newMetadata = new SamzaSqlRelMsgMetadata(newMetadata.getEventTime(), newMetadata.getArrivalTime(), newMetadata.getScanTimeNanos(), newMetadata.getScanTimeMillis());
            }
        } else {
            message.getSamzaSqlRelMsgMetadata().isNewInputMessage = true;
            outMessages.add(message);
        }
        return outMessages;
    });
}
Also used : SamzaSqlRelMsgMetadata(org.apache.samza.sql.data.SamzaSqlRelMsgMetadata) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SamzaSqlRelMessage(org.apache.samza.sql.data.SamzaSqlRelMessage)

Example 22 with SamzaSqlRelMessage

use of org.apache.samza.sql.data.SamzaSqlRelMessage in project samza by apache.

the class TestAvroRelConversion method testEmptyRecordConversion.

@Test
public void testEmptyRecordConversion() {
    GenericData.Record record = new GenericData.Record(SimpleRecord.SCHEMA$);
    SamzaSqlRelMessage message = simpleRecordAvroRelConverter.convertToRelMessage(new KV<>("key", record));
    Assert.assertEquals(message.getSamzaSqlRelRecord().getFieldNames().size(), message.getSamzaSqlRelRecord().getFieldValues().size());
}
Also used : ComplexRecord(org.apache.samza.sql.avro.schemas.ComplexRecord) StreetNumRecord(org.apache.samza.sql.avro.schemas.StreetNumRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) SimpleRecord(org.apache.samza.sql.avro.schemas.SimpleRecord) AddressRecord(org.apache.samza.sql.avro.schemas.AddressRecord) GenericData(org.apache.avro.generic.GenericData) SamzaSqlRelMessage(org.apache.samza.sql.data.SamzaSqlRelMessage) Test(org.junit.Test)

Example 23 with SamzaSqlRelMessage

use of org.apache.samza.sql.data.SamzaSqlRelMessage in project samza by apache.

the class TestAvroRelConversion method testNullRecordConversion.

@Test
public void testNullRecordConversion() {
    SamzaSqlRelMessage message = simpleRecordAvroRelConverter.convertToRelMessage(new KV<>("key", null));
    Assert.assertEquals(message.getSamzaSqlRelRecord().getFieldNames().size(), message.getSamzaSqlRelRecord().getFieldValues().size());
}
Also used : SamzaSqlRelMessage(org.apache.samza.sql.data.SamzaSqlRelMessage) Test(org.junit.Test)

Example 24 with SamzaSqlRelMessage

use of org.apache.samza.sql.data.SamzaSqlRelMessage in project samza by apache.

the class TestAvroRelConversion method testRecordConversionWithNullPayload.

// SAMZA-2110 We need to enable this when we have a true support for Null records
@Ignore
@Test
public void testRecordConversionWithNullPayload() throws IOException {
    GenericData.Record record = null;
    SamzaSqlRelMessage relMessage = nestedRecordAvroRelConverter.convertToRelMessage(new KV<>("key", record));
    LOG.info(relMessage.toString());
    KV<Object, Object> samzaMessage = nestedRecordAvroRelConverter.convertToSamzaMessage(relMessage);
    GenericRecord recordPostConversion = (GenericRecord) samzaMessage.getValue();
    Assert.assertTrue(recordPostConversion == null);
}
Also used : GenericRecord(org.apache.avro.generic.GenericRecord) GenericData(org.apache.avro.generic.GenericData) SamzaSqlRelMessage(org.apache.samza.sql.data.SamzaSqlRelMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with SamzaSqlRelMessage

use of org.apache.samza.sql.data.SamzaSqlRelMessage in project samza by apache.

the class TestAvroRelConversion method testSimpleRecordConversion.

@Test
public void testSimpleRecordConversion() {
    GenericData.Record record = new GenericData.Record(SimpleRecord.SCHEMA$);
    record.put("id", 1);
    record.put("name", "name1");
    SamzaSqlRelMessage message = simpleRecordAvroRelConverter.convertToRelMessage(new KV<>("key", record));
    LOG.info(message.toString());
}
Also used : ComplexRecord(org.apache.samza.sql.avro.schemas.ComplexRecord) StreetNumRecord(org.apache.samza.sql.avro.schemas.StreetNumRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) SimpleRecord(org.apache.samza.sql.avro.schemas.SimpleRecord) AddressRecord(org.apache.samza.sql.avro.schemas.AddressRecord) GenericData(org.apache.avro.generic.GenericData) SamzaSqlRelMessage(org.apache.samza.sql.data.SamzaSqlRelMessage) Test(org.junit.Test)

Aggregations

SamzaSqlRelMessage (org.apache.samza.sql.data.SamzaSqlRelMessage)28 Test (org.junit.Test)19 SamzaSqlRelMsgMetadata (org.apache.samza.sql.data.SamzaSqlRelMsgMetadata)14 ArrayList (java.util.ArrayList)13 GenericData (org.apache.avro.generic.GenericData)10 GenericRecord (org.apache.avro.generic.GenericRecord)10 HashMap (java.util.HashMap)9 IndexedRecord (org.apache.avro.generic.IndexedRecord)7 AddressRecord (org.apache.samza.sql.avro.schemas.AddressRecord)7 SimpleRecord (org.apache.samza.sql.avro.schemas.SimpleRecord)7 StreetNumRecord (org.apache.samza.sql.avro.schemas.StreetNumRecord)7 Schema (org.apache.avro.Schema)6 KV (org.apache.samza.operators.KV)6 MessageStream (org.apache.samza.operators.MessageStream)6 SamzaSqlRelRecord (org.apache.samza.sql.SamzaSqlRelRecord)6 List (java.util.List)5 ByteString (org.apache.calcite.avatica.util.ByteString)5 RelNode (org.apache.calcite.rel.RelNode)5 JoinRelType (org.apache.calcite.rel.core.JoinRelType)5 Logger (org.slf4j.Logger)5