use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestCsvWithHeaders method testColumnsMissing.
@Test
public void testColumnsMissing() throws IOException {
String sql = "SELECT a, columns FROM `dfs.data`.`%s`";
RowSet actual = client.queryBuilder().sql(sql, TEST_FILE_NAME).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("columns", MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "").build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestCsvWithHeaders method testHeadersOnly.
@Test
public void testHeadersOnly() throws Exception {
String fileName = "headersOnly.csv";
try (PrintWriter out = new PrintWriter(new FileWriter(new File(testDir, fileName)))) {
// note: no \n in the end
out.print("a,b,c");
}
RowSet actual = client.queryBuilder().sql(makeStatement(fileName)).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestCsvWithHeaders method testWildcard.
/**
* Verify that the wildcard expands columns to the header names, including
* case
*/
@Test
public void testWildcard() throws IOException {
String sql = "SELECT * FROM `dfs.data`.`%s`";
RowSet actual = client.queryBuilder().sql(sql, TEST_FILE_NAME).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("a", MinorType.VARCHAR).add("b", MinorType.VARCHAR).add("c", MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("10", "foo", "bar").build();
RowSetUtilities.verify(expected, actual);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestCsvWithSchema method testDateColDefault.
/**
* Use a user-provided default value for a missing required column.
*/
@Test
public void testDateColDefault() throws Exception {
String tableName = "missingDate";
String tablePath = buildTable(tableName, nameOnlyContents);
try {
enableSchemaSupport();
String schemaSql = SCHEMA_SQL.replace("`date` date format 'yyyy-MM-dd'", "`date` date not null format 'yyyy-MM-dd' default '2001-02-03'");
run(schemaSql, tablePath);
String sql = "SELECT id, `name`, `date` FROM " + tablePath;
RowSet actual = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).add("date", MinorType.DATE).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, "dino", LocalDate.of(2001, 2, 3)).build();
RowSetUtilities.verify(expected, actual);
} finally {
resetSchemaSupport();
}
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestCsvWithSchema method testMultiFileSchema.
/**
* Use a schema with explicit projection to get a consistent view
* of the table schema, even if columns are missing, rows are ragged,
* and column order changes.
* <p>
* Force the scans to occur in distinct fragments so the order of the
* file batches is random.
*/
@Test
public void testMultiFileSchema() throws Exception {
RowSet expected1 = null;
RowSet expected2 = null;
try {
enableSchemaSupport();
enableMultiScan();
String tablePath = buildTable("multiFileSchema", raggedMulti1Contents, reordered2Contents);
run(SCHEMA_SQL, tablePath);
// Wildcard expands to union of schema + table. In this case
// all table columns appear in the schema (though not all schema
// columns appear in the table.)
String sql = "SELECT id, `name`, `date`, gender, comment FROM " + tablePath;
TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("name", MinorType.VARCHAR).addNullable("date", MinorType.DATE).add("gender", MinorType.VARCHAR).add("comment", MinorType.VARCHAR).buildSchema();
expected1 = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, "wilma", LocalDate.of(2019, 1, 18), "female", "ABC").addRow(2, "fred", LocalDate.of(2019, 1, 19), "male", "ABC").addRow(4, "betty", LocalDate.of(2019, 5, 4), "NA", "ABC").build();
expected2 = new RowSetBuilder(client.allocator(), expectedSchema).addRow(3, "barney", LocalDate.of(2001, 1, 16), "NA", "ABC").build();
for (int i = 0; i < 10; i++) {
boolean sawSchema = false;
boolean sawFile1 = false;
boolean sawFile2 = false;
Iterator<DirectRowSet> iter = client.queryBuilder().sql(sql).rowSetIterator();
while (iter.hasNext()) {
RowSet result = iter.next();
if (result.rowCount() == 3) {
sawFile1 = true;
new RowSetComparison(expected1).verifyAndClear(result);
} else if (result.rowCount() == 1) {
sawFile2 = true;
new RowSetComparison(expected2).verifyAndClear(result);
} else {
assertEquals(0, result.rowCount());
sawSchema = true;
}
}
assertTrue(!SCHEMA_BATCH_ENABLED || sawSchema);
assertTrue(sawFile1);
assertTrue(sawFile2);
}
} finally {
expected1.clear();
expected2.clear();
resetSchemaSupport();
resetMultiScan();
}
}
Aggregations