Search in sources :

Example 6 with Extractor

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();
}
Also used : GeneratedRowWriter(com.amazonaws.athena.connector.lambda.data.writers.GeneratedRowWriter) BigIntExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.BigIntExtractor) DecimalExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.DecimalExtractor) DateDayExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.DateDayExtractor) TinyIntExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.TinyIntExtractor) VarBinaryExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.VarBinaryExtractor) BitExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.BitExtractor) IntExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.IntExtractor) Extractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.Extractor) Float8Extractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.Float8Extractor) SmallIntExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.SmallIntExtractor) VarCharExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.VarCharExtractor) Float4Extractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.Float4Extractor) DateMilliExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.DateMilliExtractor)

Example 7 with Extractor

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;
    });
}
Also used : TimeSeriesDataPoint(com.amazonaws.services.timestreamquery.model.TimeSeriesDataPoint) Datum(com.amazonaws.services.timestreamquery.model.Datum) HashMap(java.util.HashMap) ConstraintProjector(com.amazonaws.athena.connector.lambda.domain.predicate.ConstraintProjector) ArrayList(java.util.ArrayList) FieldVector(org.apache.arrow.vector.FieldVector) Field(org.apache.arrow.vector.types.pojo.Field) BigIntExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.BigIntExtractor) BitExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.BitExtractor) Float8Extractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.Float8Extractor) VarCharExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.VarCharExtractor) DateMilliExtractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.DateMilliExtractor) Extractor(com.amazonaws.athena.connector.lambda.data.writers.extractors.Extractor) Row(com.amazonaws.services.timestreamquery.model.Row) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BigIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.BigIntExtractor)7 BitExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.BitExtractor)7 DateMilliExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.DateMilliExtractor)7 Extractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.Extractor)7 Float8Extractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.Float8Extractor)7 VarCharExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.VarCharExtractor)7 Float4Extractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.Float4Extractor)6 IntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.IntExtractor)6 SmallIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.SmallIntExtractor)6 TinyIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.TinyIntExtractor)6 DateDayExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.DateDayExtractor)5 DecimalExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.DecimalExtractor)5 VarBinaryExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.VarBinaryExtractor)5 Field (org.apache.arrow.vector.types.pojo.Field)5 ConstraintProjector (com.amazonaws.athena.connector.lambda.domain.predicate.ConstraintProjector)4 FieldVector (org.apache.arrow.vector.FieldVector)3 GeneratedRowWriter (com.amazonaws.athena.connector.lambda.data.writers.GeneratedRowWriter)2 FieldWriter (com.amazonaws.athena.connector.lambda.data.writers.fieldwriters.FieldWriter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2