use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.
the class TestEmptyInputSql method testRenameProjectEmptyJson.
@Test
public void testRenameProjectEmptyJson() throws Exception {
SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("WeekId", TypeProtos.MinorType.INT).addNullable("ProductName", TypeProtos.MinorType.INT);
final BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery("select WeekId, Product as ProductName from (select CAST(`dir0` as INT) AS WeekId, " + "Product from cp.`%s`)", SINGLE_EMPTY_JSON).schemaBaseLine(expectedSchema).build().run();
}
use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.
the class TestEmptyInputSql method testQueryConstExprEmptyJson.
/**
* Test with query against an empty file. Select clause has three expressions.
* 1.0 + 100.0 as constant expression, is resolved to required FLOAT8/VARDECIMAL
* cast(100 as varchar(100) is resolved to required varchar(100)
* cast(columns as varchar(100)) is resolved to nullable varchar(100).
*/
@Test
public void testQueryConstExprEmptyJson() throws Exception {
try {
alterSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY, false);
SchemaBuilder schemaBuilder = new SchemaBuilder().add("key", TypeProtos.MinorType.FLOAT8).add("name", TypeProtos.MinorType.VARCHAR, 100).addNullable("name2", TypeProtos.MinorType.VARCHAR, 100);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery("select 1.0 + 100.0 as key, " + " cast(100 as varchar(100)) as name, " + " cast(columns as varchar(100)) as name2 " + " from cp.`%s` ", SINGLE_EMPTY_JSON).schemaBaseLine(expectedSchema).build().run();
alterSession(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY, true);
schemaBuilder = new SchemaBuilder().add("key", TypeProtos.MajorType.newBuilder().setMinorType(TypeProtos.MinorType.VARDECIMAL).setMode(TypeProtos.DataMode.REQUIRED).setPrecision(5).setScale(1).build()).add("name", TypeProtos.MinorType.VARCHAR, 100).addNullable("name2", TypeProtos.MinorType.VARCHAR, 100);
expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery("select 1.0 + 100.0 as key, " + " cast(100 as varchar(100)) as name, " + " cast(columns as varchar(100)) as name2 " + " from cp.`%s` ", SINGLE_EMPTY_JSON).schemaBaseLine(expectedSchema).build().run();
} finally {
resetSessionOption(PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY);
}
}
use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.
the class TestEmptyInputSql method testQueryMapArrayEmptyJson.
@Test
public void testQueryMapArrayEmptyJson() throws Exception {
SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("col1", TypeProtos.MinorType.INT).addNullable("col2", TypeProtos.MinorType.INT).addNullable("col3", TypeProtos.MinorType.INT);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery("select foo.a.b as col1, foo.columns[2] as col2, foo.bar.columns[3] as col3 from cp.`%s` as foo", SINGLE_EMPTY_JSON).schemaBaseLine(expectedSchema).build().run();
}
use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.
the class TestUnionAll method testUnionAllBothEmptyDirs.
@Test
public void testUnionAllBothEmptyDirs() throws Exception {
SchemaBuilder schemaBuilder = new SchemaBuilder().addNullable("key", TypeProtos.MinorType.INT);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery("SELECT key FROM dfs.tmp.`%1$s` UNION ALL SELECT key FROM dfs.tmp.`%1$s`", EMPTY_DIR_NAME).schemaBaseLine(expectedSchema).build().run();
}
use of org.apache.drill.exec.record.BatchSchemaBuilder in project drill by apache.
the class TestStarQueries method testSchemaForStarOrderByLimit.
// DRILL-5845
@Test
public void testSchemaForStarOrderByLimit() throws Exception {
final String query = "select * from cp.`tpch/nation.parquet` order by n_name limit 1";
SchemaBuilder schemaBuilder = new SchemaBuilder().add("n_nationkey", TypeProtos.MinorType.INT).add("n_name", TypeProtos.MinorType.VARCHAR).add("n_regionkey", TypeProtos.MinorType.INT).add("n_comment", TypeProtos.MinorType.VARCHAR);
BatchSchema expectedSchema = new BatchSchemaBuilder().withSchemaBuilder(schemaBuilder).build();
testBuilder().sqlQuery(query).schemaBaseLine(expectedSchema).build().run();
}
Aggregations