use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.
the class TestMathFunctions method testBasicMathFunctions.
@Test
public void testBasicMathFunctions() throws Throwable {
final DrillbitContext bitContext = mockDrillbitContext();
final UserClientConnection connection = Mockito.mock(UserClientConnection.class);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.asCharSource(DrillFileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8).read());
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContextImpl context = new FragmentContextImpl(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
assertEquals(exec.getRecordCount(), 1);
assertEquals(intMulVector.getAccessor().get(0), 2);
assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
assertEquals(intAddVector.getAccessor().get(0), 3);
assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
}
if (context.getExecutorState().getFailureCause() != null) {
throw context.getExecutorState().getFailureCause();
}
assertTrue(!context.getExecutorState().isFailed());
}
use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.
the class DoubleGen method setValue.
@Override
public void setValue(ValueVector v, int index) {
Float8Vector vector = (Float8Vector) v;
vector.getMutator().set(index, value());
}
use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.
the class TestMathFunctions method testBasicMathFunctions.
@Test
public void testBasicMathFunctions(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
mockDrillbitContext(bitContext);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(c);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/simple_math_functions.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
final FragmentContext context = new FragmentContext(bitContext, BitControl.PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final IntVector intMulVector = exec.getValueVectorById(new SchemaPath("INTMUL", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatMulVector = exec.getValueVectorById(new SchemaPath("FLOATMUL", ExpressionPosition.UNKNOWN), Float8Vector.class);
final IntVector intAddVector = exec.getValueVectorById(new SchemaPath("INTADD", ExpressionPosition.UNKNOWN), IntVector.class);
final Float8Vector floatAddVector = exec.getValueVectorById(new SchemaPath("FLOATADD", ExpressionPosition.UNKNOWN), Float8Vector.class);
assertEquals(exec.getRecordCount(), 1);
assertEquals(intMulVector.getAccessor().get(0), 2);
assertEquals(floatMulVector.getAccessor().get(0), (1.1 * 2.2), 0);
assertEquals(intAddVector.getAccessor().get(0), 3);
assertEquals(floatAddVector.getAccessor().get(0), (1.1 + 2.2), 0);
}
if (context.getFailureCause() != null) {
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
use of org.apache.drill.exec.vector.Float8Vector in project drill by apache.
the class TestCastFunctions method testCastFloat8.
@Test
public //cast to float8
void testCastFloat8(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
mockDrillbitContext(bitContext);
final PhysicalPlanReader reader = PhysicalPlanReaderTestFactory.defaultPhysicalPlanReader(CONFIG);
final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/functions/cast/testCastFloat8.json"), Charsets.UTF_8));
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(CONFIG);
final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
while (exec.next()) {
final Float8Vector c0 = exec.getValueVectorById(new SchemaPath("varchar_cast2", ExpressionPosition.UNKNOWN), Float8Vector.class);
final Float8Vector.Accessor a0 = c0.getAccessor();
int count = 0;
for (int i = 0; i < c0.getAccessor().getValueCount(); i++) {
final Float8Holder holder0 = new Float8Holder();
a0.get(i, holder0);
assertEquals(12.56, holder0.value, 0.001);
++count;
}
assertEquals(5, count);
}
exec.close();
context.close();
if (context.getFailureCause() != null) {
throw context.getFailureCause();
}
assertTrue(!context.isFailed());
}
use of org.apache.drill.exec.vector.Float8Vector in project drill by axbaretto.
the class TestOrderedPartitionExchange method twoBitTwoExchangeRun.
/**
* Starts two drillbits and runs a physical plan with a Mock scan, project, OrderedParititionExchange, Union Exchange,
* and sort. The final sort is done first on the partition column, and verifies that the partitions are correct, in that
* all rows in partition 0 should come in the sort order before any row in partition 1, etc. Also verifies that the standard
* deviation of the size of the partitions is less than one tenth the mean size of the partitions, because we expect all
* the partitions to be roughly equal in size.
* @throws Exception
*/
@Test
public void twoBitTwoExchangeRun() throws Exception {
RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
bit1.run();
bit2.run();
client.connect();
List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.toString(DrillFileUtils.getResourceAsFile("/sender/ordered_exchange.json"), Charsets.UTF_8));
int count = 0;
List<Integer> partitionRecordCounts = Lists.newArrayList();
for (QueryDataBatch b : results) {
if (b.getData() != null) {
int rows = b.getHeader().getRowCount();
count += rows;
DrillConfig config = DrillConfig.create();
RecordBatchLoader loader = new RecordBatchLoader(new BootStrapContext(config, SystemOptionManager.createDefaultOptionDefinitions(), ClassPathScanner.fromPrescan(config)).getAllocator());
loader.load(b.getHeader().getDef(), b.getData());
BigIntVector vv1 = (BigIntVector) loader.getValueAccessorById(BigIntVector.class, loader.getValueVectorId(new SchemaPath("col1", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
Float8Vector vv2 = (Float8Vector) loader.getValueAccessorById(Float8Vector.class, loader.getValueVectorId(new SchemaPath("col2", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
IntVector pVector = (IntVector) loader.getValueAccessorById(IntVector.class, loader.getValueVectorId(new SchemaPath("partition", ExpressionPosition.UNKNOWN)).getFieldIds()).getValueVector();
long previous1 = Long.MIN_VALUE;
double previous2 = Double.MIN_VALUE;
int partPrevious = -1;
long current1 = Long.MIN_VALUE;
double current2 = Double.MIN_VALUE;
int partCurrent = -1;
int partitionRecordCount = 0;
for (int i = 0; i < rows; i++) {
previous1 = current1;
previous2 = current2;
partPrevious = partCurrent;
current1 = vv1.getAccessor().get(i);
current2 = vv2.getAccessor().get(i);
partCurrent = pVector.getAccessor().get(i);
Assert.assertTrue(current1 >= previous1);
if (current1 == previous1) {
Assert.assertTrue(current2 <= previous2);
}
if (partCurrent == partPrevious || partPrevious == -1) {
partitionRecordCount++;
} else {
partitionRecordCounts.add(partitionRecordCount);
partitionRecordCount = 0;
}
}
partitionRecordCounts.add(partitionRecordCount);
loader.clear();
}
b.release();
}
double[] values = new double[partitionRecordCounts.size()];
int i = 0;
for (Integer rc : partitionRecordCounts) {
values[i++] = rc.doubleValue();
}
StandardDeviation stdDev = new StandardDeviation();
Mean mean = new Mean();
double std = stdDev.evaluate(values);
double m = mean.evaluate(values);
System.out.println("mean: " + m + " std dev: " + std);
// Assert.assertTrue(std < 0.1 * m);
assertEquals(31000, count);
}
}
Aggregations