use of org.apache.drill.exec.vector.accessor.ColumnWriter in project drill by apache.
the class TupleWriterImpl method setArray.
public void setArray(int colIndex, Object value) {
if (value == null) {
return;
}
String objClass = value.getClass().getName();
if (!objClass.startsWith("[")) {
throw new IllegalArgumentException("Argument is not an array");
}
ColumnWriter colWriter = column(colIndex);
if (colWriter.valueType() != ValueType.ARRAY) {
throw new IllegalArgumentException("Column is not an array");
}
ArrayWriter arrayWriter = colWriter.array();
// Figure out type
char second = objClass.charAt(1);
switch(second) {
case 'B':
AccessorUtilities.setByteArray(arrayWriter, (byte[]) value);
break;
case 'S':
AccessorUtilities.setShortArray(arrayWriter, (short[]) value);
break;
case 'I':
AccessorUtilities.setIntArray(arrayWriter, (int[]) value);
break;
case 'J':
AccessorUtilities.setLongArray(arrayWriter, (long[]) value);
break;
case 'F':
AccessorUtilities.setFloatArray(arrayWriter, (float[]) value);
break;
case 'D':
AccessorUtilities.setDoubleArray(arrayWriter, (double[]) value);
break;
case 'Z':
AccessorUtilities.setBooleanArray(arrayWriter, (boolean[]) value);
break;
case 'L':
int posn = objClass.indexOf(';');
// If the array is of type Object, then we have no type info.
String memberClassName = objClass.substring(2, posn);
if (memberClassName.equals(String.class.getName())) {
AccessorUtilities.setStringArray(arrayWriter, (String[]) value);
} else if (memberClassName.equals(Period.class.getName())) {
AccessorUtilities.setPeriodArray(arrayWriter, (Period[]) value);
} else if (memberClassName.equals(BigDecimal.class.getName())) {
AccessorUtilities.setBigDecimalArray(arrayWriter, (BigDecimal[]) value);
} else {
throw new IllegalArgumentException("Unknown Java array type: " + memberClassName);
}
break;
default:
throw new IllegalArgumentException("Unknown Java array type: " + second);
}
}
Aggregations