Skip to content

Commit

Permalink
DRILL-6210: Enhanced test schema utilities
Browse files Browse the repository at this point in the history
closes #1150
  • Loading branch information
Paul Rogers authored and Ben-Zvi committed Mar 9, 2018
1 parent b4a783a commit f653359
Show file tree
Hide file tree
Showing 56 changed files with 1,996 additions and 558 deletions.
Expand Up @@ -23,8 +23,8 @@
import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.BaseTestQuery;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
import org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException;
import org.apache.drill.test.BaseTestQuery;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
import org.apache.drill.exec.work.foreman.UnsupportedRelOperatorException;
import org.apache.drill.test.BaseTestQuery;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down
Expand Up @@ -21,11 +21,11 @@
import com.google.common.collect.Lists;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.drill.test.BaseTestQuery;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.apache.drill.categories.UnlikelyTest;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.types.TypeProtos;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down
Expand Up @@ -17,6 +17,10 @@
*/
package org.apache.drill.exec.cache;

import static org.apache.drill.test.rowSet.RowSetUtilities.objArray;
import static org.apache.drill.test.rowSet.RowSetUtilities.strArray;
import static org.junit.Assert.assertTrue;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -26,8 +30,8 @@
import java.nio.file.StandardOpenOption;

import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.cache.VectorSerializer.Reader;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.record.VectorContainer;
import org.apache.drill.exec.record.selection.SelectionVector2;
import org.apache.drill.test.DirTestWatcher;
Expand All @@ -39,14 +43,12 @@
import org.apache.drill.test.rowSet.RowSetComparison;
import org.apache.drill.test.rowSet.RowSetUtilities;
import org.apache.drill.test.rowSet.RowSetWriter;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;

import static org.junit.Assert.assertTrue;

