Search in sources :

Example 1 with PArrayDataTypeEncoder

use of org.apache.phoenix.schema.types.PArrayDataTypeEncoder in project phoenix by apache.

the class ArrayConstructorExpression method evaluate.

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    if (position == elements.length) {
        ptr.set(valuePtr.get(), valuePtr.getOffset(), valuePtr.getLength());
        return true;
    }
    TrustedByteArrayOutputStream byteStream = new TrustedByteArrayOutputStream(estimatedSize);
    DataOutputStream oStream = new DataOutputStream(byteStream);
    PArrayDataTypeEncoder builder = new PArrayDataTypeEncoder(byteStream, oStream, children.size(), baseType, getSortOrder(), rowKeyOrderOptimizable, PArrayDataType.SORTABLE_SERIALIZATION_VERSION);
    for (int i = position >= 0 ? position : 0; i < elements.length; i++) {
        Expression child = children.get(i);
        if (!child.evaluate(tuple, ptr)) {
            if (tuple != null && !tuple.isImmutable()) {
                if (position >= 0)
                    position = i;
                return false;
            }
        } else {
            builder.appendValue(ptr.get(), ptr.getOffset(), ptr.getLength());
        }
    }
    if (position >= 0)
        position = elements.length;
    byte[] bytes = builder.encode();
    ptr.set(bytes, 0, bytes.length);
    valuePtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
    return true;
}
Also used : PArrayDataTypeEncoder(org.apache.phoenix.schema.types.PArrayDataTypeEncoder) DataOutputStream(java.io.DataOutputStream) TrustedByteArrayOutputStream(org.apache.phoenix.util.TrustedByteArrayOutputStream)

Example 2 with PArrayDataTypeEncoder

use of org.apache.phoenix.schema.types.PArrayDataTypeEncoder in project phoenix by apache.

the class JONIPattern method split.

private boolean split(byte[] srcBytes, int srcOffset, int srcLen, ImmutableBytesWritable outPtr) {
    SortOrder sortOrder = SortOrder.ASC;
    PArrayDataTypeEncoder builder = new PArrayDataTypeEncoder(PVarchar.INSTANCE, sortOrder);
    int srcRange = srcOffset + srcLen;
    Matcher matcher = pattern.matcher(srcBytes, 0, srcRange);
    int cur = srcOffset;
    boolean append;
    while (true) {
        int nextCur = matcher.search(cur, srcRange, Option.DEFAULT);
        if (nextCur < 0) {
            builder.appendValue(srcBytes, cur, srcRange - cur);
            break;
        }
        // REGEXP_SPLIT("12ONE34TWO56THREE78","[0-9]+")={null, "ONE", "TWO", "THREE", null}
        if (cur == matcher.getBegin()) {
            builder.appendValue(srcBytes, cur, 0);
        }
        if (cur < matcher.getBegin()) {
            builder.appendValue(srcBytes, cur, matcher.getBegin() - cur);
        }
        cur = matcher.getEnd();
        // REGEXP_SPLIT("12ONE34TWO56THREE78","[0-9]+")={null, "ONE", "TWO", "THREE", null}
        if (cur == srcRange) {
            builder.appendValue(srcBytes, cur, 0);
            break;
        }
    }
    byte[] bytes = builder.encode();
    if (bytes == null)
        return false;
    outPtr.set(bytes);
    return true;
}
Also used : PArrayDataTypeEncoder(org.apache.phoenix.schema.types.PArrayDataTypeEncoder) Matcher(org.joni.Matcher) SortOrder(org.apache.phoenix.schema.SortOrder)

Aggregations

PArrayDataTypeEncoder (org.apache.phoenix.schema.types.PArrayDataTypeEncoder)2 DataOutputStream (java.io.DataOutputStream)1 SortOrder (org.apache.phoenix.schema.SortOrder)1 TrustedByteArrayOutputStream (org.apache.phoenix.util.TrustedByteArrayOutputStream)1 Matcher (org.joni.Matcher)1