use of org.apache.drill.exec.record.metadata.TupleMetadata 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.record.metadata.TupleMetadata 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.record.metadata.TupleMetadata 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.record.metadata.TupleMetadata in project drill by apache.
the class ResultSetCopierImpl method createProjection.
private void createProjection() {
if (resultSetWriter != null) {
// Need to build a new writer. Close this one. Doing so
// will tear down the whole show. But, the vector cache will
// ensure that the new writer reuses any matching vectors from
// the prior batch to provide vector persistence as Drill expects.
resultSetWriter.close();
}
TupleMetadata schema = resultSetReader.schema();
writerOptions.readerSchema(schema);
resultSetWriter = new ResultSetLoaderImpl(allocator, writerOptions.build());
rowWriter = resultSetWriter.writer();
currentSchemaVersion = resultSetReader.schemaVersion();
int colCount = schema.size();
projection = new CopyPair[colCount];
for (int i = 0; i < colCount; i++) {
projection[i] = new CopyPair(rowWriter.column(i).writer(), rowReader.column(i).reader());
}
}
use of org.apache.drill.exec.record.metadata.TupleMetadata in project drill by apache.
the class HyperSchemaInference method infer.
public TupleMetadata infer(VectorContainer container) throws SchemaChangeException {
TupleMetadata schema = new TupleSchema();
for (int i = 0; i < container.getNumberOfColumns(); i++) {
VectorWrapper<?> vw = container.getValueVector(i);
schema.addColumn(buildColumn(vw));
}
return schema;
}
Aggregations