Search in sources :

Example 61 with RowSetBuilder

use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.

the class TestCsvWithSchema method testDecimal.

/**
 * Basic decimal sanity test showing rounding, using default values,
 * and so on.
 */
@Test
public void testDecimal() throws Exception {
    String tableName = "decimal";
    String tablePath = buildTable(tableName, decimalContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "id int not null, " + "decimal_col decimal(5,2) not null default `100.00` " + ") for table %s";
        run(sql, tablePath);
        sql = "SELECT * FROM " + tablePath + "ORDER BY id";
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("decimal_col", MinorType.VARDECIMAL, 5, 2).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, dec("12.34")).addRow(2, dec("-56.79")).addRow(3, dec("0")).addRow(4, dec("8")).addRow(5, dec("100.00")).addRow(6, dec("0.00")).addRow(7, dec("0.00")).build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 62 with RowSetBuilder

use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.

the class TestCsvWithSchema method testBool.

/**
 * Test the many ways to specify True for boolean columns. Anything that
 * is not true is false.
 */
@Test
public void testBool() throws Exception {
    String tableName = "bool";
    String tablePath = buildTable(tableName, boolContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "id int not null, " + "bool_col boolean not null default `true` " + ") for table %s";
        run(sql, tablePath);
        sql = "SELECT * FROM " + tablePath + "ORDER BY id";
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("id", MinorType.INT).add("bool_col", MinorType.BIT).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, true).addRow(2, false).addRow(3, true).addRow(4, false).addRow(5, true).addRow(6, true).addRow(7, true).addRow(8, false).addRow(9, true).addRow(10, true).addRow(11, true).addRow(12, true).addRow(13, true).addRow(14, true).addRow(15, true).addRow(16, false).build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 63 with RowSetBuilder

use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.

the class TestCsvWithSchema 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 and table but not in schema.</li>
 * <li>Column in projection and schema, but not in table.</li>
 * <li>Column in projection, but not in schema or table.</li>
 * </ul>
 */
@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, " + "`dub` double not null, `extra` bigint not null default '20') " + "for table " + tablePath;
        run(schemaSql);
        String sql = "SELECT `intcol`, `datecol`, `str`, `dub`, `extra`, `missing` FROM " + tablePath;
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("intcol", // Has a schema
        MinorType.INT).add("datecol", // Has a schema
        MinorType.DATE).add("str", // No schema, retains type
        MinorType.VARCHAR).add("dub", // Has a schema
        MinorType.FLOAT8).add("extra", // No data, has default value
        MinorType.BIGINT).add("missing", // No data, no schema, default type
        MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(10, LocalDate.of(2019, 3, 20), "it works!", 1234.5D, 20L, "").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Example 64 with RowSetBuilder

use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.

the class TextCsvWithoutHeadersWithSchema method testMissingColumn.

/**
 * Test column in schema, not in file.
 */
@Test
public void testMissingColumn() throws Exception {
    String tablePath = buildTable("missingCol", fileContents);
    try {
        enableSchemaSupport();
        String schemaSql = "create schema (intcol int not null, datecol date not null, " + "`str` varchar not null, `dub` double not null, " + "`extra` bigint not null default '20') " + "for table %s";
        run(schemaSql, tablePath);
        String sql = "SELECT `intcol`, `datecol`, `str`, `dub`, `extra`, `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("extra", // No data, has default value
        MinorType.BIGINT).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, 20L, "").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 65 with RowSetBuilder

use of org.apache.drill.exec.physical.rowSet.RowSetBuilder in project drill by apache.

the class TextCsvWithoutHeadersWithSchema method filenameColumn.

/**
 * Test with an implicit column.
 */
@Test
public void filenameColumn() throws Exception {
    String tablePath = buildTable("test3", fileContents);
    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`, `filename` FROM %s";
        RowSet actual = client.queryBuilder().sql(sql, tablePath).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().add("intcol", MinorType.INT).add("datecol", MinorType.DATE).add("str", MinorType.VARCHAR).add("dub", MinorType.FLOAT8).add("filename", MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(10, new LocalDate(2019, 3, 20), "it works!", 1234.5D, "file0.csv").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchemaSupport();
    }
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Aggregations

RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)303 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)296 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)293 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)288 Test (org.junit.Test)282 ClusterTest (org.apache.drill.test.ClusterTest)153 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)140 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)84 EvfTest (org.apache.drill.categories.EvfTest)64 QueryBuilder (org.apache.drill.test.QueryBuilder)45 SingleRowSet (org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet)28 SubOperatorTest (org.apache.drill.test.SubOperatorTest)27 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)26 SlowTest (org.apache.drill.categories.SlowTest)23 ValueVector (org.apache.drill.exec.vector.ValueVector)23 MockResponse (okhttp3.mockwebserver.MockResponse)21 MockWebServer (okhttp3.mockwebserver.MockWebServer)21 ColumnSize (org.apache.drill.exec.record.RecordBatchSizer.ColumnSize)20 RepeatedValueVector (org.apache.drill.exec.vector.complex.RepeatedValueVector)18 JdbcStorageTest (org.apache.drill.categories.JdbcStorageTest)17