Search in sources :

Example 1 with VectorHashKeyWrapperBatch

use of org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBatch in project hive by apache.

the class TestVectorHashKeyWrapperBatch method testVectorHashKeyWrapperBatch.

// Specific test for HIVE-18744 --
// Tests Timestamp assignment.
@Test
public void testVectorHashKeyWrapperBatch() throws HiveException {
    VectorExpression[] keyExpressions = new VectorExpression[] { new IdentityExpression(0) };
    TypeInfo[] typeInfos = new TypeInfo[] { TypeInfoFactory.timestampTypeInfo };
    VectorHashKeyWrapperBatch vhkwb = VectorHashKeyWrapperBatch.compileKeyWrapperBatch(keyExpressions, typeInfos);
    VectorizedRowBatch batch = new VectorizedRowBatch(1);
    batch.selectedInUse = false;
    batch.size = 10;
    TimestampColumnVector timestampColVector = new TimestampColumnVector(batch.DEFAULT_SIZE);
    ;
    batch.cols[0] = timestampColVector;
    timestampColVector.reset();
    // Cause Timestamp object to be replaced (in buggy code) with ZERO_TIMESTAMP.
    timestampColVector.noNulls = false;
    timestampColVector.isNull[0] = true;
    Timestamp scratch = new Timestamp(2039);
    Timestamp ts0 = new Timestamp(2039);
    scratch.setTime(ts0.getTime());
    scratch.setNanos(ts0.getNanos());
    timestampColVector.set(1, scratch);
    Timestamp ts1 = new Timestamp(33222);
    scratch.setTime(ts1.getTime());
    scratch.setNanos(ts1.getNanos());
    timestampColVector.set(2, scratch);
    batch.size = 3;
    vhkwb.evaluateBatch(batch);
    VectorHashKeyWrapperBase[] vhkwArray = vhkwb.getVectorHashKeyWrappers();
    VectorHashKeyWrapperBase vhk = vhkwArray[0];
    assertTrue(vhk.isNull(0));
    vhk = vhkwArray[1];
    assertFalse(vhk.isNull(0));
    assertEquals(vhk.getTimestamp(0), ts0);
    vhk = vhkwArray[2];
    assertFalse(vhk.isNull(0));
    assertEquals(vhk.getTimestamp(0), ts1);
}
Also used : VectorHashKeyWrapperBase(org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBase) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) IdentityExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.IdentityExpression) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) VectorHashKeyWrapperBatch(org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBatch) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 2 with VectorHashKeyWrapperBatch

use of org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBatch in project hive by apache.

the class TestVectorHashKeyWrapperBatch method testVectorHashKeyWrapperGeneralCopyKey.

// Test for HIVE-24575
@Test
public void testVectorHashKeyWrapperGeneralCopyKey() throws HiveException {
    VectorExpression[] keyExpressions = new VectorExpression[] { new IdentityExpression(0) };
    TypeInfo[] typeInfos = new TypeInfo[] { TypeInfoFactory.stringTypeInfo };
    VectorHashKeyWrapperBatch vhkwb = VectorHashKeyWrapperBatch.compileKeyWrapperBatch(keyExpressions, typeInfos);
    VectorizedRowBatch batch = new VectorizedRowBatch(1);
    batch.selectedInUse = false;
    BytesColumnVector bytesColumnVector = new BytesColumnVector();
    bytesColumnVector.initBuffer(1024);
    batch.cols[0] = bytesColumnVector;
    byte[] contents = "education_reference".getBytes();
    bytesColumnVector.setVal(0, "system_management".getBytes());
    bytesColumnVector.setVal(1, "travel_transportation".getBytes());
    bytesColumnVector.setVal(2, contents);
    bytesColumnVector.setVal(3, "app_management".getBytes());
    batch.size = 4;
    vhkwb.evaluateBatch(batch);
    VectorHashKeyWrapperBase[] vhkwArray = vhkwb.getVectorHashKeyWrappers();
    VectorHashKeyWrapperGeneral hashKey2 = (VectorHashKeyWrapperGeneral) vhkwArray[2];
    VectorHashKeyWrapperGeneral hashKey1 = (VectorHashKeyWrapperGeneral) vhkwArray[1];
    assertTrue(StringExpr.equal(hashKey2.getBytes(0), hashKey2.getByteStart(0), hashKey2.getByteLength(0), contents, 0, contents.length));
    assertFalse(StringExpr.equal(hashKey2.getBytes(0), hashKey2.getByteStart(0), hashKey2.getByteLength(0), hashKey1.getBytes(0), hashKey1.getByteStart(0), hashKey1.getByteLength(0)));
    hashKey2.copyKey(hashKey1);
    assertTrue(StringExpr.equal(hashKey2.getBytes(0), hashKey2.getByteStart(0), hashKey2.getByteLength(0), contents, 0, contents.length));
    assertTrue(StringExpr.equal(hashKey2.getBytes(0), hashKey2.getByteStart(0), hashKey2.getByteLength(0), hashKey1.getBytes(0), hashKey1.getByteStart(0), hashKey1.getByteLength(0)));
}
Also used : VectorHashKeyWrapperBase(org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBase) VectorHashKeyWrapperGeneral(org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperGeneral) VectorExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression) IdentityExpression(org.apache.hadoop.hive.ql.exec.vector.expressions.IdentityExpression) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) VectorHashKeyWrapperBatch(org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBatch) Test(org.junit.Test)

Aggregations

IdentityExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.IdentityExpression)2 VectorExpression (org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression)2 VectorHashKeyWrapperBase (org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBase)2 VectorHashKeyWrapperBatch (org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperBatch)2 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)2 Test (org.junit.Test)2 Timestamp (java.sql.Timestamp)1 VectorHashKeyWrapperGeneral (org.apache.hadoop.hive.ql.exec.vector.wrapper.VectorHashKeyWrapperGeneral)1