use of com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarBinaryHolder in project aws-athena-query-federation by awslabs.
the class ExampleRecordHandler method makeExtractor.
/**
* Creates an Extractor for the given field. In this example the extractor just creates some random data.
*/
private Extractor makeExtractor(Field field, RowContext rowContext) {
Types.MinorType fieldType = Types.getMinorTypeForArrowType(field.getType());
// they need to match the split otherwise filtering will brake in unexpected ways.
if (field.getName().equals("year")) {
return (IntExtractor) (Object context, NullableIntHolder dst) -> {
dst.isSet = 1;
dst.value = rowContext.getYear();
};
} else if (field.getName().equals("month")) {
return (IntExtractor) (Object context, NullableIntHolder dst) -> {
dst.isSet = 1;
dst.value = rowContext.getMonth();
};
} else if (field.getName().equals("day")) {
return (IntExtractor) (Object context, NullableIntHolder dst) -> {
dst.isSet = 1;
dst.value = rowContext.getDay();
};
}
switch(fieldType) {
case INT:
return (IntExtractor) (Object context, NullableIntHolder dst) -> {
dst.isSet = 1;
dst.value = ((RowContext) context).seed * (((RowContext) context).negative ? -1 : 1);
};
case DATEMILLI:
return (DateMilliExtractor) (Object context, NullableDateMilliHolder dst) -> {
dst.isSet = 1;
dst.value = ((RowContext) context).seed * (((RowContext) context).negative ? -1 : 1);
};
case DATEDAY:
return (DateDayExtractor) (Object context, NullableDateDayHolder dst) -> {
dst.isSet = 1;
dst.value = ((RowContext) context).seed * (((RowContext) context).negative ? -1 : 1);
};
case TINYINT:
return (TinyIntExtractor) (Object context, NullableTinyIntHolder dst) -> {
dst.isSet = 1;
dst.value = (byte) ((((RowContext) context).seed % 4) * (((RowContext) context).negative ? -1 : 1));
};
case SMALLINT:
return (SmallIntExtractor) (Object context, NullableSmallIntHolder dst) -> {
dst.isSet = 1;
dst.value = (short) ((((RowContext) context).seed % 4) * (((RowContext) context).negative ? -1 : 1));
};
case FLOAT4:
return (Float4Extractor) (Object context, NullableFloat4Holder dst) -> {
dst.isSet = 1;
dst.value = ((float) ((RowContext) context).seed) * 1.1f * (((RowContext) context).negative ? -1f : 1f);
};
case FLOAT8:
return (Float8Extractor) (Object context, NullableFloat8Holder dst) -> {
dst.isSet = 1;
dst.value = ((double) ((RowContext) context).seed) * 1.1D;
};
case DECIMAL:
return (DecimalExtractor) (Object context, NullableDecimalHolder dst) -> {
dst.isSet = 1;
double d8Val = ((RowContext) context).seed * 1.1D * (((RowContext) context).negative ? -1d : 1d);
BigDecimal bdVal = new BigDecimal(d8Val);
dst.value = bdVal.setScale(((ArrowType.Decimal) field.getType()).getScale(), RoundingMode.HALF_UP);
};
case BIT:
return (BitExtractor) (Object context, NullableBitHolder dst) -> {
dst.isSet = 1;
dst.value = ((RowContext) context).seed % 2;
};
case BIGINT:
return (BigIntExtractor) (Object context, NullableBigIntHolder dst) -> {
dst.isSet = 1;
dst.value = ((RowContext) context).seed * 1L * (((RowContext) context).negative ? -1 : 1);
};
case VARCHAR:
return (VarCharExtractor) (Object context, NullableVarCharHolder dst) -> {
dst.isSet = 1;
dst.value = "VarChar" + ((RowContext) context).seed;
};
case VARBINARY:
return (VarBinaryExtractor) (Object context, NullableVarBinaryHolder dst) -> {
dst.isSet = 1;
dst.value = ("VarChar" + ((RowContext) context).seed).getBytes(Charsets.UTF_8);
};
default:
return null;
}
}
use of com.amazonaws.athena.connector.lambda.data.writers.holders.NullableVarBinaryHolder 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