use of org.apache.samza.sql.SamzaSqlRelRecord 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.SamzaSqlRelRecord 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.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method testArrayAtAllIntermediateFields.
@Test
public void testArrayAtAllIntermediateFields() {
SamzaSqlRelRecord record = createRecord("bar.baz[2].baf[3].foo[5]");
GetSqlFieldUdf getSqlFieldUdf = new GetSqlFieldUdf();
Assert.assertEquals(getSqlFieldUdf.execute(record, "bar.baz[2].baf[3].foo[5]"), "bar");
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method testAllFieldTypes.
@Test
public void testAllFieldTypes() {
SamzaSqlRelRecord record = createRecord("bar.map:baz.baf.foo[3].fun");
GetSqlFieldUdf getSqlFieldUdf = new GetSqlFieldUdf();
Assert.assertEquals(getSqlFieldUdf.execute(record, "bar.baz.baf.foo[3].fun"), "bar");
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method testArrayAtLastField.
@Test
public void testArrayAtLastField() {
SamzaSqlRelRecord record = createRecord("bar.baz.baf.foo[3]");
GetSqlFieldUdf getSqlFieldUdf = new GetSqlFieldUdf();
Assert.assertEquals(getSqlFieldUdf.execute(record, "bar.baz.baf.foo[3]"), "bar");
}
Aggregations