Search in sources :

Example 1 with ByteArrayPointable

use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.

the class ByteArrayNormalizedKeyComputerFactoryTest method testRandomNormalizedKey.

@Test
public void testRandomNormalizedKey() {
    for (int i = 0; i < 10; ++i) {
        ByteArrayPointable pointable1 = generateRandomByteArrayPointableWithFixLength(Math.abs(random.nextInt((i + 1) * 10)), random);
        ByteArrayPointable pointable2 = generateRandomByteArrayPointableWithFixLength(Math.abs(random.nextInt((i + 1) * 10)), random);
        assertNormalizeValue(pointable1, pointable2, computer);
    }
}
Also used : ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable) Test(org.junit.Test)

Example 2 with ByteArrayPointable

use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.

the class ByteArrayBase64ParserFactoryTest method testOneString.

void testOneString(String test) throws HyracksDataException {
    IValueParser parser = ByteArrayBase64ParserFactory.INSTANCE.createValueParser();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream outputStream = new DataOutputStream(bos);
    ByteArrayPointable bytePtr = new ByteArrayPointable();
    parser.parse(test.toCharArray(), 0, test.length(), outputStream);
    bytePtr.set(bos.toByteArray(), 0, bos.size());
    byte[] answer = DatatypeConverter.parseBase64Binary(test);
    assertTrue(bytePtr.getContentLength() == answer.length);
    assertTrue(Arrays.equals(answer, copyContent(bytePtr)));
}
Also used : ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with ByteArrayPointable

use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.

the class ByteArrayNormalizedKeyComputerFactoryTest method testCornerCase.

@Test
public void testCornerCase() {
    for (int len = 0; len < 4; ++len) {
        ByteArrayPointable pointable1 = generateRandomByteArrayPointableWithFixLength(len, random);
        ByteArrayPointable pointable2 = generateRandomByteArrayPointableWithFixLength(len, random);
        assertNormalizeValue(pointable1, pointable2, computer);
    }
    ByteArrayPointable ptr1 = ByteArrayPointable.generatePointableFromPureBytes(new byte[] { 0, 25, 34, 42 });
    ByteArrayPointable ptr2 = ByteArrayPointable.generatePointableFromPureBytes(new byte[] { (byte) 130, 25, 34, 42 });
    int n1 = computer.normalize(ptr1.getByteArray(), ptr1.getStartOffset(), ptr1.getLength());
    int n2 = computer.normalize(ptr2.getByteArray(), ptr2.getStartOffset(), ptr2.getLength());
    assertTrue(n1 < n2);
}
Also used : ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable) Test(org.junit.Test)

Example 4 with ByteArrayPointable

use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.

the class ByteArrayHexParserFactoryTest method testOneString.

void testOneString(String test) throws HyracksDataException {
    IValueParser parser = ByteArrayHexParserFactory.INSTANCE.createValueParser();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream outputStream = new DataOutputStream(bos);
    ByteArrayPointable bytePtr = new ByteArrayPointable();
    parser.parse(test.toCharArray(), 0, test.length(), outputStream);
    bytePtr.set(bos.toByteArray(), 0, bos.size());
    assertTrue(bytePtr.getContentLength() == test.length() / 2);
    assertEquals(DatatypeConverter.printHexBinary(ByteArrayPointable.copyContent(bytePtr)).toLowerCase(), test.toLowerCase());
}
Also used : ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with ByteArrayPointable

use of org.apache.hyracks.data.std.primitive.ByteArrayPointable in project asterixdb by apache.

the class ABinaryPrinterTest method generateABinaryBytesByStringContent.

public static byte[] generateABinaryBytesByStringContent(String content) {
    byte[] bytes = DatatypeConverter.parseHexBinary(content);
    ByteArrayPointable ptr = ByteArrayPointable.generatePointableFromPureBytes(bytes);
    byte[] ret = new byte[ptr.getLength() + 1];
    System.arraycopy(ptr.getByteArray(), ptr.getStartOffset(), ret, 1, ptr.getLength());
    return ret;
}
Also used : ByteArrayPointable(org.apache.hyracks.data.std.primitive.ByteArrayPointable)

Aggregations

ByteArrayPointable (org.apache.hyracks.data.std.primitive.ByteArrayPointable)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ATypeTag (org.apache.asterix.om.types.ATypeTag)1 UnsupportedItemTypeException (org.apache.asterix.runtime.exceptions.UnsupportedItemTypeException)1 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 IPointable (org.apache.hyracks.data.std.api.IPointable)1 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)1 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)1 UTF8StringWriter (org.apache.hyracks.util.string.UTF8StringWriter)1