use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method testPathTooDeep.
@Test(expected = IllegalArgumentException.class)
public void testPathTooDeep() {
SamzaSqlRelRecord record = createRecord("bar.foo");
GetSqlFieldUdf getSqlFieldUdf = new GetSqlFieldUdf();
getSqlFieldUdf.execute(record, "bar.baz.baf.funny");
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class SampleRelTableKeyConverterTest method testNullValue.
@Test
public void testNullValue() {
SampleRelTableKeyConverter sampleRelTableKeyConverter = new SampleRelTableKeyConverter();
List<Object> values = new ArrayList<>();
values.add(null);
SamzaSqlRelRecord samzaSqlRelRecord = new SamzaSqlRelRecord(ImmutableList.of("c1"), values);
Object key = sampleRelTableKeyConverter.convertToTableKeyFormat(samzaSqlRelRecord);
Assert.assertNull(key);
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestBuildOutputRecordUdf method testNoArgs.
@Test
public void testNoArgs() {
BuildOutputRecordUdf buildOutputRecordUdf = new BuildOutputRecordUdf();
SamzaSqlRelRecord actualRecord = buildOutputRecordUdf.execute();
SamzaSqlRelRecord expectedRecord = new SamzaSqlRelRecord(new ArrayList<>(), new ArrayList<>());
Assert.assertEquals(actualRecord.getFieldNames(), expectedRecord.getFieldNames());
Assert.assertEquals(actualRecord.getFieldValues(), expectedRecord.getFieldValues());
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method createRecord.
static Object createRecord(List<String> fieldNames, int level) {
String fieldName = fieldNames.get(level);
Object child = (level == fieldNames.size() - 1) ? "bar" : createRecord(fieldNames, level + 1);
boolean isMap = false;
int arrayIndex = -1;
if (fieldName.startsWith("map:")) {
isMap = true;
// strip "map:"
fieldName = fieldName.substring(4);
} else if (fieldName.endsWith("]")) {
arrayIndex = Integer.parseInt(fieldName.substring(fieldName.indexOf("[") + 1, fieldName.length() - 1));
fieldName = fieldName.substring(0, fieldName.indexOf("["));
}
if (isMap) {
Map<String, Object> retMap = new HashMap<>();
retMap.put(fieldName, child);
return retMap;
} else if (arrayIndex >= 0) {
List list = Arrays.asList(new Object[2 * arrayIndex]);
list.set(arrayIndex, child);
return list;
} else {
return new SamzaSqlRelRecord(Collections.singletonList(fieldName), Collections.singletonList(child));
}
}
use of org.apache.samza.sql.SamzaSqlRelRecord in project samza by apache.
the class TestGetSqlFieldUdf method testMultiLevel.
@Test
public void testMultiLevel() {
SamzaSqlRelRecord record = createRecord("bar.baz.baf.foo");
GetSqlFieldUdf getSqlFieldUdf = new GetSqlFieldUdf();
Assert.assertEquals(getSqlFieldUdf.execute(record, "bar.baz.baf.foo"), "bar");
}
Aggregations