Search in sources :

Example 11 with VarCharHolder

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;
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

Example 12 with VarCharHolder

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;
    }
}
Also used : BitHolder(org.apache.drill.exec.expr.holders.BitHolder) VarDecimalHolder(org.apache.drill.exec.expr.holders.VarDecimalHolder) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

Example 13 with VarCharHolder

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;
}
Also used : BaseWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter) DataMode(org.apache.drill.common.types.TypeProtos.DataMode) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder) FieldReader(org.apache.drill.exec.vector.complex.reader.FieldReader)

Example 14 with VarCharHolder

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);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

Example 15 with VarCharHolder

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;
}
Also used : VarCharHolder(org.apache.drill.exec.expr.holders.VarCharHolder)

Aggregations

VarCharHolder (org.apache.drill.exec.expr.holders.VarCharHolder)36 Test (org.junit.Test)23 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)20 VectorTest (org.apache.drill.categories.VectorTest)20 ExecTest (org.apache.drill.exec.ExecTest)20 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)5 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)4 FieldReader (org.apache.drill.exec.vector.complex.reader.FieldReader)4 BaseWriter (org.apache.drill.exec.vector.complex.writer.BaseWriter)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 PhysicalPlan (org.apache.drill.exec.physical.PhysicalPlan)3 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)3 PhysicalPlanReader (org.apache.drill.exec.planner.PhysicalPlanReader)3 VarCharVector (org.apache.drill.exec.vector.VarCharVector)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 BitHolder (org.apache.drill.exec.expr.holders.BitHolder)2 VarDecimalHolder (org.apache.drill.exec.expr.holders.VarDecimalHolder)2 DrillBuf (io.netty.buffer.DrillBuf)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1