Search in sources :

Example 6 with NullableVarCharHolder

use of com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarCharHolder in project aws-athena-query-federation by awslabs.

the class VerticaRecordHandler method makeExtractor.

/**
 * Creates an Extractor for the given field.
 */
private Extractor makeExtractor(Field field, HashMap<String, Types.MinorType> mapOfNamesAndTypes, HashMap<String, Object> mapOfcols) {
    String fieldName = field.getName();
    Types.MinorType fieldType = mapOfNamesAndTypes.get(fieldName);
    switch(fieldType) {
        case BIT:
            return (BitExtractor) (Object context, NullableBitHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = ((boolean) value) ? 1 : 0;
                    dst.isSet = 1;
                }
            };
        case TINYINT:
            return (TinyIntExtractor) (Object context, NullableTinyIntHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = Byte.parseByte(value.toString());
                    dst.isSet = 1;
                }
            };
        case SMALLINT:
            return (SmallIntExtractor) (Object context, NullableSmallIntHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = Short.parseShort(value.toString());
                    dst.isSet = 1;
                }
            };
        case INT:
        case BIGINT:
            return (BigIntExtractor) (Object context, NullableBigIntHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = Long.parseLong(value.toString());
                    dst.isSet = 1;
                }
            };
        case FLOAT4:
            return (Float4Extractor) (Object context, NullableFloat4Holder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = Float.parseFloat(value.toString());
                    dst.isSet = 1;
                }
            };
        case FLOAT8:
            return (Float8Extractor) (Object context, NullableFloat8Holder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = Double.parseDouble(value.toString());
                    dst.isSet = 1;
                }
            };
        case DECIMAL:
            return (DecimalExtractor) (Object context, NullableDecimalHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = new BigDecimal(value.toString());
                    dst.isSet = 1;
                }
            };
        case DATEDAY:
            return (DateDayExtractor) (Object context, NullableDateDayHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.isSet = 1;
                    dst.value = (int) LocalDate.parse(value.toString()).toEpochDay();
                }
            };
        case DATEMILLI:
            return (DateMilliExtractor) (Object context, NullableDateMilliHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName).toString();
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = LocalDateTime.parse(value.toString()).atZone(BlockUtils.UTC_ZONE_ID).toInstant().toEpochMilli();
                    dst.isSet = 1;
                }
            };
        case VARCHAR:
            return (VarCharExtractor) (Object context, NullableVarCharHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName);
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = value.toString();
                    dst.isSet = 1;
                }
            };
        case VARBINARY:
            return (VarBinaryExtractor) (Object context, NullableVarBinaryHolder dst) -> {
                Object value = ((RowContext) context).getNameValue().get(fieldName).toString();
                if (value == null) {
                    dst.isSet = 0;
                } else {
                    dst.value = value.toString().getBytes();
                    dst.isSet = 1;
                }
            };
        default:
            throw new RuntimeException("Unhandled type " + fieldType);
    }
}
Also used : Types(org.apache.arrow.vector.types.Types) NullableVarBinaryHolder(com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarBinaryHolder) NullableVarCharHolder(com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarCharHolder) NullableDecimalHolder(com.amazonaws.athena.connector.lambda.data.writers.holders.NullableDecimalHolder) BigDecimal(java.math.BigDecimal)

Aggregations

NullableVarCharHolder (com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarCharHolder)6 NullableBigIntHolder (org.apache.arrow.vector.holders.NullableBigIntHolder)5 NullableBitHolder (org.apache.arrow.vector.holders.NullableBitHolder)5 NullableFloat8Holder (org.apache.arrow.vector.holders.NullableFloat8Holder)5 NullableFloat4Holder (org.apache.arrow.vector.holders.NullableFloat4Holder)4 NullableIntHolder (org.apache.arrow.vector.holders.NullableIntHolder)4 Types (org.apache.arrow.vector.types.Types)4 NullableDateMilliHolder (org.apache.arrow.vector.holders.NullableDateMilliHolder)3 BigIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.BigIntExtractor)2 BitExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.BitExtractor)2 DateMilliExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.DateMilliExtractor)2 Float4Extractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.Float4Extractor)2 Float8Extractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.Float8Extractor)2 IntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.IntExtractor)2 SmallIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.SmallIntExtractor)2 TinyIntExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.TinyIntExtractor)2 VarCharExtractor (com.amazonaws.athena.connector.lambda.data.writers.extractors.VarCharExtractor)2 NullableDecimalHolder (com.amazonaws.athena.connector.lambda.data.writers.holders.NullableDecimalHolder)2 NullableVarBinaryHolder (com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarBinaryHolder)2 BigDecimal (java.math.BigDecimal)2