public static void addRandomNulls(VectorizedRowBatch batch) { for (int i = 0; i != batch.numCols; i++) { addRandomNulls(batch.cols[i]); } }
@Test public void testLongScalarSubtractLongColWithNulls() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatchSingleLongVector( VectorizedRowBatch.DEFAULT_SIZE); LongColumnVector lcv = (LongColumnVector) batch.cols[0]; TestVectorizedRowBatch.addRandomNulls(lcv); LongScalarSubtractLongColumn expr = new LongScalarSubtractLongColumn(100, 0, 1); expr.evaluate(batch); //verify for (int i=0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) { if (!lcv.isNull[i]) { Assert.assertEquals(100 - i * 37, ((LongColumnVector)batch.cols[1]).vector[i]); } else { Assert.assertTrue(((LongColumnVector)batch.cols[1]).isNull[i]); } } Assert.assertFalse(((LongColumnVector)batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector)batch.cols[1]).isRepeating); TestVectorArithmeticExpressions.verifyLongNullDataVectorEntries( (LongColumnVector) batch.cols[1], batch.selected, batch.selectedInUse, batch.size); }
private void longColAddLongScalarCheckedWithNulls(boolean isChecked) throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatchSingleLongVector( VectorizedRowBatch.DEFAULT_SIZE); LongColumnVector lcv = (LongColumnVector) batch.cols[0]; LongColumnVector lcvOut = (LongColumnVector) batch.cols[1]; TestVectorizedRowBatch.addRandomNulls(lcv); VectorExpression expr; if (isChecked) { expr = new LongColAddLongScalarChecked(0, 23, 1); expr.setOutputTypeInfo(TypeInfoFactory.getPrimitiveTypeInfo("bigint")); } else { expr = new LongColAddLongScalar(0, 23, 1); } expr.evaluate(batch); // verify for (int i=0; i < VectorizedRowBatch.DEFAULT_SIZE; i++) { if (!lcv.isNull[i]) { Assert.assertEquals(i*37+23, lcvOut.vector[i]); } else { Assert.assertTrue(lcvOut.isNull[i]); } } Assert.assertFalse(lcvOut.noNulls); Assert.assertFalse(lcvOut.isRepeating); verifyLongNullDataVectorEntries(lcvOut, batch.selected, batch.selectedInUse, batch.size); }
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFWeekOfYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFWeekOfYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFWeekOfYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFWeekOfYear(batch, testType);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFYear(batch, testType);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFMinute(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMinute(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFMinute(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMinute(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMinute(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMinute(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMinute(batch, testType);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFSecond(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFSecond(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFSecond(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFSecond(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFSecond(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFSecond(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFSecond(batch, testType);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFDayOfMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFDayOfMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFDayOfMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFDayOfMonth(batch, testType);
Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch, testType); batch = getVectorizedRowBatch(boundaries, boundaries.length, testType); verifyUDFMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch, testType); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMonth(batch, testType);
private VectorizedRowBatch makeBatch() { VectorizedRowBatch batch = new VectorizedRowBatch(3); LongColumnVector lv = new LongColumnVector(); DoubleColumnVector dv = new DoubleColumnVector(); BytesColumnVector bv = new BytesColumnVector(); setSampleStringCol(bv); batch.cols[0] = lv; batch.cols[1] = dv; batch.cols[2] = bv; addRandomNulls(batch); return batch; }
@Test public void testVectorUDFMonth() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatch(new int[] {0}, VectorizedRowBatch.DEFAULT_SIZE); Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch); int[] boundaries = getAllBoundaries(); batch = getVectorizedRowBatch(boundaries, boundaries.length); verifyUDFMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMonth(batch); batch = getVectorizedRowBatch(new int[] {0}, 1); batch.cols[0].isRepeating = true; verifyUDFMonth(batch); batch.cols[0].noNulls = false; batch.cols[0].isNull[0] = true; verifyUDFMonth(batch); batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE); verifyUDFMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFMonth(batch); }
@Test public void testVectorUDFDayOfMonth() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatch(new int[] {0}, VectorizedRowBatch.DEFAULT_SIZE); Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFDayOfMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch); int[] boundaries = getAllBoundaries(); batch = getVectorizedRowBatch(boundaries, boundaries.length); verifyUDFDayOfMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFDayOfMonth(batch); batch = getVectorizedRowBatch(new int[] {0}, 1); batch.cols[0].isRepeating = true; verifyUDFDayOfMonth(batch); batch.cols[0].noNulls = false; batch.cols[0].isNull[0] = true; verifyUDFDayOfMonth(batch); batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE); verifyUDFDayOfMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFDayOfMonth(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFDayOfMonth(batch); }
private void testDateAddColCol(PrimitiveCategory colType1, boolean isPositive) throws HiveException { LongColumnVector date1 = newRandomLongColumnVector(10000, size); LongColumnVector days2 = newRandomLongColumnVector(1000, size); ColumnVector col1 = castTo(date1, colType1); LongColumnVector output = new LongColumnVector(size); VectorizedRowBatch batch = new VectorizedRowBatch(3, size); batch.cols[0] = col1; batch.cols[1] = days2; batch.cols[2] = output; validateDateAdd(batch, date1, days2, colType1, isPositive); TestVectorizedRowBatch.addRandomNulls(date1); batch.cols[0] = castTo(date1, colType1); validateDateAdd(batch, date1, days2, colType1, isPositive); TestVectorizedRowBatch.addRandomNulls(days2); batch.cols[1] = days2; validateDateAdd(batch, date1, days2, colType1, isPositive); }
@Test public void testVectorUDFUnixTimeStamp() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatch(new int[] {0}, VectorizedRowBatch.DEFAULT_SIZE); Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFUnixTimeStamp(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFUnixTimeStamp(batch); int[] boundaries = getAllBoundaries(); batch = getVectorizedRowBatch(boundaries, boundaries.length); verifyUDFUnixTimeStamp(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFUnixTimeStamp(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFUnixTimeStamp(batch); batch = getVectorizedRowBatch(new int[] {0}, 1); batch.cols[0].isRepeating = true; verifyUDFUnixTimeStamp(batch); batch.cols[0].noNulls = false; batch.cols[0].isNull[0] = true; verifyUDFUnixTimeStamp(batch); batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE); verifyUDFUnixTimeStamp(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFUnixTimeStamp(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFUnixTimeStamp(batch); }
@Test public void testVectorUDFYear() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatch(new int[] {0}, VectorizedRowBatch.DEFAULT_SIZE); Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch); int[] boundaries = getAllBoundaries(); batch = getVectorizedRowBatch(boundaries, boundaries.length); verifyUDFYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFYear(batch); batch = getVectorizedRowBatch(new int[] {0}, 1); batch.cols[0].isRepeating = true; verifyUDFYear(batch); batch.cols[0].noNulls = false; batch.cols[0].isNull[0] = true; verifyUDFYear(batch); batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE); verifyUDFYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFYear(batch); }
@Test public void testVectorUDFWeekOfYear() throws HiveException { VectorizedRowBatch batch = getVectorizedRowBatch(new int[] {0}, VectorizedRowBatch.DEFAULT_SIZE); Assert.assertTrue(((LongColumnVector) batch.cols[1]).noNulls); Assert.assertFalse(((LongColumnVector) batch.cols[1]).isRepeating); verifyUDFWeekOfYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch); int[] boundaries = getAllBoundaries(); batch = getVectorizedRowBatch(boundaries, boundaries.length); verifyUDFWeekOfYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFWeekOfYear(batch); batch = getVectorizedRowBatch(new int[] {0}, 1); batch.cols[0].isRepeating = true; verifyUDFWeekOfYear(batch); batch.cols[0].noNulls = false; batch.cols[0].isNull[0] = true; verifyUDFWeekOfYear(batch); batch = getVectorizedRandomRowBatch(200, VectorizedRowBatch.DEFAULT_SIZE); verifyUDFWeekOfYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); verifyUDFWeekOfYear(batch); TestVectorizedRowBatch.addRandomNulls(batch.cols[1]); verifyUDFWeekOfYear(batch); }
private void testDateAddScalarCol(PrimitiveCategory colType1, boolean isPositive) throws HiveException { LongColumnVector date2 = newRandomLongColumnVector(10000, size); long scalar1 = newRandom(1000); LongColumnVector output = new LongColumnVector(size); VectorizedRowBatch batch = new VectorizedRowBatch(2, size); batch.cols[0] = date2; batch.cols[1] = output; validateDateAdd(batch, scalar1, date2, colType1, isPositive); TestVectorizedRowBatch.addRandomNulls(date2); batch.cols[0] = date2; validateDateAdd(batch, scalar1, date2, colType1, isPositive); }
private void testDateAddColScalar(PrimitiveCategory colType1, boolean isPositive) throws HiveException { LongColumnVector date1 = newRandomLongColumnVector(10000, size); ColumnVector col1 = castTo(date1, colType1); long scalar2 = newRandom(1000); LongColumnVector output = new LongColumnVector(size); VectorizedRowBatch batch = new VectorizedRowBatch(2, size); batch.cols[0] = col1; batch.cols[1] = output; validateDateAdd(batch, colType1, scalar2, isPositive, date1); TestVectorizedRowBatch.addRandomNulls(batch.cols[0]); validateDateAdd(batch, colType1, scalar2, isPositive, date1); }
TestVectorizedRowBatch.addRandomNulls(date); batch.cols[0] = castTo(date, type); validateToDate(batch, type, date);
@Test public void testDate() throws HiveException { for (PrimitiveCategory colType : dateTimestampStringTypes) { if (colType == PrimitiveCategory.DATE) { continue; } LongColumnVector date = newRandomLongColumnVector(10000, size); LongColumnVector output = new LongColumnVector(size); VectorizedRowBatch batch = new VectorizedRowBatch(2, size); batch.cols[0] = castTo(date, colType); batch.cols[1] = output; validateDate(batch, colType, date); TestVectorizedRowBatch.addRandomNulls(date); batch.cols[0] = castTo(date, colType); validateDate(batch, colType, date); } VectorExpression udf = new VectorUDFDateString(0, 1); udf.setInputTypeInfos(new TypeInfo[] {TypeInfoFactory.stringTypeInfo}); udf.transientInit(); VectorizedRowBatch batch = new VectorizedRowBatch(2, 1); batch.cols[0] = new BytesColumnVector(1); batch.cols[1] = new LongColumnVector(1); BytesColumnVector bcv = (BytesColumnVector) batch.cols[0]; byte[] bytes = "error".getBytes(utf8); bcv.vector[0] = bytes; bcv.start[0] = 0; bcv.length[0] = bytes.length; udf.evaluate(batch); Assert.assertEquals(batch.cols[1].isNull[0], true); }