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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations