use of com.amazonaws.services.timestreamquery.model.TimeSeriesDataPoint 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;
});
}
use of com.amazonaws.services.timestreamquery.model.TimeSeriesDataPoint in project aws-athena-query-federation by awslabs.
the class TestUtils method buildTimeSeries.
private static void buildTimeSeries(Field field, Datum datum) {
List<TimeSeriesDataPoint> dataPoints = new ArrayList<>();
for (int i = 0; i < 10; i++) {
TimeSeriesDataPoint dataPoint = new TimeSeriesDataPoint();
Datum dataPointValue = new Datum();
dataPoint.setTime(TIMESTAMP_FORMATTER.format(new Date(System.currentTimeMillis() - RAND.nextInt(1_000_000))));
/**
* Presently we only support TimeSeries as LIST<STRUCT<DATEMILLISECONDS, DOUBLE|INT|FLOAT8|BIT|BIGINT>>
*/
Field struct = field.getChildren().get(0);
assertEquals(Types.MinorType.STRUCT, Types.getMinorTypeForArrowType(struct.getType()));
Field baseSeriesType = struct.getChildren().get(1);
switch(Types.getMinorTypeForArrowType(baseSeriesType.getType())) {
case FLOAT8:
dataPointValue.setScalarValue(String.valueOf(RAND.nextFloat()));
break;
case BIT:
dataPointValue.setScalarValue(String.valueOf(RAND.nextBoolean()));
break;
case INT:
dataPointValue.setScalarValue(String.valueOf(RAND.nextInt()));
break;
case BIGINT:
dataPointValue.setScalarValue(String.valueOf(RAND.nextLong()));
break;
}
dataPoint.setValue(dataPointValue);
dataPoints.add(dataPoint);
}
datum.setTimeSeriesValue(dataPoints);
}
Aggregations