use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestJdbcWriterWithPostgres method testBasicCTASWithSpacesInTableName.
@Test
public void testBasicCTASWithSpacesInTableName() throws Exception {
String query = "CREATE TABLE pg.public.`test table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
// Create the table and insert the values
QuerySummary insertResults = queryBuilder().sql(query).run();
assertTrue(insertResults.succeeded());
// Query the table to see if the insertion was successful
String testQuery = "SELECT * FROM pg.public.`test table`";
DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("ID", MinorType.BIGINT, DataMode.OPTIONAL).add("NAME", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
RowSetUtilities.verify(expected, results);
// Now drop the table
String dropQuery = "DROP TABLE pg.public.`test table`";
QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
assertTrue(dropResults.succeeded());
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestJdbcWriterWithH2 method testCTASFromFileWithUglyData.
@Test
public void testCTASFromFileWithUglyData() throws Exception {
String sql = String.format("CREATE TABLE %s AS SELECT ugly1, ugly2 FROM cp.`json/uglyData.json`", TEST_TABLE);
QuerySummary insertResults = queryBuilder().sql(sql).run();
assertTrue(insertResults.succeeded());
try {
sql = String.format("SELECT * FROM %s", TEST_TABLE);
DirectRowSet results = queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("ugly1", MinorType.VARCHAR, 38).addNullable("ugly2", MinorType.VARCHAR, 38).build();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("O'Malley", "Abraham Lincoln's best speech started with: \"Four score and seven years ago...").build();
RowSetUtilities.verify(expected, results);
} finally {
QuerySummary dropResults = queryBuilder().sql(DROP_TEST_TABLE).run();
assertTrue(dropResults.succeeded());
}
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestJdbcWriterWithH2 method testBasicCTASWithSpacesInFieldNames.
@Test
public void testBasicCTASWithSpacesInFieldNames() throws Exception {
String query = String.format("CREATE TABLE %s (`My id`, `My name`) AS SELECT * FROM (VALUES(1,2), (3,4))", TEST_TABLE);
// Create the table and insert the values
QuerySummary insertResults = queryBuilder().sql(query).run();
assertTrue(insertResults.succeeded());
try {
// Query the table to see if the insertion was successful
String testQuery = String.format("SELECT * FROM %s", TEST_TABLE);
DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("My id", MinorType.BIGINT, DataMode.OPTIONAL).add("My name", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
RowSetUtilities.verify(expected, results);
} finally {
QuerySummary dropResults = queryBuilder().sql(DROP_TEST_TABLE).run();
assertTrue(dropResults.succeeded());
}
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestJdbcWriterWithH2 method testBasicCTAS.
@Test
public void testBasicCTAS() throws Exception {
String query = String.format("CREATE TABLE %s (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))", TEST_TABLE);
// Create the table and insert the values
QuerySummary insertResults = queryBuilder().sql(query).run();
try {
assertTrue(insertResults.succeeded());
// Query the table to see if the insertion was successful
String testQuery = String.format("SELECT * FROM %s", TEST_TABLE);
DirectRowSet results = queryBuilder().sql(testQuery).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("ID", MinorType.BIGINT, DataMode.OPTIONAL).add("NAME", MinorType.BIGINT, DataMode.OPTIONAL).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1L, 2L).addRow(3L, 4L).build();
RowSetUtilities.verify(expected, results);
} finally {
QuerySummary dropResults = queryBuilder().sql(DROP_TEST_TABLE).run();
assertTrue(dropResults.succeeded());
}
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestResultSetLoaderUnions method testListofListofScalar.
/**
* The semantics of the ListVector are such that it allows
* multi-dimensional lists. In this way, it is like a (slightly
* more normalized) version of the repeated list vector. This form
* allows arrays to be null.
* <p>
* This test verifies that the (non-repeated) list vector can
* be used to create multi-dimensional arrays in the result set
* loader layer. However, the rest of Drill does not support this
* functionality at present, so this test is more of a proof-of-
* concept than a necessity.
*/
@Test
public void testListofListofScalar() {
// JSON equivalent: {a: [[1, 2], [3, 4]]}
final ResultSetLoader rsLoader = new ResultSetLoaderImpl(fixture.allocator());
final RowSetLoader writer = rsLoader.writer();
// Can write a batch as if this was a repeated Varchar, except
// that any value can also be null.
rsLoader.startBatch();
writer.addColumn(MaterializedField.create("a", Types.optional(MinorType.LIST)));
final ArrayWriter outerArray = writer.array("a");
final VariantWriter outerVariant = outerArray.variant();
outerVariant.addMember(MinorType.LIST);
final ArrayWriter innerArray = outerVariant.array();
final VariantWriter innerVariant = innerArray.variant();
innerVariant.addMember(MinorType.INT);
writer.addSingleCol(listValue(listValue(1, 2), listValue(3, 4)));
final RowSet results = fixture.wrap(rsLoader.harvest());
// Verify metadata
final ListVector outer = (ListVector) results.container().getValueVector(0).getValueVector();
final MajorType outerType = outer.getField().getType();
assertEquals(1, outerType.getSubTypeCount());
assertEquals(MinorType.LIST, outerType.getSubType(0));
assertEquals(1, outer.getField().getChildren().size());
final ListVector inner = (ListVector) outer.getDataVector();
assertSame(inner.getField(), outer.getField().getChildren().iterator().next());
final MajorType innerType = inner.getField().getType();
assertEquals(1, innerType.getSubTypeCount());
assertEquals(MinorType.INT, innerType.getSubType(0));
assertEquals(1, inner.getField().getChildren().size());
final ValueVector data = inner.getDataVector();
assertSame(data.getField(), inner.getField().getChildren().iterator().next());
assertEquals(MinorType.INT, data.getField().getType().getMinorType());
assertEquals(DataMode.OPTIONAL, data.getField().getType().getMode());
assertTrue(data instanceof NullableIntVector);
// Note use of TupleMetadata: BatchSchema can't hold the
// structure of a list.
final TupleMetadata expectedSchema = new SchemaBuilder().addList("a").addList().addType(MinorType.INT).resumeUnion().resumeSchema().buildSchema();
final RowSet expected = new RowSetBuilder(fixture.allocator(), expectedSchema).addSingleCol(listValue(listValue(1, 2), listValue(3, 4))).build();
RowSetUtilities.verify(expected, results);
}
Aggregations