use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TextCsvWithoutHeadersWithSchema method testBasicSchema.
/**
* Test the simplest possible case: a table with one file:
* <ul>
* <li>Column in projection, table, and schema</li>
* <li>Column in projection, but not in schema or table.</li>
* <li>Column in schema and table, but not in projection.</li>
* <li>Column in table (at end of row), but not in schema</li>
* </ul>
* Also tests type conversion, including "empty" (no) conversion.
*/
@Test
public void testBasicSchema() throws Exception {
String tablePath = buildTable("basic", basicFileContents);
try {
enableSchemaSupport();
String schemaSql = "create schema (intcol int not null, datecol date not null, " + "`str` varchar not null, `dub` double not null) " + "for table %s";
run(schemaSql, tablePath);
String sql = "SELECT `intcol`, `datecol`, `str`, `dub`, `missing` FROM %s";
RowSet actual = client.queryBuilder().sql(sql, tablePath).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().add("intcol", // Has a schema
MinorType.INT).add("datecol", // Has a schema
MinorType.DATE).add("str", // Has a schema, original type
MinorType.VARCHAR).add("dub", // Has a schema
MinorType.FLOAT8).add("missing", // No data, no schema, default type
MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(10, new LocalDate(2019, 3, 20), "it works!", 1234.5D, "").build();
RowSetUtilities.verify(expected, actual);
} finally {
resetSchemaSupport();
}
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestSasReader method testMetadataColumns.
@Test
public void testMetadataColumns() throws Exception {
String sql = "SELECT _compression_method, _file_label, _file_type, " + "_os_name, _os_type, _sas_release, _session_encoding, _server_type, " + "_date_created, _date_modified FROM cp.`sas/date_formats.sas7bdat`";
RowSet results = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("_compression_method", MinorType.VARCHAR).addNullable("_file_label", MinorType.VARCHAR).addNullable("_file_type", MinorType.VARCHAR).addNullable("_os_name", MinorType.VARCHAR).addNullable("_os_type", MinorType.VARCHAR).addNullable("_sas_release", MinorType.VARCHAR).addNullable("_session_encoding", MinorType.VARCHAR).addNullable("_server_type", MinorType.VARCHAR).addNullable("_date_created", MinorType.DATE).addNullable("_date_modified", MinorType.DATE).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(null, "DATA", null, null, "9.0401M4", null, "X64_7PRO", null, LocalDate.parse("2017-03-14"), LocalDate.parse("2017-03-14")).build();
new RowSetComparison(expected).verifyAndClearAll(results);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestSasReader method testDates.
@Test
public void testDates() throws Exception {
String sql = "SELECT b8601da, e8601da, `date` FROM cp.`sas/date_formats.sas7bdat`";
RowSet results = client.queryBuilder().sql(sql).rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("b8601da", MinorType.DATE).addNullable("e8601da", MinorType.DATE).addNullable("date", MinorType.DATE).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(LocalDate.parse("2017-03-14"), LocalDate.parse("2017-03-14"), LocalDate.parse("2017-03-14")).build();
new RowSetComparison(expected).verifyAndClearAll(results);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestSpssReader method testExplicitQuery.
@Test
public void testExplicitQuery() throws Exception {
String sql = "SELECT ID, Urban, Urban_value FROM dfs.`spss/testdata.sav` WHERE d16=4";
QueryBuilder q = client.queryBuilder().sql(sql);
RowSet results = q.rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("ID", TypeProtos.MinorType.FLOAT8).addNullable("Urban", TypeProtos.MinorType.FLOAT8).addNullable("Urban_value", TypeProtos.MinorType.VARCHAR).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(47.0, 1.0, "Urban").addRow(53.0, 1.0, "Urban").addRow(66.0, 1.0, "Urban").build();
assertEquals(3, results.rowCount());
new RowSetComparison(expected).verifyAndClearAll(results);
}
use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.
the class TestSpssReader method testStarQuery.
@Test
public void testStarQuery() throws Exception {
String sql = "SELECT * FROM dfs.`spss/testdata.sav` WHERE d16=4";
QueryBuilder q = client.queryBuilder().sql(sql);
RowSet results = q.rowSet();
TupleMetadata expectedSchema = new SchemaBuilder().addNullable("ID", TypeProtos.MinorType.FLOAT8).addNullable("Urban", TypeProtos.MinorType.FLOAT8).addNullable("Urban_value", TypeProtos.MinorType.VARCHAR).addNullable("District", TypeProtos.MinorType.FLOAT8).addNullable("District_value", TypeProtos.MinorType.VARCHAR).addNullable("Province", TypeProtos.MinorType.FLOAT8).addNullable("Province_value", TypeProtos.MinorType.VARCHAR).addNullable("Interviewer", TypeProtos.MinorType.FLOAT8).addNullable("Date", TypeProtos.MinorType.FLOAT8).addNullable("d6_1", TypeProtos.MinorType.FLOAT8).addNullable("d6_1_Value", TypeProtos.MinorType.VARCHAR).addNullable("d6_2", TypeProtos.MinorType.FLOAT8).addNullable("d6_2_Value", TypeProtos.MinorType.VARCHAR).addNullable("d6_3", TypeProtos.MinorType.FLOAT8).addNullable("d6_3_Value", TypeProtos.MinorType.VARCHAR).addNullable("d6_4", TypeProtos.MinorType.FLOAT8).addNullable("d6_4_Value", TypeProtos.MinorType.VARCHAR).addNullable("s_1", TypeProtos.MinorType.VARCHAR).addNullable("d6_5", TypeProtos.MinorType.FLOAT8).addNullable("d6_5_Value", TypeProtos.MinorType.VARCHAR).addNullable("d6_6", TypeProtos.MinorType.FLOAT8).addNullable("d6_6_Value", TypeProtos.MinorType.VARCHAR).addNullable("d6_7", TypeProtos.MinorType.FLOAT8).addNullable("d6_7_Value", TypeProtos.MinorType.VARCHAR).addNullable("q1", TypeProtos.MinorType.FLOAT8).addNullable("q1_Value", TypeProtos.MinorType.VARCHAR).addNullable("q2", TypeProtos.MinorType.FLOAT8).addNullable("q2_Value", TypeProtos.MinorType.VARCHAR).addNullable("d7a", TypeProtos.MinorType.FLOAT8).addNullable("d7a_Value", TypeProtos.MinorType.VARCHAR).addNullable("d7b", TypeProtos.MinorType.FLOAT8).addNullable("d7b_Value", TypeProtos.MinorType.VARCHAR).addNullable("d16", TypeProtos.MinorType.FLOAT8).addNullable("Stratum", TypeProtos.MinorType.FLOAT8).addNullable("S1_IP", TypeProtos.MinorType.FLOAT8).addNullable("S2_IP", TypeProtos.MinorType.FLOAT8).addNullable("Sample_Weight", TypeProtos.MinorType.FLOAT8).buildSchema();
RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(47.0, 1.0, "Urban", 101.0, "Kabul", 1.0, "Kabul", 151.0, 1.34557632E10, 1.0, "Yes", 2.0, "No", 2.0, "No", 2.0, "No", "", 2.0, "No", 2.0, "No", 2.0, "No", 1.0, "Good", 2.0, "The same", 5.0, "Housewife (not working outside of the home)", 97.0, "Not Asked", 4.0, 121.0, 0.007463305415042708, 0.006666666666666667, 20098.33333333333).addRow(53.0, 1.0, "Urban", 101.0, "Kabul", 1.0, "Kabul", 151.0, 1.34557632E10, 1.0, "Yes", 2.0, "No", 2.0, "No", 2.0, "No", "", 2.0, "No", 2.0, "No", 2.0, "No", 1.0, "Good", 2.0, "The same", 5.0, "Housewife (not working outside of the home)", 97.0, "Not Asked", 4.0, 121.0, 0.007463305415042708, 0.006666666666666667, 20098.33333333333).addRow(66.0, 1.0, "Urban", 101.0, "Kabul", 1.0, "Kabul", 774.0, 1.34556768E10, 2.0, "No", 1.0, "Yes", 1.0, "Yes", 2.0, "No", "", 2.0, "No", 2.0, "No", 2.0, "No", 1.0, "Good", 1.0, "Better", 1.0, "Working full time", 13.0, "Private Business Sole Proprietor", 4.0, 111.0, 0.017389288198469743, 0.006666666666666667, 8626.0).build();
assertEquals(3, results.rowCount());
new RowSetComparison(expected).verifyAndClearAll(results);
}
Aggregations