public class TestBatchSerialization extends DrillTest {

@ClassRule
Expand Down Expand Up @@ -179,17 +181,17 @@ public void testTypes() throws IOException {

private SingleRowSet buildMapSet(BatchSchema schema) {
return fixture.rowSetBuilder(schema)
.addRow(1, new Object[] {100, "first"})
.addRow(2, new Object[] {200, "second"})
.addRow(3, new Object[] {300, "third"})
.addRow(1, objArray(100, "first"))
.addRow(2, objArray(200, "second"))
.addRow(3, objArray(300, "third"))
.build();
}

private SingleRowSet buildArraySet(BatchSchema schema) {
return fixture.rowSetBuilder(schema)
.addRow(1, new String[] { "first, second, third" } )
.addRow(1, strArray("first, second, third"))
.addRow(2, null)
.addRow(3, new String[] { "third, fourth, fifth" } )
.addRow(3, strArray("third, fourth, fifth"))
.build();
}

Expand All @@ -206,7 +208,7 @@ public void testMap() throws IOException {
.addMap("map")
.add("key", MinorType.INT)
.add("value", MinorType.VARCHAR)
.buildMap()
.resumeSchema()
.build();

verifySerialize(buildMapSet(schema).toIndirect(),
Expand Down
Expand Up @@ -48,7 +48,7 @@
import org.apache.drill.exec.vector.VarCharVector;
import org.apache.drill.test.SubOperatorTest;
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.Test;

/**
Expand Down
Expand Up @@ -17,13 +17,15 @@
******************************************************************************/
package org.apache.drill.exec.physical.impl.validate;

import static org.junit.Assert.*;
import static org.apache.drill.test.rowSet.RowSetUtilities.intArray;
import static org.apache.drill.test.rowSet.RowSetUtilities.strArray;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.apache.drill.common.types.TypeProtos.DataMode;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.exec.physical.impl.validate.BatchValidator;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.record.VectorAccessible;
import org.apache.drill.exec.vector.RepeatedVarCharVector;
Expand All @@ -33,7 +35,7 @@
import org.apache.drill.test.LogFixture;
import org.apache.drill.test.OperatorFixture;
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -108,9 +110,9 @@ public void testValidRepeated() {
.build();

SingleRowSet batch = fixture.rowSetBuilder(schema)
.addRow(new int[] {}, new String[] {})
.addRow(new int[] {1, 2, 3}, new String[] {"fred", "barney", "wilma"})
.addRow(new int[] {4}, new String[] {"dino"})
.addRow(intArray(), strArray())
.addRow(intArray(1, 2, 3), strArray("fred", "barney", "wilma"))
.addRow(intArray(4), strArray("dino"))
.build();

BatchValidator validator = new BatchValidator(batch.vectorAccessible(), true);
Expand All @@ -135,10 +137,8 @@ public void testVariableMissingLast() {
// Don't do this in real code!

VectorAccessible va = batch.vectorAccessible();
@SuppressWarnings("resource")
ValueVector v = va.iterator().next().getValueVector();
VarCharVector vc = (VarCharVector) v;
@SuppressWarnings("resource")
UInt4Vector ov = vc.getOffsetVector();
assertTrue(ov.getAccessor().get(3) > 0);
ov.getMutator().set(3, 0);
Expand Down Expand Up @@ -183,10 +183,8 @@ public void zapOffset(SingleRowSet batch, int index, int bogusValue) {
// Don't do this in real code!

VectorAccessible va = batch.vectorAccessible();
@SuppressWarnings("resource")
ValueVector v = va.iterator().next().getValueVector();
VarCharVector vc = (VarCharVector) v;
@SuppressWarnings("resource")
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(index, bogusValue);
}
Expand Down Expand Up @@ -270,16 +268,14 @@ public void testRepeatedBadArrayOffset() {
.build();

SingleRowSet batch = fixture.rowSetBuilder(schema)
.addRow((Object) new String[] {})
.addRow((Object) new String[] {"fred", "barney", "wilma"})
.addRow((Object) new String[] {"dino"})
.addRow((Object) strArray())
.addRow((Object) strArray("fred", "barney", "wilma"))
.addRow((Object) strArray("dino"))
.build();

VectorAccessible va = batch.vectorAccessible();
@SuppressWarnings("resource")
ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector vc = (RepeatedVarCharVector) v;
@SuppressWarnings("resource")
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(3, 1);

Expand All @@ -298,18 +294,15 @@ public void testRepeatedBadValueOffset() {
.build();

SingleRowSet batch = fixture.rowSetBuilder(schema)
.addRow((Object) new String[] {})
.addRow((Object) new String[] {"fred", "barney", "wilma"})
.addRow((Object) new String[] {"dino"})
.addRow((Object) strArray())
.addRow((Object) strArray("fred", "barney", "wilma"))
.addRow((Object) strArray("dino"))
.build();

VectorAccessible va = batch.vectorAccessible();
@SuppressWarnings("resource")
ValueVector v = va.iterator().next().getValueVector();
RepeatedVarCharVector rvc = (RepeatedVarCharVector) v;
@SuppressWarnings("resource")
VarCharVector vc = rvc.getDataVector();
@SuppressWarnings("resource")
UInt4Vector ov = vc.getOffsetVector();
ov.getMutator().set(4, 100_000);

Expand Down
Expand Up @@ -30,8 +30,8 @@
import org.apache.drill.test.TestBuilder;
import org.apache.drill.test.rowSet.RowSet;
import org.apache.drill.test.rowSet.RowSetBuilder;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.file.JsonFileBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand Down
Expand Up @@ -38,8 +38,8 @@
import org.apache.drill.test.rowSet.DirectRowSet;
import org.apache.drill.test.rowSet.RowSet;
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.apache.drill.test.rowSet.RowSetComparison;
import org.apache.drill.test.rowSet.SchemaBuilder;

import com.google.common.collect.Lists;

Expand Down
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.drill.exec.physical.impl.xsort.managed;

import static org.apache.drill.test.rowSet.RowSetUtilities.objArray;
import static org.junit.Assert.fail;

import java.util.ArrayList;
Expand All @@ -37,7 +38,7 @@
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.RowSetUtilities;
import org.apache.drill.test.rowSet.RowSetWriter;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand Down Expand Up @@ -348,28 +349,28 @@ public void testMapType(OperatorFixture fixture) throws Exception {
.add("b", MinorType.INT)
.addMap("m2")
.add("c", MinorType.INT)
.buildMap()
.buildMap()
.resumeMap()
.resumeSchema()
.build();

CopierTester tester = new CopierTester(fixture);
tester.addInput(fixture.rowSetBuilder(schema)
.addRow(1, new Object[] {10, new Object[] {100}})
.addRow(5, new Object[] {50, new Object[] {500}})
.addRow(1, objArray(10, objArray(100)))
.addRow(5, objArray(50, objArray(500)))
.withSv2()
.build());

tester.addInput(fixture.rowSetBuilder(schema)
.addRow(2, new Object[] {20, new Object[] {200}})
.addRow(6, new Object[] {60, new Object[] {600}})
.addRow(2, objArray(20, objArray(200)))
.addRow(6, objArray(60, objArray(600)))
.withSv2()
.build());

tester.addOutput(fixture.rowSetBuilder(schema)
.addRow(1, new Object[] {10, new Object[] {100}})
.addRow(2, new Object[] {20, new Object[] {200}})
.addRow(5, new Object[] {50, new Object[] {500}})
.addRow(6, new Object[] {60, new Object[] {600}})
.addRow(1, objArray(10, objArray(100)))
.addRow(2, objArray(20, objArray(200)))
.addRow(5, objArray(50, objArray(500)))
.addRow(6, objArray(60, objArray(600)))
.build());

tester.run();
Expand Down
Expand Up @@ -17,15 +17,16 @@
*/
package org.apache.drill.exec.physical.impl.xsort.managed;

import static org.apache.drill.test.rowSet.RowSetUtilities.intArray;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.apache.drill.common.types.TypeProtos.DataMode;
import org.apache.drill.common.types.TypeProtos.MinorType;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.record.RecordBatchSizer;
import org.apache.drill.exec.record.RecordBatchSizer.ColumnSize;
import org.apache.drill.exec.record.BatchSchema;
import org.apache.drill.exec.record.VectorInitializer;
import org.apache.drill.exec.record.VectorInitializer.AllocationHint;
import org.apache.drill.exec.vector.IntVector;
Expand All @@ -35,7 +36,7 @@
import org.apache.drill.test.rowSet.RowSet;
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.RowSetBuilder;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.Test;

/**
Expand All @@ -61,9 +62,9 @@ public void testSizer() {
.addArray("b", MinorType.INT)
.build();
RowSetBuilder builder = fixture.rowSetBuilder(schema)
.addRow(1, new int[] {10});
.addRow(1, intArray(10));
for (int i = 2; i <= 10; i++) {
builder.addRow(i, new int[] {});
builder.addRow(i, intArray());
}
RowSet rows = builder.build();

Expand Down
Expand Up @@ -47,11 +47,11 @@
import org.apache.drill.test.rowSet.IndirectRowSet;
import org.apache.drill.test.rowSet.RowSet;
import org.apache.drill.test.rowSet.RowSet.ExtendableRowSet;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.apache.drill.test.rowSet.RowSetBuilder;
import org.apache.drill.test.rowSet.RowSetComparison;
import org.apache.drill.test.rowSet.RowSetReader;
import org.apache.drill.test.rowSet.RowSetWriter;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.junit.Test;
import org.junit.experimental.categories.Category;

Expand Down
Expand Up @@ -39,10 +39,10 @@
import org.apache.drill.test.rowSet.RowSetReader;
import org.apache.drill.test.rowSet.RowSetWriter;
import org.apache.drill.test.rowSet.RowSet.SingleRowSet;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.apache.drill.test.rowSet.RowSetBuilder;
import org.apache.drill.test.rowSet.RowSetComparison;
import org.apache.drill.test.rowSet.RowSetUtilities;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.joda.time.Period;
import org.junit.AfterClass;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -635,7 +635,7 @@ public void testMapKey() throws Exception {
.addMap("map")
.add("key", MinorType.INT)
.add("value", MinorType.VARCHAR)
.buildMap()
.resumeSchema()
.build();

SingleRowSet input = fixture.rowSetBuilder(schema)
Expand Down
Expand Up @@ -28,7 +28,7 @@
import org.apache.drill.exec.physical.rowSet.impl.ResultSetLoaderImpl.ResultSetOptions;
import org.apache.drill.exec.vector.ValueVector;
import org.apache.drill.test.SubOperatorTest;
import org.apache.drill.test.rowSet.SchemaBuilder;
import org.apache.drill.test.rowSet.schema.SchemaBuilder;
import org.junit.Test;

/**
Expand Down

0 comments on commit f653359

Please sign in to comment.