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);
}
}
Aggregations