Search in sources :

Example 1 with RowSetBuilder

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

the class TestDirectConverter method testImplicitConversionIntTruncation.

/**
 * The column accessors provide only int setters. For performance, the int value is
 * assumed to be of the correct range for the target column. If not, truncation of
 * the highest bytes occurs.
 * <p>
 * The assumption is, if the reader or other code expects that overflow might
 * occur, that code should be implemented in the client (or in a type conversion
 * shim), leaving the normal code path to optimize for the 99% of the cases where
 * the value is in the proper range.
 */
@Test
public void testImplicitConversionIntTruncation() {
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).buildSchema();
    // Test allowed implicit conversions.
    RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(Byte.MAX_VALUE + 1, Short.MAX_VALUE + 1).addRow(Byte.MAX_VALUE + 2, Short.MAX_VALUE + 2).build();
    // Build the expected vector without a type converter.
    final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(Byte.MIN_VALUE, Short.MIN_VALUE).addRow(Byte.MIN_VALUE + 1, Short.MIN_VALUE + 1).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 2 with RowSetBuilder

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

the class TestDirectConverter method testImplicitConversion.

/**
 * Tests the implicit conversions provided by the column writer itself.
 * No conversion mechanism is needed in this case.
 */
@Test
public void testImplicitConversion() {
    TupleMetadata schema = new SchemaBuilder().add("ti", MinorType.TINYINT).add("si", MinorType.SMALLINT).add("int", MinorType.INT).add("bi", MinorType.BIGINT).add("fl", MinorType.FLOAT4).add("db", MinorType.FLOAT8).add("dec", MinorType.VARDECIMAL, 10, 0).buildSchema();
    // Test allowed implicit conversions.
    RowSet actual = new RowSetBuilder(fixture.allocator(), schema).addRow(11, 12, 13, 14, 15, 16, // int
    17).addRow(21L, 22L, 23L, 24L, 25L, 26L, // long
    27L).addRow(31F, 32F, 33F, 34F, 35F, 36F, // float
    37F).addRow(41D, 42D, 43D, 44D, 45D, 46D, // double
    47D).addRow(dec(51), dec(52), dec(53), dec(54), dec(55), dec(56), // decimal
    dec(57)).build();
    final SingleRowSet expected = fixture.rowSetBuilder(schema).addRow(11, 12, 13, 14L, 15F, 16D, dec(17)).addRow(21, 22, 23, 24L, 25F, 26D, dec(27)).addRow(31, 32, 33, 34L, 35F, 36D, dec(37)).addRow(41, 42, 43, 44L, 45F, 46D, dec(47)).addRow(51, 52, 53, 54L, 55L, 56D, dec(57)).build();
    RowSetUtilities.verify(expected, actual);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) SingleRowSet(org.apache.drill.exec.physical.rowSet.RowSet.SingleRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 3 with RowSetBuilder

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

the class TestSequenceFileReader method testExplicitQuery.

@Test
public void testExplicitQuery() throws Exception {
    String sql = "select convert_from(binary_key, 'UTF8') as binary_key from cp.`sequencefiles/simple.seq`";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    TupleMetadata schema = new SchemaBuilder().addNullable(SequenceFileBatchReader.KEY_SCHEMA, MinorType.VARCHAR).build();
    RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow(byteWritableString("key0")).addRow(byteWritableString("key1")).build();
    assertEquals(2, sets.rowCount());
    new RowSetComparison(expected).verifyAndClearAll(sets);
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) QueryBuilder(org.apache.drill.test.QueryBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Example 4 with RowSetBuilder

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

the class TestJdbcWriterWithMySQL method testBasicCTASIfNotExists.

@Test
public void testBasicCTASIfNotExists() throws Exception {
    String query = "CREATE TABLE IF NOT EXISTS mysql.`drill_mysql_test`.`test_table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    assertTrue(insertResults.succeeded());
    // Query the table to see if the insertion was successful
    String testQuery = "SELECT * FROM  mysql.`drill_mysql_test`.`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);
    // Now drop the table
    String dropQuery = "DROP TABLE mysql.`drill_mysql_test`.`test_table`";
    QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
    assertTrue(dropResults.succeeded());
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) JdbcStorageTest(org.apache.drill.categories.JdbcStorageTest)

Example 5 with RowSetBuilder

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

the class TestJdbcWriterWithMySQL method testBasicCTASWithLocalDatabase.

@Test
@Ignore("Requires local installation of MySQL")
public void testBasicCTASWithLocalDatabase() throws Exception {
    // Local databases
    String localMySql = "jdbc:mysql://localhost:3306/?useJDBCCompliantTimezoneShift=true&serverTimezone=EST5EDT";
    JdbcStorageConfig localJdbcStorageConfig = new JdbcStorageConfig("com.mysql.cj.jdbc.Driver", localMySql, "root", "password", false, true, null, null, 10000);
    localJdbcStorageConfig.setEnabled(true);
    cluster.defineStoragePlugin("localMysql", localJdbcStorageConfig);
    String query = "CREATE TABLE localMysql.`drill_mysql_test`.`test_table` (ID, NAME) AS SELECT * FROM (VALUES(1,2), (3,4))";
    // Create the table and insert the values
    QuerySummary insertResults = queryBuilder().sql(query).run();
    assertTrue(insertResults.succeeded());
    // Query the table to see if the insertion was successful
    String testQuery = "SELECT * FROM  localMysql.`drill_mysql_test`.`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);
    // Now drop the table
    String dropQuery = "DROP TABLE localMysql.`drill_mysql_test`.`test_table`";
    QuerySummary dropResults = queryBuilder().sql(dropQuery).run();
    assertTrue(dropResults.succeeded());
}
Also used : RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) Ignore(org.junit.Ignore) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) JdbcStorageTest(org.apache.drill.categories.JdbcStorageTest)

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