use of org.apache.drill.exec.physical.config.LateralJoinPOP in project drill by apache.
the class TestLateralJoinCorrectness method testMultiLevelLateral_SchemaChange_RightUnnest.
/**
* This test generates an operator tree for multi level LATERAL by stacking 2 LATERAL and finally an UNNEST pair
* (using MockRecord Batch) as left and right child of lower level LATERAL. In this setup the test try to simulate
* the SchemaChange happening at upper level LATERAL left incoming second batch, which also results into the
* SchemaChange of right UNNEST of lower level LATERAL. This test validates that the schema change is handled
* correctly by both upper and lower level LATERAL.
*
* @throws Exception
*/
@Test
public void testMultiLevelLateral_SchemaChange_RightUnnest() throws Exception {
// ** Prepare first pair of left batch and right batch for lower level LATERAL Lateral_1 **
final LateralJoinPOP popConfig_1 = new LateralJoinPOP(null, null, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
TupleMetadata leftSchemaWithImplicit = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).addRow(1, 1, 10, "item1").build();
final RowSet.SingleRowSet nonEmptyLeftRowSet2 = fixture.rowSetBuilder(leftSchemaWithImplicit).addRow(1, 1111, 10001, "NewRecord").build();
leftContainer.add(emptyLeftRowSet_1.container());
leftContainer.add(nonEmptyLeftRowSet_1.container());
leftContainer.add(nonEmptyLeftRowSet2.container());
// Get the left IterOutcomes for Lateral Join
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch leftMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
// Get the right container with dummy data
TupleMetadata rightSchema2 = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_right_new", TypeProtos.MinorType.INT).add("cost_right_new", TypeProtos.MinorType.VARCHAR).add("name_right_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyRightRowSet_rightSchema2 = fixture.rowSetBuilder(rightSchema2).build();
final RowSet.SingleRowSet nonEmptyRightRowSet_rightSchema2 = fixture.rowSetBuilder(rightSchema2).addRow(1, 5, "51", "item51").addRow(1, 6, "61", "item61").addRow(1, 7, "71", "item71").build();
rightContainer.add(emptyRightRowSet.container());
rightContainer.add(nonEmptyRightRowSet.container());
rightContainer.add(emptyRightRowSet_rightSchema2.container());
rightContainer.add(nonEmptyRightRowSet_rightSchema2.container());
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch rightMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
final LateralJoinBatch lowerLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_1, rightMockBatch_1);
// ** Prepare second pair of left and right batch for upper level Lateral_2 **
// Create left input schema for first batch
TupleMetadata leftSchema3 = new SchemaBuilder().add("id_left_new", TypeProtos.MinorType.INT).add("cost_left_new", TypeProtos.MinorType.INT).add("name_left_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).addRow(6, 60, "item6").build();
// Get left input schema for second left batch
TupleMetadata leftSchema4 = new SchemaBuilder().add("id_left_new_new", TypeProtos.MinorType.INT).add("cost_left_new_new", TypeProtos.MinorType.VARCHAR).add("name_left_new_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema4 = fixture.rowSetBuilder(leftSchema4).addRow(100, "100", "item100").build();
// Build Left container for upper level LATERAL operator
final List<VectorContainer> leftContainer2 = new ArrayList<>(5);
// Get the left container with dummy data
leftContainer2.add(emptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema4.container());
// Get the left container outcomes for upper level LATERAL operator
final List<RecordBatch.IterOutcome> leftOutcomes2 = new ArrayList<>(5);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes2.add(RecordBatch.IterOutcome.OK);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
final CloseableRecordBatch leftMockBatch_2 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer2, leftOutcomes2, leftContainer2.get(0).getSchema());
final LateralJoinBatch upperLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_2, lowerLevelLateral);
try {
// 3 for first batch on left side and another 3 for next left batch
final int expectedOutputRecordCount = 6;
int actualOutputRecordCount = 0;
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.NONE == upperLevelLateral.next());
assertTrue(actualOutputRecordCount == expectedOutputRecordCount);
} catch (AssertionError | Exception error) {
fail();
} finally {
// Close all the resources for this test case
upperLevelLateral.close();
leftMockBatch_2.close();
lowerLevelLateral.close();
leftMockBatch_1.close();
rightMockBatch_1.close();
leftContainer2.clear();
leftOutcomes2.clear();
}
}
use of org.apache.drill.exec.physical.config.LateralJoinPOP in project drill by apache.
the class TestLateralJoinCorrectness method testMultiLevelLateral_SchemaChange_LeftRightUnnest.
/**
* This test generates an operator tree for multi level LATERAL by stacking 2 LATERAL and finally an UNNEST pair
* (using MockRecord Batch) as left and right child of lower level LATERAL. In this setup the test try to simulate
* the SchemaChange happening at upper level LATERAL left incoming second batch, which also results into the
* SchemaChange of both left&right UNNEST of lower level LATERAL. This test validates that the schema change is
* handled correctly by both upper and lower level LATERAL.
*
* @throws Exception
*/
@Test
public void testMultiLevelLateral_SchemaChange_LeftRightUnnest() throws Exception {
// ** Prepare first pair of left batch and right batch for lower level LATERAL Lateral_1 **
final LateralJoinPOP popConfig_1 = new LateralJoinPOP(null, null, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
TupleMetadata leftSchemaWithImplicit = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).addRow(1, 1, 10, "item1").build();
// Create left input schema for first batch
TupleMetadata leftSchema2 = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_left_new", TypeProtos.MinorType.INT).add("cost_left_new", TypeProtos.MinorType.INT).add("name_left_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_leftSchema2 = fixture.rowSetBuilder(leftSchema2).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema2 = fixture.rowSetBuilder(leftSchema2).addRow(1, 6, 60, "item6").build();
leftContainer.add(emptyLeftRowSet_1.container());
leftContainer.add(nonEmptyLeftRowSet_1.container());
leftContainer.add(emptyLeftRowSet_leftSchema2.container());
leftContainer.add(nonEmptyLeftRowSet_leftSchema2.container());
// Get the left IterOutcomes for Lateral Join
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch leftMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
// Get the right container with dummy data
TupleMetadata rightSchema2 = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_right_new", TypeProtos.MinorType.INT).add("cost_right_new", TypeProtos.MinorType.VARCHAR).add("name_right_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyRightRowSet_rightSchema2 = fixture.rowSetBuilder(rightSchema2).build();
final RowSet.SingleRowSet nonEmptyRightRowSet_rightSchema2 = fixture.rowSetBuilder(rightSchema2).addRow(1, 5, "51", "item51").addRow(1, 6, "61", "item61").addRow(1, 7, "71", "item71").build();
rightContainer.add(emptyRightRowSet.container());
rightContainer.add(nonEmptyRightRowSet.container());
rightContainer.add(emptyRightRowSet_rightSchema2.container());
rightContainer.add(nonEmptyRightRowSet_rightSchema2.container());
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch rightMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
final LateralJoinBatch lowerLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_1, rightMockBatch_1);
// ** Prepare second pair of left and right batch for upper level Lateral_2 **
// Create left input schema for first batch
TupleMetadata leftSchema3 = new SchemaBuilder().add("id_left_left", TypeProtos.MinorType.INT).add("cost_left_left", TypeProtos.MinorType.INT).add("name_left_left", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).addRow(6, 60, "item6").build();
// Get left input schema for second left batch
TupleMetadata leftSchema4 = new SchemaBuilder().add("id_left_left_new", TypeProtos.MinorType.INT).add("cost_left_left_new", TypeProtos.MinorType.VARCHAR).add("name_left_left_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema4 = fixture.rowSetBuilder(leftSchema4).addRow(100, "100", "item100").build();
// Build Left container for upper level LATERAL operator
final List<VectorContainer> leftContainer2 = new ArrayList<>(5);
// Get the left container with dummy data
leftContainer2.add(emptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema4.container());
// Get the left container outcomes for upper level LATERAL operator
final List<RecordBatch.IterOutcome> leftOutcomes2 = new ArrayList<>(5);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes2.add(RecordBatch.IterOutcome.OK);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
final CloseableRecordBatch leftMockBatch_2 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer2, leftOutcomes2, leftContainer2.get(0).getSchema());
final LateralJoinBatch upperLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_2, lowerLevelLateral);
try {
// 3 for first batch on left side and another 3 for next left batch
final int expectedOutputRecordCount = 6;
int actualOutputRecordCount = 0;
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.NONE == upperLevelLateral.next());
assertTrue(actualOutputRecordCount == expectedOutputRecordCount);
} catch (AssertionError | Exception error) {
fail();
} finally {
// Close all the resources for this test case
upperLevelLateral.close();
leftMockBatch_2.close();
lowerLevelLateral.close();
leftMockBatch_1.close();
rightMockBatch_1.close();
leftContainer2.clear();
leftOutcomes2.clear();
}
}
use of org.apache.drill.exec.physical.config.LateralJoinPOP in project drill by apache.
the class TestLateralJoinCorrectness method testMultiLevelLateral_SchemaChange_LeftUnnest.
/**
* This test generates an operator tree for multi level LATERAL by stacking 2 LATERAL and finally an UNNEST pair
* (using MockRecord Batch) as left and right child of lower level LATERAL. In this setup the test try to simulate
* the SchemaChange happening at upper level LATERAL left incoming second batch, which also results into the
* SchemaChange of left UNNEST of lower level LATERAL. This test validates that the schema change is handled
* correctly by both upper and lower level LATERAL.
*
* @throws Exception
*/
@Test
public void testMultiLevelLateral_SchemaChange_LeftUnnest() throws Exception {
// ** Prepare first pair of left batch and right batch for lower level LATERAL Lateral_1 **
final LateralJoinPOP popConfig_1 = new LateralJoinPOP(null, null, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
TupleMetadata leftSchemaWithImplicit = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_1 = fixture.rowSetBuilder(leftSchemaWithImplicit).addRow(1, 1, 10, "item1").build();
leftContainer.add(emptyLeftRowSet_1.container());
leftContainer.add(nonEmptyLeftRowSet_1.container());
// Create left input schema2 for schema change batch
TupleMetadata leftSchema2 = new SchemaBuilder().add(popConfig_1.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("new_id_left", TypeProtos.MinorType.INT).add("new_cost_left", TypeProtos.MinorType.INT).add("new_name_left", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_Schema2 = fixture.rowSetBuilder(leftSchema2).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_Schema2 = fixture.rowSetBuilder(leftSchema2).addRow(1, 1111, 10001, "NewRecord").build();
leftContainer.add(emptyLeftRowSet_Schema2.container());
leftContainer.add(nonEmptyLeftRowSet_Schema2.container());
// Get the left IterOutcomes for Lateral Join
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch leftMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
// Get the right container with dummy data
final RowSet.SingleRowSet nonEmptyRightRowSet_1 = fixture.rowSetBuilder(rightSchema).addRow(1, 5, 51, "item51").addRow(1, 6, 61, "item61").addRow(1, 7, 71, "item71").build();
rightContainer.add(emptyRightRowSet.container());
rightContainer.add(nonEmptyRightRowSet.container());
rightContainer.add(nonEmptyRightRowSet_1.container());
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch rightMockBatch_1 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
final LateralJoinBatch lowerLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_1, rightMockBatch_1);
// ** Prepare second pair of left and right batch for upper level Lateral_2 **
// Create left input schema for first batch
TupleMetadata leftSchema3 = new SchemaBuilder().add("id_left_new", TypeProtos.MinorType.INT).add("cost_left_new", TypeProtos.MinorType.INT).add("name_left_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet emptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).build();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema3 = fixture.rowSetBuilder(leftSchema3).addRow(6, 60, "item6").build();
// Get left input schema for second left batch
TupleMetadata leftSchema4 = new SchemaBuilder().add("id_left_new_new", TypeProtos.MinorType.INT).add("cost_left_new_new", TypeProtos.MinorType.VARCHAR).add("name_left_new_new", TypeProtos.MinorType.VARCHAR).buildSchema();
final RowSet.SingleRowSet nonEmptyLeftRowSet_leftSchema4 = fixture.rowSetBuilder(leftSchema4).addRow(100, "100", "item100").build();
// Build Left container for upper level LATERAL operator
final List<VectorContainer> leftContainer2 = new ArrayList<>(5);
// Get the left container with dummy data
leftContainer2.add(emptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema3.container());
leftContainer2.add(nonEmptyLeftRowSet_leftSchema4.container());
// Get the left container outcomes for upper level LATERAL operator
final List<RecordBatch.IterOutcome> leftOutcomes2 = new ArrayList<>(5);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
leftOutcomes2.add(RecordBatch.IterOutcome.OK);
leftOutcomes2.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
final CloseableRecordBatch leftMockBatch_2 = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer2, leftOutcomes2, leftContainer2.get(0).getSchema());
final LateralJoinBatch upperLevelLateral = new LateralJoinBatch(popConfig_1, fixture.getFragmentContext(), leftMockBatch_2, lowerLevelLateral);
try {
// 3 for first batch on left side and another 3 for next left batch
final int expectedOutputRecordCount = 6;
int actualOutputRecordCount = 0;
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.OK == upperLevelLateral.next());
actualOutputRecordCount += upperLevelLateral.getRecordCount();
assertTrue(RecordBatch.IterOutcome.NONE == upperLevelLateral.next());
assertTrue(actualOutputRecordCount == expectedOutputRecordCount);
} catch (AssertionError | Exception error) {
fail();
} finally {
// Close all the resources for this test case
upperLevelLateral.close();
leftMockBatch_2.close();
lowerLevelLateral.close();
leftMockBatch_1.close();
rightMockBatch_1.close();
leftContainer2.clear();
leftOutcomes2.clear();
}
}
use of org.apache.drill.exec.physical.config.LateralJoinPOP in project drill by apache.
the class TestLateralJoinCorrectnessBatchProcessing method testLeftAndRight_OutputFull_WithPendingLeftRow_LeftJoin.
@Test
public void testLeftAndRight_OutputFull_WithPendingLeftRow_LeftJoin() throws Exception {
leftContainer.add(nonEmptyLeftRowSet.container());
// Get the left IterOutcomes for Lateral Join
leftOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
// Create Left MockRecordBatch
final CloseableRecordBatch leftMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, leftContainer, leftOutcomes, leftContainer.get(0).getSchema());
// Get the right container with dummy data
final RowSet.SingleRowSet nonEmptyRightRowSet2 = fixture.rowSetBuilder(rightSchema).addRow(1, 11, 110, "item11").addRow(2, 22, 220, "item22").build();
final RowSet.SingleRowSet expectedRowSet = fixture.rowSetBuilder(expectedSchemaLeftJoin).addRow(1, 10, "item1", 11, 110, "item11").addRow(2, 20, "item2", 22, 220, "item22").addRow(3, 30, "item3", null, null, null).build();
final RowSet.SingleRowSet expectedRowSet1 = fixture.rowSetBuilder(expectedSchemaLeftJoin).addRow(4, 40, "item4", null, null, null).build();
rightContainer.add(emptyRightRowSet.container());
rightContainer.add(nonEmptyRightRowSet2.container());
rightOutcomes.add(RecordBatch.IterOutcome.OK_NEW_SCHEMA);
rightOutcomes.add(RecordBatch.IterOutcome.EMIT);
final CloseableRecordBatch rightMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, rightContainer, rightOutcomes, rightContainer.get(0).getSchema());
LateralJoinPOP ljPopConfig = new LateralJoinPOP(null, null, JoinRelType.LEFT, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
final LateralJoinBatch ljBatch = new LateralJoinBatch(ljPopConfig, fixture.getFragmentContext(), leftMockBatch, rightMockBatch);
ljBatch.setMaxOutputRowCount(3);
ljBatch.setUseMemoryManager(false);
try {
assertTrue(RecordBatch.IterOutcome.OK_NEW_SCHEMA == ljBatch.next());
assertTrue(RecordBatch.IterOutcome.OK == ljBatch.next());
assertTrue(ljBatch.getRecordCount() == 3);
// verify results
RowSet actualRowSet = DirectRowSet.fromContainer(ljBatch.getContainer());
new RowSetComparison(expectedRowSet).verify(actualRowSet);
// Release output container memory for this batch as other operators will do
VectorAccessibleUtilities.clear(ljBatch);
assertTrue(RecordBatch.IterOutcome.OK == ljBatch.next());
assertTrue(ljBatch.getRecordCount() == (nonEmptyLeftRowSet.rowCount() - 3));
// verify results
RowSet actualRowSet2 = DirectRowSet.fromContainer(ljBatch.getContainer());
new RowSetComparison(expectedRowSet1).verify(actualRowSet2);
assertTrue(RecordBatch.IterOutcome.NONE == ljBatch.next());
} finally {
// Close all the resources for this test case
ljBatch.close();
leftMockBatch.close();
rightMockBatch.close();
nonEmptyRightRowSet2.clear();
expectedRowSet.clear();
expectedRowSet1.clear();
}
}
use of org.apache.drill.exec.physical.config.LateralJoinPOP in project drill by apache.
the class TestLateralJoinCorrectnessBatchProcessing method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
PhysicalOperator mockPopConfig = new MockStorePOP(null);
operatorContext = fixture.newOperatorContext(mockPopConfig);
ljPopConfig = new LateralJoinPOP(null, null, JoinRelType.INNER, DrillLateralJoinRelBase.IMPLICIT_COLUMN, Lists.newArrayList());
leftSchema = new SchemaBuilder().add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).buildSchema();
emptyLeftRowSet = fixture.rowSetBuilder(leftSchema).build();
rightSchema = new SchemaBuilder().add(ljPopConfig.getImplicitRIDColumn(), TypeProtos.MinorType.INT).add("id_right", TypeProtos.MinorType.INT).add("cost_right", TypeProtos.MinorType.INT).add("name_right", TypeProtos.MinorType.VARCHAR).buildSchema();
emptyRightRowSet = fixture.rowSetBuilder(rightSchema).build();
expectedSchema = new SchemaBuilder().add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).add("id_right", TypeProtos.MinorType.INT).add("cost_right", TypeProtos.MinorType.INT).add("name_right", TypeProtos.MinorType.VARCHAR).buildSchema();
expectedSchemaLeftJoin = new SchemaBuilder().add("id_left", TypeProtos.MinorType.INT).add("cost_left", TypeProtos.MinorType.INT).add("name_left", TypeProtos.MinorType.VARCHAR).add("id_right", TypeProtos.MinorType.INT, TypeProtos.DataMode.OPTIONAL).add("cost_right", TypeProtos.MinorType.INT, TypeProtos.DataMode.OPTIONAL).add("name_right", TypeProtos.MinorType.VARCHAR, TypeProtos.DataMode.OPTIONAL).buildSchema();
}
Aggregations