Search in sources :

Example 16 with SamzaSqlRelRecord

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");
}
Also used : SamzaSqlRelRecord(org.apache.samza.sql.SamzaSqlRelRecord) Test(org.junit.Test)

Example 17 with SamzaSqlRelRecord

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);
}
Also used : SamzaSqlRelRecord(org.apache.samza.sql.SamzaSqlRelRecord) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with SamzaSqlRelRecord

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());
}
Also used : SamzaSqlRelRecord(org.apache.samza.sql.SamzaSqlRelRecord) Test(org.junit.Test)

Example 19 with SamzaSqlRelRecord

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));
    }
}
Also used : SamzaSqlRelRecord(org.apache.samza.sql.SamzaSqlRelRecord) HashMap(java.util.HashMap) List(java.util.List)

Example 20 with SamzaSqlRelRecord

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");
}
Also used : SamzaSqlRelRecord(org.apache.samza.sql.SamzaSqlRelRecord) Test(org.junit.Test)

Aggregations

SamzaSqlRelRecord (org.apache.samza.sql.SamzaSqlRelRecord)31 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)6 SamzaSqlRelMessage (org.apache.samza.sql.data.SamzaSqlRelMessage)5 List (java.util.List)3 Schema (org.apache.avro.Schema)3 JoinRelType (org.apache.calcite.rel.core.JoinRelType)3 SamzaSqlRelMsgMetadata (org.apache.samza.sql.data.SamzaSqlRelMsgMetadata)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GenericData (org.apache.avro.generic.GenericData)2 ByteString (org.apache.calcite.avatica.util.ByteString)2 SamzaException (org.apache.samza.SamzaException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 Collectors (java.util.stream.Collectors)1 GenericRecord (org.apache.avro.generic.GenericRecord)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1