use of org.apache.druid.segment.transform.ExpressionTransform in project druid by druid-io.
the class SqlFirehoseTest method testFirehoseTransformingParser.
@Test
public void testFirehoseTransformingParser() throws Exception {
final TestCloseable closeable = new TestCloseable();
List<Object> expectedResults = new ArrayList<>();
for (Map<String, Object> map : inputs) {
expectedResults.add(map.get("x") + "foo");
}
final List<JsonIterator<Map<String, Object>>> lineIterators = fileList.stream().map(s -> new JsonIterator<Map<String, Object>>(TYPE_REF, s, closeable, objectMapper)).collect(Collectors.toList());
final InputRowParser stringParser = new TransformingStringInputRowParser(new TimeAndDimsParseSpec(new TimestampSpec("timestamp", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("x")))), Charset.defaultCharset().name(), new TransformSpec(null, ImmutableList.of(new ExpressionTransform("xfoo", "concat(x,'foo')", ExprMacroTable.nil()))));
try (final SqlFirehose firehose = new SqlFirehose(lineIterators.iterator(), stringParser, closeable)) {
final List<Object> results = new ArrayList<>();
while (firehose.hasMore()) {
final InputRow inputRow = firehose.nextRow();
if (inputRow == null) {
results.add(null);
} else {
results.add(inputRow.getDimension("xfoo").get(0));
}
}
Assert.assertEquals(expectedResults, results);
}
}
use of org.apache.druid.segment.transform.ExpressionTransform in project druid by druid-io.
the class LookupSerdeModuleTest method testExpressionTransformSerde.
@Test
public void testExpressionTransformSerde() throws Exception {
final ExpressionTransform transform = new ExpressionTransform("xxx", "lookup(xxx, 'beep')", injector.getInstance(ExprMacroTable.class));
Assert.assertEquals(transform, objectMapper.readValue(objectMapper.writeValueAsBytes(transform), ExpressionTransform.class));
}
Aggregations