Search in sources :

Example 11 with QueryBuilder

use of org.apache.drill.test.QueryBuilder in project drill by apache.

the class TestPdfFormat method testWithCompressedFile.

@Test
public void testWithCompressedFile() throws Exception {
    generateCompressedFile("pdf/argentina_diputados_voting_record.pdf", "zip", "pdf/compressed.pdf.zip");
    String sql = "SELECT * FROM dfs.`pdf/compressed.pdf.zip` WHERE `Provincia` = 'Rio Negro'";
    QueryBuilder q = client.queryBuilder().sql(sql);
    RowSet results = q.rowSet();
    TupleMetadata expectedSchema = new SchemaBuilder().addNullable("Apellido y Nombre", MinorType.VARCHAR).addNullable("Bloque polĂ­tico", MinorType.VARCHAR).addNullable("Provincia", MinorType.VARCHAR).addNullable("field_0", MinorType.VARCHAR).buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), expectedSchema).addRow("ALBRIEU, Oscar Edmundo Nicolas", "Frente para la Victoria - PJ", "Rio Negro", "AFIRMATIVO").addRow("AVOSCAN, Herman Horacio", "Frente para la Victoria - PJ", "Rio Negro", "AFIRMATIVO").addRow("CEJAS, Jorge Alberto", "Frente para la Victoria - PJ", "Rio Negro", "AFIRMATIVO").build();
    new RowSetComparison(expected).verifyAndClearAll(results);
}
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 12 with QueryBuilder

use of org.apache.drill.test.QueryBuilder in project drill by apache.

the class TestComplexSchemaFunctions method testMapSchemaFunctionWithInnerMap.

@Test
public void testMapSchemaFunctionWithInnerMap() throws RpcException {
    String sql = "SELECT getMapSchema(t1.record.map) AS schema FROM cp.`json/nestedSchema.json` AS t1";
    QueryBuilder q = client.queryBuilder().sql(sql);
    RowSet results = q.rowSet();
    assertEquals(results.rowCount(), 1);
    TupleMetadata expectedSchema = new SchemaBuilder().addMap("schema").addNullable("nested_int_field", MinorType.VARCHAR).addNullable("nested_double_field", MinorType.VARCHAR).addNullable("nested_string_field", MinorType.VARCHAR).resumeSchema().build();
    RowSet expected = client.rowSetBuilder(expectedSchema).addRow((Object) strArray("BIGINT", "FLOAT8", "VARCHAR")).build();
    new RowSetComparison(expected).verifyAndClearAll(results);
}
Also used : 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) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 13 with QueryBuilder

use of org.apache.drill.test.QueryBuilder in project drill by apache.

the class TestComplexSchemaFunctions method testMapSchemaFunction.

@Test
public void testMapSchemaFunction() throws RpcException {
    String sql = "SELECT getMapSchema(record) AS schema FROM cp.`json/nestedSchema.json`";
    QueryBuilder q = client.queryBuilder().sql(sql);
    RowSet results = q.rowSet();
    assertEquals(results.rowCount(), 1);
    TupleMetadata expectedSchema = new SchemaBuilder().addMap("schema").addNullable("int_field", MinorType.VARCHAR).addNullable("double_field", MinorType.VARCHAR).addNullable("string_field", MinorType.VARCHAR).addNullable("boolean_field", MinorType.VARCHAR).addNullable("int_list", MinorType.VARCHAR).addNullable("double_list", MinorType.VARCHAR).addNullable("boolean_list", MinorType.VARCHAR).addNullable("map", MinorType.VARCHAR).addNullable("repeated_map", MinorType.VARCHAR).resumeSchema().build();
    RowSet expected = client.rowSetBuilder(expectedSchema).addRow((Object) strArray("BIGINT", "FLOAT8", "VARCHAR", "BIT", "REPEATED_BIGINT", "REPEATED_FLOAT8", "REPEATED_BIT", "MAP", "REPEATED_MAP")).build();
    new RowSetComparison(expected).verifyAndClearAll(results);
}
Also used : 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) SqlFunctionTest(org.apache.drill.categories.SqlFunctionTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest)

Example 14 with QueryBuilder

use of org.apache.drill.test.QueryBuilder in project drill by apache.

the class TestFilesTable method testShowFilesForSpecificDirectory.

@Test
public void testShowFilesForSpecificDirectory() throws Exception {
    try {
        client.alterSession(ExecConstants.LIST_FILES_RECURSIVELY, false);
        QueryBuilder queryBuilder = client.queryBuilder().sql("show files in dfs.`files`.folder1");
        QueryBuilder.QuerySummary querySummary = queryBuilder.run();
        assertTrue(querySummary.succeeded());
        assertEquals(2, querySummary.recordCount());
        // option has no effect
        client.alterSession(ExecConstants.LIST_FILES_RECURSIVELY, true);
        querySummary = queryBuilder.run();
        assertTrue(querySummary.succeeded());
        assertEquals(2, querySummary.recordCount());
    } finally {
        client.resetSession(ExecConstants.LIST_FILES_RECURSIVELY);
    }
}
Also used : QueryBuilder(org.apache.drill.test.QueryBuilder) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test) SqlTest(org.apache.drill.categories.SqlTest)

Example 15 with QueryBuilder

use of org.apache.drill.test.QueryBuilder in project drill by apache.

the class TestLogReaderIssue method testIssue7853UseValidDatetimeFormat.

@Test
public void testIssue7853UseValidDatetimeFormat() throws Exception {
    String sql = "SELECT type, `time` FROM `dfs.data`.`root/issue7853.log`";
    QueryBuilder builder = client.queryBuilder().sql(sql);
    RowSet sets = builder.rowSet();
    TupleMetadata schema = new SchemaBuilder().addNullable("type", MinorType.VARCHAR).addNullable("time", MinorType.TIMESTAMP).buildSchema();
    RowSet expected = new RowSetBuilder(client.allocator(), schema).addRow("h2", 1611446100664L).addRow("h2", 1611446100666L).build();
    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) BaseCsvTest(org.apache.drill.exec.store.easy.text.compliant.BaseCsvTest) Test(org.junit.Test) EvfTest(org.apache.drill.categories.EvfTest)

Aggregations

QueryBuilder (org.apache.drill.test.QueryBuilder)65 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)61 Test (org.junit.Test)53 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)48 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)48 RowSetComparison (org.apache.drill.test.rowSet.RowSetComparison)48 RowSetBuilder (org.apache.drill.exec.physical.rowSet.RowSetBuilder)45 ClusterTest (org.apache.drill.test.ClusterTest)39 SlowTest (org.apache.drill.categories.SlowTest)14 SqlFunctionTest (org.apache.drill.categories.SqlFunctionTest)3 UnlikelyTest (org.apache.drill.categories.UnlikelyTest)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Ignore (org.junit.Ignore)2 EvfTest (org.apache.drill.categories.EvfTest)1 SqlTest (org.apache.drill.categories.SqlTest)1 BaseCsvTest (org.apache.drill.exec.store.easy.text.compliant.BaseCsvTest)1 Disabled (org.junit.jupiter.api.Disabled)1 Test (org.junit.jupiter.api.Test)1