Search in sources :

Example 56 with RowSetBuilder

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

the class TestCsvWithSchema method testDecimalDefaultRound.

/**
 * Verify that the decimal default value is rounded according
 * to the scale specified in the decimal type.
 */
@Test
public void testDecimalDefaultRound() throws Exception {
    String tableName = "defaultRound";
    String tablePath = buildTable(tableName, raggedDecimalContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "id int not null, " + "decimal_col decimal(5) not null default `1111.56789` " + ") 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, 0).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, dec("1235")).addRow(2, dec("1112")).addRow(3, dec("-12")).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 57 with RowSetBuilder

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

the class TestCsvWithSchema method testBlankColsWithNullableSchema.

/**
 * As above, but with a nullable numeric column. Here, by default,
 * blank values become nulls.
 */
@Test
public void testBlankColsWithNullableSchema() throws Exception {
    String tableName = "blankColsNullableSchema";
    String tablePath = buildTable(tableName, blankColContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "id int not null, amount int, start_date date" + ") 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).addNullable("amount", MinorType.INT).addNullable("start_date", MinorType.DATE).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, 20, LocalDate.of(2019, 1, 1)).addRow(2, null, null).addRow(3, 30, null).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 58 with RowSetBuilder

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

the class TestCsvWithSchema method testMissingCols.

@Test
public void testMissingCols() throws Exception {
    String tableName = "missingCols";
    String tablePath = buildTable(tableName, trivalContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "col_int integer, " + "col_bigint bigint, " + "col_double double, " + "col_float float, " + "col_var varchar, " + "col_boolean boolean, " + "col_interval interval, " + "col_time time, " + "col_date date, " + "col_timestamp timestamp" + ") for table %s";
        run(sql, tablePath);
        sql = "SELECT * FROM " + tablePath + "ORDER BY id";
        RowSet actual = client.queryBuilder().sql(sql).rowSet();
        TupleMetadata expectedSchema = new SchemaBuilder().addNullable("col_int", MinorType.INT).addNullable("col_bigint", MinorType.BIGINT).addNullable("col_double", MinorType.FLOAT8).addNullable("col_float", MinorType.FLOAT4).addNullable("col_var", MinorType.VARCHAR).addNullable("col_boolean", MinorType.BIT).addNullable("col_interval", MinorType.INTERVAL).addNullable("col_time", MinorType.TIME).addNullable("col_date", MinorType.DATE).addNullable("col_timestamp", MinorType.TIMESTAMP).add("id", MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(null, null, null, null, null, null, null, null, null, null, "1").build();
        RowSetUtilities.verify(expected, actual);
    } finally {
        resetSchema();
    }
}
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 59 with RowSetBuilder

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

the class TestCsvWithSchema method testMissingColsNullable.

/**
 * Demonstrate that CSV works for a schema with nullable types when columns
 * are missing (there is no comma to introduce an empty field in the data.)
 */
@Test
public void testMissingColsNullable() throws Exception {
    String tableName = "missingColsNullable";
    String tablePath = buildTable(tableName, missingColContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "id int not null, amount int, start_date date" + ") 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).addNullable("amount", MinorType.INT).addNullable("start_date", MinorType.DATE).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(1, 20, LocalDate.of(2019, 1, 1)).addRow(2, null, null).addRow(3, 30, null).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 60 with RowSetBuilder

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

the class TestCsvWithSchema method testMissingColsReq.

/**
 * Verify that, if a schema is provided, a column is missing,
 * and there is no default, that the mode is left at required and
 * the column is filled with zeros. Note that this behavior is
 * specific to the text readers: if have no schema, even an missing
 * VARCHAR column will be REQUIRED and set to an empty string
 * (reason: if the column does appear it will be a required VARCHAR,
 * so, to be consistent, missing columns are also required.)
 */
@Test
public void testMissingColsReq() throws Exception {
    String tableName = "missingColsStrict";
    String tablePath = buildTable(tableName, trivalContents);
    try {
        enableSchemaSupport();
        String sql = "create or replace schema (" + "col_int integer not null, " + "col_bigint bigint not null, " + "col_double double not null, " + "col_float float not null, " + "col_var varchar not null, " + "col_boolean boolean not null, " + "col_interval interval not null, " + "col_time time not null, " + "col_date date not null, " + "col_timestamp timestamp not null" + ") 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("col_int", MinorType.INT).add("col_bigint", MinorType.BIGINT).add("col_double", MinorType.FLOAT8).add("col_float", MinorType.FLOAT4).add("col_var", MinorType.VARCHAR).add("col_boolean", MinorType.BIT).add("col_interval", MinorType.INTERVAL).add("col_time", MinorType.TIME).add("col_date", MinorType.DATE).add("col_timestamp", MinorType.TIMESTAMP).add("id", MinorType.VARCHAR).buildSchema();
        RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow(0, 0L, 0.0, 0D, "", false, new Period(0), 0, 0L, 0L, "1").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) Period(org.joda.time.Period) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

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