use of com.amazonaws.athena.connector.lambda.data.writers.extractors.Extractor in project aws-athena-query-federation by awslabs.
the class UserDefinedFunctionHandler method createOutputRowWriter.
private GeneratedRowWriter createOutputRowWriter(Field outputField, List<ArrowValueProjector> valueProjectors, Method udfMethod) {
GeneratedRowWriter.RowWriterBuilder builder = GeneratedRowWriter.newBuilder();
Extractor extractor = makeExtractor(outputField, valueProjectors, udfMethod);
if (extractor != null) {
builder.withExtractor(outputField.getName(), extractor);
} else {
builder.withFieldWriterFactory(outputField.getName(), makeFactory(outputField, valueProjectors, udfMethod));
}
return builder.build();
}
use of com.amazonaws.athena.connector.lambda.data.writers.extractors.Extractor in project aws-athena-query-federation by awslabs.
the class TimestreamRecordHandler method buildTimeSeriesExtractor.
private void buildTimeSeriesExtractor(GeneratedRowWriter.RowWriterBuilder builder, Field field, int curFieldNum) {
builder.withFieldWriterFactory(field.getName(), (FieldVector vector, Extractor extractor, ConstraintProjector constraint) -> (Object context, int rowNum) -> {
Row row = (Row) context;
Datum datum = row.getData().get(curFieldNum);
Field timeField = field.getChildren().get(0).getChildren().get(0);
Field valueField = field.getChildren().get(0).getChildren().get(1);
if (datum.getTimeSeriesValue() != null) {
List<Map<String, Object>> values = new ArrayList<>();
for (TimeSeriesDataPoint nextDatum : datum.getTimeSeriesValue()) {
Map<String, Object> eventMap = new HashMap<>();
eventMap.put(timeField.getName(), TIMESTAMP_FORMATTER.parse(nextDatum.getTime()).getTime());
switch(Types.getMinorTypeForArrowType(valueField.getType())) {
case FLOAT8:
eventMap.put(valueField.getName(), Double.valueOf(nextDatum.getValue().getScalarValue()));
break;
case BIGINT:
eventMap.put(valueField.getName(), Long.valueOf(nextDatum.getValue().getScalarValue()));
break;
case INT:
eventMap.put(valueField.getName(), Integer.valueOf(nextDatum.getValue().getScalarValue()));
break;
case BIT:
eventMap.put(valueField.getName(), Boolean.valueOf(((Row) context).getData().get(curFieldNum).getScalarValue()) == false ? 0 : 1);
break;
}
values.add(eventMap);
}
BlockUtils.setComplexValue(vector, rowNum, FieldResolver.DEFAULT, values);
} else {
throw new RuntimeException("Only LISTs of type TimeSeries are presently supported.");
}
// we don't yet support predicate pushdown on complex types
return true;
});
}
Aggregations