use of org.apache.samza.sql.data.SamzaSqlRelMsgMetadata in project samza by apache.
the class TestSamzaSqlLocalTableJoinFunction method testNullRecordWithLeftOuterJoin.
@Test
public void testNullRecordWithLeftOuterJoin() {
SamzaSqlRelMessage streamMsg = new SamzaSqlRelMessage(streamFieldNames, streamFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
JoinRelType joinRelType = JoinRelType.LEFT;
List<Integer> streamKeyIds = Arrays.asList(0, 1);
List<Integer> tableKeyIds = Arrays.asList(2, 3);
JoinInputNode mockTableInputNode = mock(JoinInputNode.class);
when(mockTableInputNode.getKeyIds()).thenReturn(tableKeyIds);
when(mockTableInputNode.isPosOnRight()).thenReturn(true);
when(mockTableInputNode.getFieldNames()).thenReturn(tableFieldNames);
JoinInputNode mockStreamInputNode = mock(JoinInputNode.class);
when(mockStreamInputNode.getKeyIds()).thenReturn(streamKeyIds);
when(mockStreamInputNode.isPosOnRight()).thenReturn(false);
when(mockStreamInputNode.getFieldNames()).thenReturn(streamFieldNames);
SamzaSqlLocalTableJoinFunction joinFn = new SamzaSqlLocalTableJoinFunction(mockStreamInputNode, mockTableInputNode, joinRelType);
SamzaSqlRelMessage outMsg = joinFn.apply(streamMsg, null);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues().size(), outMsg.getSamzaSqlRelRecord().getFieldNames().size());
List<String> expectedFieldNames = new ArrayList<>(streamFieldNames);
expectedFieldNames.addAll(tableFieldNames);
List<Object> expectedFieldValues = new ArrayList<>(streamFieldValues);
expectedFieldValues.addAll(tableFieldNames.stream().map(name -> null).collect(Collectors.toList()));
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues(), expectedFieldValues);
}
use of org.apache.samza.sql.data.SamzaSqlRelMsgMetadata in project samza by apache.
the class TestSamzaSqlLocalTableJoinFunction method testWithInnerJoinWithTableOnLeft.
@Test
public void testWithInnerJoinWithTableOnLeft() {
SamzaSqlRelMessage streamMsg = new SamzaSqlRelMessage(streamFieldNames, streamFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
SamzaSqlRelMessage tableMsg = new SamzaSqlRelMessage(tableFieldNames, tableFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
JoinRelType joinRelType = JoinRelType.INNER;
List<Integer> streamKeyIds = Arrays.asList(0, 2);
List<Integer> tableKeyIds = Arrays.asList(0, 2);
SamzaSqlRelRecord compositeKey = SamzaSqlRelMessage.createSamzaSqlCompositeKey(tableMsg, tableKeyIds);
KV<SamzaSqlRelRecord, SamzaSqlRelMessage> record = KV.of(compositeKey, tableMsg);
JoinInputNode mockTableInputNode = mock(JoinInputNode.class);
when(mockTableInputNode.getKeyIds()).thenReturn(tableKeyIds);
when(mockTableInputNode.isPosOnRight()).thenReturn(false);
when(mockTableInputNode.getFieldNames()).thenReturn(tableFieldNames);
JoinInputNode mockStreamInputNode = mock(JoinInputNode.class);
when(mockStreamInputNode.getKeyIds()).thenReturn(streamKeyIds);
when(mockStreamInputNode.isPosOnRight()).thenReturn(true);
when(mockStreamInputNode.getFieldNames()).thenReturn(streamFieldNames);
SamzaSqlLocalTableJoinFunction joinFn = new SamzaSqlLocalTableJoinFunction(mockStreamInputNode, mockTableInputNode, joinRelType);
SamzaSqlRelMessage outMsg = joinFn.apply(streamMsg, record);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues().size(), outMsg.getSamzaSqlRelRecord().getFieldNames().size());
List<String> expectedFieldNames = new ArrayList<>(tableFieldNames);
expectedFieldNames.addAll(streamFieldNames);
List<Object> expectedFieldValues = new ArrayList<>(tableFieldValues);
expectedFieldValues.addAll(streamFieldValues);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues(), expectedFieldValues);
}
use of org.apache.samza.sql.data.SamzaSqlRelMsgMetadata in project samza by apache.
the class TestSamzaSqlLocalTableJoinFunction method testNullRecordWithInnerJoin.
@Test
public void testNullRecordWithInnerJoin() {
SamzaSqlRelMessage streamMsg = new SamzaSqlRelMessage(streamFieldNames, streamFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
JoinRelType joinRelType = JoinRelType.INNER;
List<Integer> streamKeyIds = Arrays.asList(0, 1);
List<Integer> tableKeyIds = Arrays.asList(2, 3);
JoinInputNode mockTableInputNode = mock(JoinInputNode.class);
when(mockTableInputNode.getKeyIds()).thenReturn(tableKeyIds);
when(mockTableInputNode.isPosOnRight()).thenReturn(true);
when(mockTableInputNode.getFieldNames()).thenReturn(tableFieldNames);
JoinInputNode mockStreamInputNode = mock(JoinInputNode.class);
when(mockStreamInputNode.getKeyIds()).thenReturn(streamKeyIds);
when(mockStreamInputNode.isPosOnRight()).thenReturn(false);
when(mockStreamInputNode.getFieldNames()).thenReturn(streamFieldNames);
SamzaSqlLocalTableJoinFunction joinFn = new SamzaSqlLocalTableJoinFunction(mockStreamInputNode, mockTableInputNode, joinRelType);
SamzaSqlRelMessage outMsg = joinFn.apply(streamMsg, null);
Assert.assertNull(outMsg);
}
use of org.apache.samza.sql.data.SamzaSqlRelMsgMetadata in project samza by apache.
the class TestSamzaSqlLocalTableJoinFunction method testWithInnerJoinWithTableOnRight.
@Test
public void testWithInnerJoinWithTableOnRight() {
SamzaSqlRelMessage streamMsg = new SamzaSqlRelMessage(streamFieldNames, streamFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
SamzaSqlRelMessage tableMsg = new SamzaSqlRelMessage(tableFieldNames, tableFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
JoinRelType joinRelType = JoinRelType.INNER;
List<Integer> streamKeyIds = Arrays.asList(0, 1);
List<Integer> tableKeyIds = Arrays.asList(0, 1);
SamzaSqlRelRecord compositeKey = SamzaSqlRelMessage.createSamzaSqlCompositeKey(tableMsg, tableKeyIds);
KV<SamzaSqlRelRecord, SamzaSqlRelMessage> record = KV.of(compositeKey, tableMsg);
JoinInputNode mockTableInputNode = mock(JoinInputNode.class);
when(mockTableInputNode.getKeyIds()).thenReturn(tableKeyIds);
when(mockTableInputNode.isPosOnRight()).thenReturn(true);
when(mockTableInputNode.getFieldNames()).thenReturn(tableFieldNames);
JoinInputNode mockStreamInputNode = mock(JoinInputNode.class);
when(mockStreamInputNode.getKeyIds()).thenReturn(streamKeyIds);
when(mockStreamInputNode.isPosOnRight()).thenReturn(false);
when(mockStreamInputNode.getFieldNames()).thenReturn(streamFieldNames);
SamzaSqlLocalTableJoinFunction joinFn = new SamzaSqlLocalTableJoinFunction(mockStreamInputNode, mockTableInputNode, joinRelType);
SamzaSqlRelMessage outMsg = joinFn.apply(streamMsg, record);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues().size(), outMsg.getSamzaSqlRelRecord().getFieldNames().size());
List<String> expectedFieldNames = new ArrayList<>(streamFieldNames);
expectedFieldNames.addAll(tableFieldNames);
List<Object> expectedFieldValues = new ArrayList<>(streamFieldValues);
expectedFieldValues.addAll(tableFieldValues);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues(), expectedFieldValues);
}
use of org.apache.samza.sql.data.SamzaSqlRelMsgMetadata in project samza by apache.
the class TestSamzaSqlRemoteTableJoinFunction method testWithInnerJoinWithTableOnRight.
@Test
public void testWithInnerJoinWithTableOnRight() {
Map<String, String> props = new HashMap<>();
SystemStream ss = new SystemStream("test", "nestedRecord");
props.put(String.format(ConfigBasedAvroRelSchemaProviderFactory.CFG_SOURCE_SCHEMA, ss.getSystem(), ss.getStream()), SimpleRecord.SCHEMA$.toString());
ConfigBasedAvroRelSchemaProviderFactory factory = new ConfigBasedAvroRelSchemaProviderFactory();
AvroRelSchemaProvider schemaProvider = (AvroRelSchemaProvider) factory.create(ss, new MapConfig(props));
AvroRelConverter relConverter = new AvroRelConverter(ss, schemaProvider, new MapConfig());
SamzaRelTableKeyConverter relTableKeyConverter = new SampleRelTableKeyConverter();
String remoteTableName = "testDb.testTable.$table";
GenericData.Record tableRecord = new GenericData.Record(SimpleRecord.SCHEMA$);
tableRecord.put("id", 1);
tableRecord.put("name", "name1");
SamzaSqlRelMessage streamMsg = new SamzaSqlRelMessage(streamFieldNames, streamFieldValues, new SamzaSqlRelMsgMetadata(0L, 0L));
SamzaSqlRelMessage tableMsg = relConverter.convertToRelMessage(new KV(tableRecord.get("id"), tableRecord));
JoinRelType joinRelType = JoinRelType.INNER;
List<Integer> streamKeyIds = Arrays.asList(1);
List<Integer> tableKeyIds = Arrays.asList(0);
KV<Object, GenericRecord> record = KV.of(tableRecord.get("id"), tableRecord);
JoinInputNode mockTableInputNode = mock(JoinInputNode.class);
when(mockTableInputNode.getKeyIds()).thenReturn(tableKeyIds);
when(mockTableInputNode.isPosOnRight()).thenReturn(true);
when(mockTableInputNode.getFieldNames()).thenReturn(tableMsg.getSamzaSqlRelRecord().getFieldNames());
when(mockTableInputNode.getSourceName()).thenReturn(remoteTableName);
JoinInputNode mockStreamInputNode = mock(JoinInputNode.class);
when(mockStreamInputNode.getKeyIds()).thenReturn(streamKeyIds);
when(mockStreamInputNode.isPosOnRight()).thenReturn(false);
when(mockStreamInputNode.getFieldNames()).thenReturn(streamFieldNames);
SamzaSqlRemoteTableJoinFunction joinFn = new SamzaSqlRemoteTableJoinFunction(relConverter, relTableKeyConverter, mockStreamInputNode, mockTableInputNode, joinRelType, 0);
SamzaSqlRelMessage outMsg = joinFn.apply(streamMsg, record);
Assert.assertEquals(outMsg.getSamzaSqlRelRecord().getFieldValues().size(), outMsg.getSamzaSqlRelRecord().getFieldNames().size());
List<String> expectedFieldNames = new ArrayList<>(streamFieldNames);
expectedFieldNames.addAll(tableMsg.getSamzaSqlRelRecord().getFieldNames());
List<Object> expectedFieldValues = new ArrayList<>(streamFieldValues);
expectedFieldValues.addAll(tableMsg.getSamzaSqlRelRecord().getFieldValues());
Assert.assertEquals(expectedFieldNames, outMsg.getSamzaSqlRelRecord().getFieldNames());
Assert.assertEquals(expectedFieldValues, outMsg.getSamzaSqlRelRecord().getFieldValues());
}
Aggregations