use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by axbaretto.
the class ValueHolderHelper method getVarCharHolder.
public static VarCharHolder getVarCharHolder(BufferAllocator a, String s) {
VarCharHolder vch = new VarCharHolder();
byte[] b = s.getBytes(Charsets.UTF_8);
vch.start = 0;
vch.end = b.length;
//
vch.buffer = a.buffer(b.length);
vch.buffer.setBytes(0, b);
return vch;
}
use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.
the class FilterBuilder method getValueExpressionFromConst.
private LogicalExpression getValueExpressionFromConst(ValueHolder holder, TypeProtos.MinorType type) {
switch(type) {
case INT:
return ValueExpressions.getInt(((IntHolder) holder).value);
case BIGINT:
return ValueExpressions.getBigInt(((BigIntHolder) holder).value);
case FLOAT4:
return ValueExpressions.getFloat4(((Float4Holder) holder).value);
case FLOAT8:
return ValueExpressions.getFloat8(((Float8Holder) holder).value);
case VARDECIMAL:
VarDecimalHolder decimalHolder = (VarDecimalHolder) holder;
return ValueExpressions.getVarDecimal(DecimalUtility.getBigDecimalFromDrillBuf(decimalHolder.buffer, decimalHolder.start, decimalHolder.end - decimalHolder.start, decimalHolder.scale), decimalHolder.precision, decimalHolder.scale);
case DATE:
return ValueExpressions.getDate(((DateHolder) holder).value);
case TIMESTAMP:
return ValueExpressions.getTimeStamp(((TimeStampHolder) holder).value);
case TIME:
return ValueExpressions.getTime(((TimeHolder) holder).value);
case BIT:
return ValueExpressions.getBit(((BitHolder) holder).value == 1);
case VARCHAR:
VarCharHolder varCharHolder = (VarCharHolder) holder;
String value = StringFunctionHelpers.toStringFromUTF8(varCharHolder.start, varCharHolder.end, varCharHolder.buffer);
return ValueExpressions.getChar(value, value.length());
default:
return null;
}
}
use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.
the class ComplexSchemaUtils method getFields.
public static DrillBuf getFields(FieldReader reader, BaseWriter.ComplexWriter outWriter, DrillBuf buffer) {
BaseWriter.MapWriter queryMapWriter = outWriter.rootAsMap();
if (reader.getType().getMinorType() != MinorType.MAP) {
// If the field is not a map, return an empty map
queryMapWriter.start();
queryMapWriter.end();
}
Iterator<String> fieldIterator = reader.iterator();
queryMapWriter.start();
while (fieldIterator.hasNext()) {
String fieldName = fieldIterator.next();
FieldReader fieldReader = reader.reader(fieldName);
String dataType = fieldReader.getType().getMinorType().toString();
DataMode dataMode = fieldReader.getType().getMode();
if (dataMode == DataMode.REPEATED) {
dataType = dataMode + "_" + dataType;
}
VarCharHolder rowHolder = new VarCharHolder();
byte[] rowStringBytes = dataType.getBytes();
buffer = buffer.reallocIfNeeded(rowStringBytes.length);
buffer.setBytes(0, rowStringBytes);
rowHolder.start = 0;
rowHolder.end = rowStringBytes.length;
rowHolder.buffer = buffer;
queryMapWriter.varChar(fieldName).write(rowHolder);
}
queryMapWriter.end();
return buffer;
}
use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.
the class BsonRecordReader method writeString.
private void writeString(String readString, final MapOrListWriterImpl writer, String fieldName, boolean isList) {
int length;
byte[] strBytes;
try {
strBytes = readString.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new DrillRuntimeException("Unable to read string value for field: " + fieldName, e);
}
length = strBytes.length;
ensure(length);
workBuf.setBytes(0, strBytes);
final VarCharHolder vh = new VarCharHolder();
vh.buffer = workBuf;
vh.start = 0;
vh.end = length;
if (isList == false) {
writer.varChar(fieldName).write(vh);
} else {
writer.list.varChar().write(vh);
}
}
use of org.apache.drill.exec.expr.holders.VarCharHolder in project drill by apache.
the class ValueHolderHelper method getVarCharHolder.
public static VarCharHolder getVarCharHolder(BufferAllocator a, String s) {
VarCharHolder vch = new VarCharHolder();
byte[] b = s.getBytes(Charsets.UTF_8);
vch.start = 0;
vch.end = b.length;
vch.buffer = a.buffer(b.length);
vch.buffer.setBytes(0, b);
return vch;
}
Aggregations