use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class PhysicalOpUnitTestBase method parseExprs.
protected List<NamedExpression> parseExprs(String... expressionsAndOutputNames) {
Preconditions.checkArgument(expressionsAndOutputNames.length % 2 == 0, "List of expressions and output field names" + " is not complete, each expression must explicitly give and output name,");
List<NamedExpression> ret = new ArrayList<>();
for (int i = 0; i < expressionsAndOutputNames.length; i += 2) {
ret.add(new NamedExpression(parseExpr(expressionsAndOutputNames[i]), new FieldReference(new SchemaPath(new PathSegment.NameSegment(expressionsAndOutputNames[i + 1])))));
}
return ret;
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class TestExternalSortExec method testSortSpec.
@Test
public void testSortSpec() {
FieldReference expr = FieldReference.getWithQuotedRef("foo");
Ordering ordering = new Ordering(Ordering.ORDER_ASC, expr, Ordering.NULLS_FIRST);
// Basics
ExternalSort popConfig = new ExternalSort(null, Lists.newArrayList(ordering), false);
assertSame(ordering, popConfig.getOrderings().get(0));
assertFalse(popConfig.getReverse());
assertEquals(SelectionVectorMode.FOUR_BYTE, popConfig.getSVMode());
assertEquals(CoreOperatorType.EXTERNAL_SORT_VALUE, popConfig.getOperatorType());
assertEquals(ExternalSort.DEFAULT_SORT_ALLOCATION, popConfig.getInitialAllocation());
assertEquals(AbstractBase.MAX_ALLOCATION, popConfig.getMaxAllocation());
assertTrue(popConfig.isExecutable());
// Non-default settings
popConfig = new ExternalSort(null, Lists.newArrayList(ordering), true);
assertTrue(popConfig.getReverse());
long maxAlloc = 50_000_000;
popConfig.setMaxAllocation(maxAlloc);
assertEquals(ExternalSort.DEFAULT_SORT_ALLOCATION, popConfig.getInitialAllocation());
assertEquals(maxAlloc, popConfig.getMaxAllocation());
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class TestSortImpl method makeSortImpl.
/**
* Create the sort implementation to be used by test.
*
* @param fixture operator fixture
* @param sortOrder sort order as specified by {@link Ordering}
* @param nullOrder null order as specified by {@link Ordering}
* @param outputBatch where the sort should write its output
* @return the sort initialized sort implementation, ready to
* do work
*/
public static SortImpl makeSortImpl(OperatorFixture fixture, String sortOrder, String nullOrder, VectorContainer outputBatch) {
FieldReference expr = FieldReference.getWithQuotedRef("key");
Ordering ordering = new Ordering(sortOrder, expr, nullOrder);
Sort popConfig = new Sort(null, Lists.newArrayList(ordering), false);
OperatorContext opContext = fixture.newOperatorContext(popConfig);
QueryId queryId = QueryId.newBuilder().setPart1(1234).setPart2(5678).build();
FragmentHandle handle = FragmentHandle.newBuilder().setMajorFragmentId(2).setMinorFragmentId(3).setQueryId(queryId).build();
SortConfig sortConfig = new SortConfig(opContext.getFragmentContext().getConfig(), opContext.getFragmentContext().getOptions());
SpillSet spillSet = new SpillSet(opContext.getFragmentContext().getConfig(), handle, popConfig);
PriorityQueueCopierWrapper copierHolder = new PriorityQueueCopierWrapper(opContext);
SpilledRuns spilledRuns = new SpilledRuns(opContext, spillSet, copierHolder);
return new SortImpl(opContext, sortConfig, spilledRuns, outputBatch);
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class TestSorter method makeSortConfig.
public static Sort makeSortConfig(String key, String sortOrder, String nullOrder) {
FieldReference expr = FieldReference.getWithQuotedRef(key);
Ordering ordering = new Ordering(sortOrder, expr, nullOrder);
return new Sort(null, Lists.newArrayList(ordering), false);
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class ExpressionTreeMaterializerTest method testMaterializingLateboundTree.
@Test
public void testMaterializingLateboundTree() throws SchemaChangeException {
final RecordBatch batch = mock(RecordBatch.class);
when(batch.getValueVectorId(SchemaPath.getSimplePath("test"))).thenReturn(new TypedFieldId(Types.required(MinorType.BIT), -4));
when(batch.getValueVectorId(SchemaPath.getSimplePath("test1"))).thenReturn(new TypedFieldId(Types.required(MinorType.BIGINT), -5));
ErrorCollector ec = new ErrorCollectorImpl();
LogicalExpression elseExpression = new IfExpression.Builder().setElse(new ValueExpressions.LongExpression(1L, ExpressionPosition.UNKNOWN)).setIfCondition(new IfExpression.IfCondition(new ValueExpressions.BooleanExpression("true", ExpressionPosition.UNKNOWN), new FieldReference("test1", ExpressionPosition.UNKNOWN))).build();
LogicalExpression expr = new IfExpression.Builder().setIfCondition(new IfExpression.IfCondition(new FieldReference("test", ExpressionPosition.UNKNOWN), new ValueExpressions.LongExpression(2L, ExpressionPosition.UNKNOWN))).setElse(elseExpression).build();
LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(expr, batch, ec, registry);
assertTrue(newExpr instanceof IfExpression);
IfExpression newIfExpr = (IfExpression) newExpr;
IfExpression.IfCondition ifCondition = newIfExpr.ifCondition;
assertTrue(newIfExpr.elseExpression instanceof IfExpression);
assertEquals(bigIntType, ifCondition.expression.getMajorType());
assertEquals(true, ((ValueExpressions.BooleanExpression) ((IfExpression) (newIfExpr.elseExpression)).ifCondition.condition).value);
if (ec.hasErrors()) {
System.out.println(ec.toErrorString());
}
assertFalse(ec.hasErrors());
}
Aggregations